計數時開始都是0,可是不久后就顯示亂碼, 有哪位高手幫助一下,小弟在這感激不盡了, 急呀,過兩天就要交板了!! 我Q是170074505,這兩天我會一直在線!!
#include <AT89x51.h> /********************************* 全局變量定義 *********************************/ unsigned char code pcode[]={215,17,205,93,27,94,222,21,223,95};//無小數點 unsigned char code chom[]={8,64,32,16,4,128}; //數碼管選擇 unsigned char temp[6]={0,0,0,0,0,0}; unsigned char T0count; unsigned char timecount; bit flag; unsigned long x; /****************************************************** 子函數定義 *******************************************************/ void t0(void) interrupt 1 using 1 { T0count++; }
void t1(void) interrupt 3 using 1 //定時2m { TH1=(65536-15536)/256; TL1=(65536-15536)%256; timecount++; if(timecount==40) { TR0=0; //T0停止計數 timecount=0; flag=1; } } void get_1() { x=(T0count*65536+TH0*256+TL0)/2; //低頻 } void get_2() { x=(T0count*65536+TH0*256+TL0)*8; //高頻 } void deal() //存六位數碼值 { int i; for(i=0;i<6;i++) { temp=x%10; x=x/10; } } void delay(unsigned dly) { unsigned i; for(;dly>0;dly--) for(i=50;i>0;i--); } void play() { int i; for(i=0;i<6;i++) { P1=pcode[temp]; //數碼顯示 P2=chom; //數碼管選擇 delay(10); } } /************************** 主函數,定時器0對外部脈沖計數,定時器1定時50m*40=2s; ****************************/ void main(void) { int a; TMOD=0x15; TH0=0; TL0=0; TH1=(65536-15536)/256; TL1=(65536-15536)%256; TR1=1; TR0=1; ET0=1; ET1=1; EA=1; while(1) { if(flag==1) { a=P3&0x80; if(a==0x80) get_2(); else get_1(); deal(); TR0=1; //重啟T0計數 flag=0; } play(); } }
|