1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| #include "led_1602.h" #include "ds1302.h" #include <at89x52.h>
uint i=0;
void display_time_week(uint cl_week,uint w_local); void display_time_date(uint *timep);
void delay (uint xms);
uchar dis_wel[]="Welcome!"; uchar dis_blog[]="www.erf172.tk"; uchar dis_week[]="SunMonTueWedThuFriSat";
extern uint *TIME_P;
uint time[7]={0x00,0x51,0x17,0x11,0x09,3,0x19};
void main() { TIME_P=time;
_1602_init(); _1602_command(0x80);
while(dis_blog[i]!='\0') { _1602_data(dis_blog[i]); i++; }
_1602_command(0xc0); i=0;
while(dis_wel[i]!='\0') { _1602_data(dis_wel[i]); i++; }
delay(5000);
Ds1302Init();
_1602_command(1);
while (1){ Ds1302ReadTime(); display_time_date(TIME_P);
}
}
void display_time_date(uint *timep) {
uint i=0; uchar time_display_date[10]={'2','0',0,0,'/',0,0,'/',0,0}; uchar time_display_clock[8]={0,0,':',0,0,':',0,0}; uchar time_display_week=0;
time_display_date[2]=*(timep+6)/16+'0'; time_display_date[3]=*(timep+6)%16+'0'; time_display_date[5]=*(timep+4)/16+'0'; time_display_date[6]=*(timep+4)%16+'0';
time_display_date[8]=*(timep+3)/16+'0'; time_display_date[9]=*(timep+3)%16+'0';
time_display_clock[0]=*(timep+2)/16+'0'; time_display_clock[1]=*(timep+2)%16+'0';
time_display_clock[3]=*(timep+1)/16+'0'; time_display_clock[4]=*(timep+1)%16+'0'; time_display_clock[6]=*(timep+0)/16+'0'; time_display_clock[7]=*(timep+0)%16+'0';
time_display_week=*(timep+5)%7; _1602_command(0x83);
for ( i = 0; i < 10; i++) { _1602_data(time_display_date[i]); } _1602_command(0xc6);
for ( i = 0; i < 8; i++) { _1602_data(time_display_clock[i]); }
_1602_command(0xc2); _1602_data(time_display_week);
display_time_week(time_display_week,0xc2); }
void display_time_week(uint cl_week,uint w_local) {
_1602_command(w_local); uint j=0; j=cl_week*3; while(j<=cl_week*3+2) { _1602_data(dis_week[j]); j++; } }
void delay(uint xms) { unsigned int x,y; for(x=xms;x>0;x--) for(y=110;y>0;y--); }
|