中级会员
- 积分
- 429
- 威望
- 230
- 贡献
- 127
- 兑换币
- 138
- 注册时间
- 2013-3-13
- 在线时间
- 36 小时
|
mc9s12xs128的外部中断的例子
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#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; //清除中断标志位
}
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
}
static void Port_Init(void)
{
DDRB = 0xff; //LED PTB0--7,
PORTB= 0xff; //LEDs on
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;
}
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 */
}
问一下,什么样的外部信号才能产生中断啊????
跪求答案
补充内容 (2013-9-9 22:07):
具体一点,向H7口上输入一个下降沿脉冲,就会进入中断函数吗?? |
|