飞思卡尔单片机,我是新手,编了一个秒表的程序,但是但不运行后发现,程序跳不进中断?请高手指点!!! 5
#include<hidef.h>/*commondefinesandmacros*/#include"derivative.h"/*derivative-specifi...
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
char shu[]={0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,0xFE, 0xF6};
int sec,c;
void timer_init() ;
void delay(int cnt) {
int a,b;
for(a=100;a>0;a--)
for(b=cnt;b>0;b--);
}
void timer_init() {
TSCR1=0X90; //使能定时器并设置为自动清除标志TFLG1
TSCR2=0X04;//设置分频系数为16
TIE=0X01; //定时器通道0中断使能
TIOS_IOS0=1; //PT0口为输出比较
TC0=TCNT+5000; //设定初值 //定的时间就是从0加到5000要的时间
EnableInterrupts;
}
void main(void) {
/* put your own code here */
DDRB=0xff;
DDRP=0x03;
timer_init();
for(;;) {
PTP_PTP0=1;
PORTB=shu[sec/10];
delay(50);
PTP_PTP0=0;
PORTB=0x00;
PTP_PTP1=1;
PORTB=shu[sec%10];
delay(50);
PTP_PTP1=0;
PORTB=0x00;
// _FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vpit0 timer0(void){
DisableInterrupts;
c++;
if(c==20) {
sec++;
if(sec==60)
sec=0;
c=0;
}
TC0=TCNT+5000; //设定比较器下次中断时间
EnableInterrupts;
}
#pragma CODE_SEG DEFAULT 展开
#include "derivative.h" /* derivative-specific definitions */
char shu[]={0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,0xFE, 0xF6};
int sec,c;
void timer_init() ;
void delay(int cnt) {
int a,b;
for(a=100;a>0;a--)
for(b=cnt;b>0;b--);
}
void timer_init() {
TSCR1=0X90; //使能定时器并设置为自动清除标志TFLG1
TSCR2=0X04;//设置分频系数为16
TIE=0X01; //定时器通道0中断使能
TIOS_IOS0=1; //PT0口为输出比较
TC0=TCNT+5000; //设定初值 //定的时间就是从0加到5000要的时间
EnableInterrupts;
}
void main(void) {
/* put your own code here */
DDRB=0xff;
DDRP=0x03;
timer_init();
for(;;) {
PTP_PTP0=1;
PORTB=shu[sec/10];
delay(50);
PTP_PTP0=0;
PORTB=0x00;
PTP_PTP1=1;
PORTB=shu[sec%10];
delay(50);
PTP_PTP1=0;
PORTB=0x00;
// _FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vpit0 timer0(void){
DisableInterrupts;
c++;
if(c==20) {
sec++;
if(sec==60)
sec=0;
c=0;
}
TC0=TCNT+5000; //设定比较器下次中断时间
EnableInterrupts;
}
#pragma CODE_SEG DEFAULT 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询