用一個外部中斷讀取編碼器圈數(shù),用一個定時器實現(xiàn)30s倒計時,并將圈數(shù)和時間在LCD上顯示。程序編譯沒有問題,但LCD上出現(xiàn)跳動的亂碼,求高手幫幫忙呀~跪謝謝了~~
#include "lcd.h"
#include "common.h"
int degree=0;
int time=35;
int circle;
unsigned char xdata countdown[2];
unsigned char xdata circlestr[2];
void main(void)
{
IT0=1; //外部中斷0下降沿觸發(fā)
EA=1; //全局中斷打開
EX0=1; //允許外部中斷0
TMOD|=0x01; //定時器0 16位定時器 X=65535-10000(10毫秒)=55535=D8F0(十六進制)定時10ms
TH0=0xd8; //計數(shù)時間
TL0=0xf0;
IE=0x82; //這里是中斷優(yōu)先級控制EA=1(開總中斷),ET0=1(定時器0允許中斷),這里用定時器0來定時
TR0=1; //打開定時器0
circle=degree/360; //取圈數(shù)
circlestr[0]=circle/10+0x30; //取十位
circlestr[1]=circle%10+0x30; //取個位
countdown[0]=time/10+0x30; //取時間十位
countdown[1]=time%10+0x30; //取個位
LCD_Init( );
LCD_ClearScreen();
while( 1 )
{
LCD_ShowDot6x8Str(48, 1, circlestr); //LCD顯示圈數(shù)
LCD_ShowDot6x8Str(48, 0, countdown); // LCD顯示倒計時30s
}
}
void int0()interrupt 0 //外部中斷0
{
EA=0;
if(P3^3==0)
degree++;
else
degree--;
EA=1;
}
void tim(void) interrupt 1 using 1 //定時器0中斷
{
int count; //99只是一個數(shù),可以任意改,因為這里只學(xué)習(xí)怎樣實現(xiàn)倒計時
TH0=0xd8; //定時10毫秒
TL0=0xf0;
count++;
if(count==100) //10毫秒定時,10*100=1000(毫秒)=1秒
if(time>=0) time--;
}
[此貼子已經(jīng)被作者于2012-3-11 0:02:36編輯過]
|