|
大佬幫忙看下中斷服務(wù)程序和初始化部分有什么問(wèn)題,在Proteus里仿真的時(shí)候LCD屏不顯示數(shù)字。
void init() //定時(shí)器0初始化
{
EA=1;
EX0=1;//開(kāi)外部INTO中斷
IT0=1; //INT0負(fù)跳變觸發(fā)
EX1=1;//開(kāi)外部INT1中斷
IT1=1; //INT1負(fù)跳變觸發(fā)
TMOD=0x01;//定時(shí)器0工作于方式1
TH0=0x3c; //50ms
TL0=0xb0;
ET0=1;//開(kāi)定時(shí)中斷
TR0=1;//啟動(dòng)定時(shí)
}
void display() //顯示函數(shù)
{
Velocity3=Velocity1+Velocity2;
Velocity=Velocity3/2;
Mileage=Mileage+Velocity*500/36;
write_1602com(0x80+2);
if(Velocity/100==0)
write_1602dat(' ');
else
write_1602dat(0x30+Velocity/100);
if((Velocity/100+Velocity%100/10)==0)
write_1602dat(' ');
else
write_1602dat(0x30+Velocity%100/10);
write_1602dat(0x30+Velocity%10);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602com(0x80+14);
if((VH/10)==0)
write_1602dat(' ');
else
write_1602dat(0x30+VH/10);
write_1602dat(0x30+VH%10);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602com(0x80+0x40+8);
write_1602dat(0x30+Mileage/1000000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602dat(0x30+Mileage%1000000/100000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602com(0x80+0x40+11);
write_1602dat(0x30+Mileage%100000/10000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602dat(0x30+Mileage%10000/1000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
write_1602dat(0x30+Mileage%1000/100);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
}
void main() //主函數(shù)
{
lcd_init();
init;
while(1)
{
anjian();
display();
alarm();
}
}
void EXINT0() interrupt 0 //外部中斷函數(shù)
{
count1++; //有信號(hào)加
}
void EXINT1() interrupt 2 //外部中斷函數(shù)
{
count2++; //有信號(hào)加
}
void time0() interrupt 1 //定時(shí)器中斷執(zhí)行函數(shù)
{
uchar m;
TH0=0x3c;
TL0=0xb0; //50ms
m++;
if(m%5==0&&flag_alarm==1)
{
BUZZ=!BUZZ;
}
if(m>=10)
{
Velocity1=count1/5;//(速度是將500ms內(nèi)的脈沖數(shù)除以5)(此處的速度值和轉(zhuǎn)數(shù)沒(méi)有計(jì)算公式,只是為了得到一個(gè)隨轉(zhuǎn)速大小變化的速度值)
Velocity2=count2/5;
m=0;
count1=0;
count2=0;
}
}
|
|