智能车制作

标题: XS128外部H7口J0口中断例程 [打印本页]

作者: 凌风    时间: 2010-2-26 13:22
标题: XS128外部H7口J0口中断例程
XS128外部H7口J0口中断例程
[ 2009-4-19 4:58:00 | By: 龙丘 ]
  
0
推荐/********************************************
龙丘智能车多功能开发平台
Designed by Chiu Sir
E-mail:chiusir@163.com
软件版本:V1.0
最后更新:2009年4月19日
相关信息参考下列地址:
博客:  http://longqiu.21ic.org
淘宝店:http://shop36265907.taobao.com
------------------------------------
Code Warrior 5.0
Target : MC9S12XS128
Crystal: 16.000Mhz
busclock:16.000MHz
pllclock:32.000MHz   

使用说明:
H7,J0外部中断演示,分别亮灭PB0和PB2。
============================================*/
#i nclude "derivative.h"
#i nclude <stdio.h>
#i nclude <string.h>  
#i nclude "LQfun.h"  
#i nclude "LQ12864.h"   

#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 24 PORTJ_ISR(void)
{         
  PORTB_PB0=~PORTB_PB0;
  PIFJ_PIFJ0=1;   //清除中断标志位
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 25 PORTH_ISR(void)
{
  PORTB_PB2=~PORTB_PB2;
  PIFH_PIFH7=1;   //清除中断标志位        
}
static void Port_Init(void)
{  
    DDRA = 0xff;  //LCD1100,PA0--4,PA67 D1D2
    PORTA= 0x00;   
      
    DDRB = 0xff;  //LED  PTB0--7,
    PORTB= 0xff;  //LEDs on  
   
    DDRE = 0xFF;  //MOTOR CONTROL
    PORTE= 0x00;  //P      
   
    DDRH = 0x00; // PORTH input
    PTIH = 0X00; // KEY,PH0--5
    PERH = 0xff; // PORTH pull up  
    PPSH = 0x00; // Port H Polarity Select Register-falling edge
    PIEH = 0x80; // PORTH interrut disable,
                 // PH7判断奇偶场换场信号
   
    DDRJ = 0X00; // PJ0判断行同步脉冲到达
    //PPSJ = 0x01; // Port J Polarity Select Register-rising EDGE
    PPSJ = 0x00; // Port J Polarity Select Register-falling EDGE   
    PIEJ = 0X01; // VIDEO SYNC INTERRUPT DISABLED,BUT NOT IN MAIN()
    PERJ = 0xff;
   
    DDRM = 0XFF; // motor2的驱动模块MC33886的初始化子程序
    PTIM = 0X01; // ENM0=0,operating run;
    PERM = 0xff; // EN:PM0=1,full run;
   
    DDR1AD0=0xF8;
    PT1AD0 =0xFF;
}
void SetBusCLK_32M(void)
{   
    CLKSEL=0X00;    // disengage PLL to system
    PLLCTL_PLLON=1;   // turn on PLL
    SYNR =0x40 | 0x03;  // pllclock=2*osc*(1+SYNR)/(1+REFDV)=64MHz;                     
    REFDV=0xc0 | 0x01;
    POSTDIV=0x00;  
    _asm(nop);          // BUS CLOCK=32M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));   //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;          //engage PLL to system;  
}
void Dly_ms(int ms)
{
   int ii,jj;
   if (ms<1) ms=1;
   for(ii=0;ii<ms;ii++)
     //for(jj=0;jj<1335;jj++);  //16MHz--1ms
     for(jj=0;jj<2770;jj++);  //32MHz--1ms
     //for(jj=0;jj<4006;jj++);  //48MHz--1ms
     //for(jj=0;jj<5341;jj++);    //64MHz--1ms  
}

//============================MAIN()===========================
void main(void)
{
  /* put your own code here */
  byte i=0;
  
  Port_Init();            // initial board
  SetBusCLK_32M();  
  PORTB=0XFF;
  EnableInterrupts;
  for(;;)
  {
     Dly_ms(500);
     PORTB_PB1=~PORTB_PB1;
  }
  /* please make sure that you never leave this */
}
作者: zhwbiao123    时间: 2010-2-26 14:08
好东西!谢谢!
作者: zhwbiao123    时间: 2010-2-26 14:08
好东西!谢谢!
作者: 姚先生    时间: 2010-3-3 12:10
谢了
作者: chihua    时间: 2010-3-6 20:32
不错!
作者: shiftenter    时间: 2010-3-7 10:12
支持龙丘
作者: 凌风    时间: 2010-3-9 10:53
大家共同学习 共同进步
作者: qianjincheng    时间: 2010-3-10 17:49
xiexie
作者: 梧桐1209    时间: 2010-11-27 14:47
  大家共同学习 共同进步
作者: qaabq    时间: 2011-7-15 01:04
好东西!谢谢!
作者: pang5bo    时间: 2011-8-19 17:55
楼主在程序后面加个说明呗,我勉强看英文才看懂的




欢迎光临 智能车制作 (http://www.znczz.com/) Powered by Discuz! X3.2