《DS1302数码管显示程序(最新整理)》由会员分享,可在线阅读,更多相关《DS1302数码管显示程序(最新整理)(9页珍藏版)》请在人人文库网上搜索。
1、*/huaqinMCU DS1302 实验程序 数码管显示 时钟设置说明/8 键为时钟设置、时分切换、保存 0 键为加 4 键为减/*/ #include #define uchar unsigned char #define uint unsigned int/=以下 IO 定义请根据您硬件的连接修改= sbit T_RST=P35;/ds1302-5sbit T_IO=P34;/ds1302-6 sbit T_CLK=P36;/ds1302-7 sbit ACC0=ACC0;sbit ACC7=ACC7;/累加器 A 51 单片机原理中有介绍sbit up=P31;sbit down=P3。
2、2; sbit set=P30;uchar a,b,clock_ss,clock_sg,clock_fs,clock_fg,clock_ms,clock_mg; int hour,mie,sei;uchar clk_time3;/秒,分,时寄存器初始值code uchar ledmap=0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x40;/数码管段码/*DS1302:写入操作(上升沿)*/ void write_byte(uchar da)uchar i; ACC=da;for(i=8;i0;i-)T_IO=ACC0;T_CLK=0。
3、;T_CLK=1;ACC=ACC1;/*DS1302:读取操作(下降沿)*/ uchar read_byte(void)uchar i;for(i=0;i1;T_CLK = 1;T_CLK = 0; ACC7 = T_IO;return(ACC);/*DS1302:写 入 数 据 ( 先 送 地 址 , 再 写 数 据 )*/ void write_1302(uchar addr,uchar da)T_RST=0;/停止工作T_CLK=0;T_RST=1;/重新工作write_byte(addr);/写入地址write_byte(da); T_RST=0; T_CLK=1;/*DS1302:读。
4、 取 数 据 ( 先 送 地 址 , 再 读 数 据 )*/ uchar read_1302(uchar addr)uchar temp;T_RST=0; T_CLK=0;T_RST=1;/停止工作/重新工作write_byte(addr);/写入地址temp=read_byte();T_RST=0;T_CLK=1;/停止工作return(temp);/*延时程序=a*1ms*/ void delay(uchar a)uchar i; while(a- !=0)/ led_disp(); for(i=0;i=24)hour=0;delayAJ(10);if(b=2)mie+; if(mie=6。
5、0)mie=0;delayAJ(10);/以上时钟+设定if(down=0)delayAJ(5);/消抖if(down=0)delayAJ(5); if(b=1)hour-; if(hour0)hour=23;delayAJ(10);if(b=2)mie-; if(mie0)mie=59;delayAJ(10);/以上时钟-设定/*以下是转 BCD 码的程序 DS1302 认 BCD 码clock_s1=hour/10;clock_s2=hour%10; clock_s1=clock_s1&0xff; clock_s2=clock_s2&0xff; clock_s1=4; clock_s1=c。
6、lock_s1|clock_s2;/10to16clock_f1=mie/10; clock_f2=mie%10;clock_f1=clock_f1&0xff; /全 1 出 1 与运算clock_f2=clock_f2&0xff; clock_f1=4; clock_f1=clock_f1|clock_f2;/10to16/*转 BCD 码的程序 DS1302 认 BCD 码if(b=3)b=0;write_1302(0x8e,0x00); /WP=0 写操作write_1302(0x80,0x01);/0x80 是写秒数据此处写进01秒write_1302(0x82,clock_f1);/。
7、0x82 是写分数据write_1302(0x84,clock_s1);/0x84 是写时数据write_1302(0x8e,0x80); /WP=1 写保护delay(255);/*主程序*/ void main(void)uchartemp=0x80; uchar i;b=0;P3=0xff;while(1)temp=0x81;/读的初始地址for(i=0;i3;i+)/分别把秒分时数据读出分 3 次读好一次地址加 2 temp+=2;clk_timei=read_1302(temp); temp+=2;key();/键盘扫描“”“”At the end, Xiao Bian gives 。
8、you a passage. Minand once said, people who learn to learn are very happy people. In every wonderful life, learning is an eternal theme. As a professional clerical and teaching position, I understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous lear。
9、ning can achieve better self. Only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet the needs of the market. This document is also edited by my studio professionals, there may be errors in the document, if there are errors, please correct, thank you。