/*---------------------------------------------------------------------------------------*/ /*-----------------------------------99s记数---------------------------------------------*/ #include #include #define uint unsigned int #define uchar unsigned char sbit CLK=P2^5; /*************时钟***********/ sbit STR=P2^6; /*************锁存***********/ sbit RData=P2^7; /*************数据***********/ void Timer0_Init(); uchar Shi,Temp,TT,Ge; uchar code Tab[][16]={ 0xFF,0xFF,0xF8,0x0F,0xF7,0xF7,0xEF,0xFB,0xEF,0xFB,0xF7,0xF7,0xF8,0x0F,0xFF,0xFF,/*"0",0*/ 0xFF,0xFF,0xF7,0xFB,0xF7,0xFB,0xE0,0x03,0xFF,0xFB,0xFF,0xFB,0xFF,0xFF,0xFF,0xFF,/*"1",1*/ 0xFF,0xFF,0xF1,0xF3,0xEF,0xEB,0xEF,0xDB,0xEF,0xBB,0xEE,0x7B,0xF1,0xF3,0xFF,0xFF,/*"2",2*/ 0xFF,0xFF,0xF3,0xE7,0xEF,0xFB,0xEE,0xFB,0xEE,0xFB,0xED,0x77,0xF3,0x8F,0xFF,0xFF,/*"3",3*/ 0xFF,0xFF,0xFF,0x1F,0xFC,0xDF,0xFB,0xDB,0xF7,0xDB,0xE0,0x03,0xFF,0xDB,0xFF,0xFF,/*"4",4*/ 0xFF,0xFF,0xE0,0x67,0xEF,0x7B,0xEE,0xFB,0xEE,0xFB,0xEF,0x77,0xEF,0x8F,0xFF,0xFF,/*"5",5*/ 0xFF,0xFF,0xF8,0x0F,0xF7,0x77,0xEE,0xFB,0xEE,0xFB,0xE7,0x77,0xFF,0x8F,0xFF,0xFF,/*"6",6*/ 0xFF,0xFF,0xE3,0xFF,0xEF,0xFF,0xEF,0x03,0xEC,0xFF,0xE3,0xFF,0xEF,0xFF,0xFF,0xFF,/*"7",7*/ 0xFF,0xFF,0xF1,0xC7,0xEE,0xBB,0xEF,0x7B,0xEF,0x7B,0xEE,0xBB,0xF1,0xC7,0xFF,0xFF,/*"8",8*/ 0xFF,0xFF,0xF8,0xFF,0xF7,0x73,0xEF,0xBB,0xEF,0xBB,0xF7,0x77,0xF8,0x0F,0xFF,0xFF,/*"9",9*/ }; void delay(uchar n) { while(n--); } void sendbyteR(uchar bbyte1) /*74HC595的驱动程序*/ { uchar i; for(i=0;i<8;i++) { RData=bbyte1&0x80; CLK=1; delay(2); CLK=0; bbyte1<<=1; _nop_(); _nop_(); } } void main() { uchar i; Timer0_Init(); while(1) { for(i=0;i<8;i++) { sendbyteR(Tab[Shi][i*2]); sendbyteR(Tab[Shi][i*2+1]); P0=i; STR=1; STR=0; delay(10); } for(i=8;i<16;i++) { sendbyteR(Tab[Ge][i*2-16]); /*因为i=8,i*2=16直接读到数组的第2个数据,因此要减去16*/ sendbyteR(Tab[Ge][i*2+1-16]); P0=i; STR=1; STR=0; delay(10); } } } void Timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; TT++; if(TT==20) { TT=0; Temp--; if(Temp==0) { Temp=99; } Shi=Temp/10; Ge =Temp%10; } } void Timer0_Init() { TH0=(65536-50000)/256; TL0=(65536-50000)%256; TMOD=0x01; EA=1; ET0=1; TR0=1; Temp=10; Ge=0; Shi=0; }