单片机源程序如下:
- #include "reg51.h"
- #include "ds1302.h"
- #define uc unsigned char
- uc tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,
- 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xc1};
- uc duan[8];
- unsigned int ms;
- bit flag;
- unsigned char key,qiehuan;
- unsigned char moshi;
- bit anxia;
- unsigned char discom,wei;
- unsigned int canshu=23;
- void delay(unsigned int k)
- {
- unsigned char i;
- for(i=0;i<k;i++);
- }
- void Init()
- {
- P2=P2&0X1F|0X80;
- P0=0XFF;
- P2&=0X1F;
- P2=P2&0X1F|0XA0;
- P0=0X00;
- P2&=0X1F;
- }
- void display()
- {
- for(discom=0;discom<8;discom++)
- {
- P3=0X00;
- P3=1<<discom;
- P2=tab[duan[discom]];
- delay(200);
- }
- }
- void time0_Init()
- {
- TMOD = 0x01; //设置定时器模式
- TL0 = (65536-10)%256; //设置定时初值
- TH0 = (65536-10)/256; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1;
- EA=1;
- ET0=1;
- }
- void time0()interrupt 1
- {
-
- ms++;
- if(ms==1)
- {ms=0;
-
- }
- display();
- }
- void main()
- {
- Init();
- time0_Init();
- SETRTC();
- while(1)
- {
- display();
- RTC();
- duan[0]=TIM[2]>>4;
- duan[1]=TIM[2]&0X0F;
- duan[2]=11;
- duan[3]=TIM[1]>>4;
- duan[4]=TIM[1]&0X0F;
- duan[5]=11;
- duan[6]=TIM[0]>>4;
- duan[7]=TIM[0]&0X0f;
- }
- }
复制代码
仿真程序:
DS1302程序 仿真.zip
(78.29 KB, 下载次数: 7)
|