sbit MERCLK=P1^0; sbit TIMERIO=P1^ 1; sbit TIMERRST=P1^2; sbit WDT=P1^3; uchar bdata DS 1302dat; sbit ds1302datHbit=DSI302ciat"7; sbit ds1302datBit=DS1302dat^0; uchar bdata DS 1302adr; shit ds1302adrBit=DS1302adr^0; uchar idata SEC; uchar idata MIN; uchar idata HR; uchar idata DATE; uchar idata MONTH; uchar idata DAY; uehar idata YEAR; void delay(uchar time) { uchar i,j; for(i=0;i<time;i++) { for(j=0;j<time;j++) { WDT=~ WDT; } } void writeDS1302(uchar d5RanlAdr,UChar ds1302data) { uchar i; TIMERCLK=0; delay(2); TIMERRST=1; delay(2); DS1302adr=dsRamAdr; DS 1302dat=ds 1302data; fof(i=0;i<3;i++) { CY=O; TIMERCLK=0; CY=ds13G2adrBit; TIMERIO=CY; delay(2); TIMERCLK=1; DS 1302adr=DS 1302adr>>1; } for(i=0;i<8;i++) { CY=0; TIMERCLK=0; CY=ds1302datBit; TIMERIO=CY; delay(2); TIMERCLK=1 ; DS-1302dat=DS-1302dat>>1; } TIMERRST=0; delay(2); TIMERCLK=0; } uchar readDS-1302(uchar DS 1302Adr) { uchar i; TIMERCLK=0; delay(2); TIMERRST=1; delay(2); DS 1302adr=DS 1302Adr; for(i=0;i<8;i++) { TIMERCLK=0; TIMERIO=ds-1302adrBit; delay(2); TIMERCLK=1; DS-1302adr=DS-1302adr>>1; TIMERIO=1; for(i=0;i<7;i++) { TIMERCLK=0; ds-1302datHbit=TIMERIO; TIMERCLK=1; DS 1302dat=DS 1302dat; l; TIMERCLK=0; ds-1302datHbit=TIMERIO; } TIMERRST=0; delay(2); TIMERCLK=0; return DS 1302dat; } TIMERCLK=0; Ds 1302datHbit=TIMERIO; void DS 13021nitial(void) 〔 uchar ds1302st; TIMERCLK=0; TIMERRST=0; ds1302st=readDS1302(0x0c1); if(ds1302st!=0x55) { W DT=~WDT; writeDS1302(0x8e,0x00); writeDS 1302(0x82,0x00); writcDS1302(0x84,0x1b); writeDS1302(0x86,0x19); WDT=~WDT; writeDS 1302(0x88,0x09); \vriteDS1302(0x8a,0x02); writeDS 1302(0x8c, 0x00); WDT=~WDT; writeDS1302(0x90,0x0a6); (vriteDS 1302 (0x0C0,0X55); writeDS 1302(0x80;0x00); void readRTC(void) { MONTH=readDS 1302(0x89); DATE=readDS 1302(0x87); HR=readDS 1302(0x85); MIN=readDS 1302(0x83); }