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