#include <reg51.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int sbit SEC=P1^7; sbit MIN=P1^6; sbit HOU=P1^5; uchar code table[]= //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // {0xc0,0xF9,0xA4,0xB0,0x99, //0 1 2 3 4 5 6 7 8 9 A B C D E F OFF - // 0x92,0x82,0xF8,0x80,0x90, 0x88,0x83,0xc6,0xa1,0x86, 0x8e,0xff,0xbf};
void delay(uint); uchar econd[8]={16,16,16,16,16,16,16,16}; void display(unsigned char display_buffer[8]); uchar flag=0,hour=12,minute=0,second=0; void main() { uchar keyval=0,miao=0; EA=1; ET0=1; TMOD=0X11; TH0=(65535-50000)/256; TL0=(65535-50000)%256; TR0=1; // econd[0]=1; // // econd[1]=2; //显示hour econd[2]=17; //显示 - // econd[3]=0; // // econd[4]=0; //显示minute econd[5]=17; //显示 - // econd[6]=0; // // econd[7]=0; //显示second
while(1) { if(flag==20) { flag=0; second++; } if(second==60) {second=0;minute++;} if(minute==60) {minute=0;hour++;} if(SEC==0) {delay(5);if(SEC==0){while(!SEC);}second++;} if(MIN==0) {delay(5);if(MIN==0){while(!MIN);}minute++;} if(HOU==0) {delay(5);if(HOU==0){while(!HOU);}hour++;} ///////////////////////////////////////////////// econd[6]=second/10; econd[7]=second%10; ///////////////////////////////////////////////// ///////////////////////////////////////////////// econd[3]=minute/10; econd[4]=minute%10; ///////////////////////////////////////////////// ///////////////////////////////////////////////// econd[0]=hour/10; econd[1]=hour%10; ///////////////////////////////////////////////// display(econd); } }
/////////////////////////////////////////////////////// void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=100;y>0;y--); }
////////////////////////////////////////////////// void display(unsigned char display_buffer[8]) { uchar temp,i; temp=0x01; for(i=0;i<8;i++) { P2=temp; temp=_crol_(temp,1); P0=table[display_buffer]]; delay(2); } } void timer0() interrupt 1 { TH0=(65535-50000)/256; //延时50ms TL0=(65535-50000)%256; flag++; }
|