數(shù)碼管顯示的電子時(shí)鐘C51程序 作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對(duì)面交流海量資料庫(kù)查詢(xún) 收藏 /*************************************************************功能: 實(shí)現(xiàn)電子時(shí)鐘顯示(C)定義: P2口位選,P0口段選 時(shí)間: 2010—11—26*************************************************************/#includecode unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char StrTab[6]; unsigned char minute=30,hour=12,second=0; void Displaypro(void){ StrTab[0]=tab[second%10]; StrTab[1]=tab[second/10]; StrTab[2]=tab[minute%10]; StrTab[3]=tab[minute/10]; StrTab[4]=tab[hour%10]; StrTab[5]=tab[hour/10]; }main(){ TMOD |=0x01; TH0=0xd8; TL0=0xf0; ET0=1; TR0=1; TMOD |=0x10; TH1=0xF8; TL1=0xf0; ET1=1; TR1=1; EA =1; while(1){;} }void time1_isr(void) interrupt 3{ static unsigned char num; TH1=0xf8; TL1=0xf0; switch (num) { case 0:P2=0x01;P0=StrTab[num];break; case 1:P2=0x02;P0=StrTab[num];break; case 2:P2=0x04;P0=StrTab[num];break; case 3:P2=0x08;P0=StrTab[num];break; case 4:P2=0x10;P0=StrTab[num];break; case 5:P2=0x20;P0=StrTab[num];break; default:break; } num++; if(num==6) num=0;}void tim(void) interrupt 1{ static unsigned char count; TH0=0xd8; TL0=0xf0; count++; switch (count) { case 0: case 20: case 40: case 60: case 80:Displaypro();break; default:break; } if (count==100) { count=0; second++; if(second==60) { second=0; minute++; if(minute==60) { minute=0; hour++; if(hour==24) hour=0; } } }}//源代碼下載 :http://www.51hei.com/f/szc511.rar 上一頁(yè) 1 2 下一頁(yè)
評(píng)論