完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
新建文本文档 (3).rar
(2.48 KB, 下载次数: 17
)
|
|
相关推荐
2个回答
|
|
下载还要扣E币的啊
|
|
|
|
这里就是里面的程序
#include #define uint unsigned int #define uchar unsigned char ***it LCD_RS = P2^6; ***it LCD_RW = P2^5; ***it LCD_EP = P2^7; ***it SCLK=P3^6; //时钟 ***it IO=P3^4; //数据 ***it RST=P3^5;// DS1302复位 ***it beep=P1^5; uchar s1num=0,temp=0,day=0,year=0,mon=0,a=0,week=0,flag=0,num1=0,flag0=0,flag1=0,s4num=0; //flag1为是否达到闹钟时间,flag0为是否开启闹钟 char miao=0,shi=0,fen=0; char ashi,afen,amiao; //闹钟时分秒 //int num=0; uchar code table[]=" 20 - - "; uchar code table1[]=" : : "; //uchar code table2[7][3]={"THS","FRI","STA","SUN","MON","TUS","WED"}; uchar code ping[]={31,28,31,30,31,30,31,31,30,31,30,31}; uchar code run[]={31,29,31,30,31,30,31,31,30,31,30,31}; //延时函数 void delay(uchar z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } //蜂鸣器函数 void wybeep() { beep=1; delay(10); beep=0; delay(10); } //测忙函数 bit lcd_bz() { bit result; LCD_RS = 0; LCD_RW = 1; LCD_EP = 1; delay(5); result = (bit)(P0 & 0x80); //检测P0最高位是否为1 LCD_EP = 0; return result;//返回侧忙结果 } //LCD1602写指令函数(4位数据口) void write_com_8bit(uint com) { // 写入指令数据到LCD while(lcd_bz()); LCD_RS = 0; LCD_RW = 0; LCD_EP = 0; delay(1); P0 = com; //将高4位位指令通过P0口传给1602 delay(5); LCD_EP = 1; delay(5); LCD_EP = 0; } void write_com(uint com) //写命令函数 { while(lcd_bz()); LCD_RS = 0; LCD_RW = 0; LCD_EP = 0; delay(5); P0 = com; delay(5); LCD_EP = 1; delay(5); LCD_EP = 0; delay(5); P0 = (com&0x0f)<<4; delay(5); LCD_EP = 1; delay(5); LCD_EP = 0; } //LCD1602写数据函数 void write_data(uint date) { while(lcd_bz()); LCD_RS = 1; LCD_RW = 0; LCD_EP = 0; delay(5); P0 =date; delay(5); LCD_EP = 1; delay(5); LCD_EP = 0; LCD_RS = 1; LCD_RW = 0; LCD_EP = 0; delay(5); P0 = (date&0x0f)<<4; delay(5); LCD_EP = 1; delay(5); LCD_EP = 0; } //DS1302写一个字节数据 void write_byte(uchar date) { for (a=0;a<8;a++) //循环8次 写入数据 { SCLK=0; IO=date&0x01; delay(1); date>>=1; SCLK=1; delay(1); } } //向1302芯片写函数,指定写入地址,数据 void write_1302(uchar add,uchar date) { RST=0; delay(1); SCLK=0; delay(1); RST=1; delay(1); write_byte(add); write_byte(date); delay(1); RST=0; } //DS1302读数据函数 uchar read_1302(uchar add) { uchar date; delay(1); RST=1; add=add|0x01; for(a=0;a<8;a++) { if (add & 0x01) { IO=1; } else { IO=0; } SCLK=1; delay(1); SCLK=0; add=add>> 1; } for (a = 0; a < 8; a ++) { date=date>> 1; if (IO) { date |= 0x80; } else { date &= 0x7F; } SCLK=1; SCLK=0; } RST=0; //停止DS1302总线 return date; } //时分秒分离函数 void write_sfm(uchar add,uchar shu) { uchar shi,ge; shi=shu/10; //分离操作 ge=shu%10; write_com(0x80+0x40+add); //地址指向 write_data(0x30+shi); write_data(0x30+ge); } //年月日分离函数 void write_ymd(uchar add3,uchar shu3) { uchar shi,ge; shi=shu3/10; //分离操作 ge=shu3%10; write_com(0x80+add3); //地址指向 write_data(0x30+shi); write_data(0x30+ge); } //星期输出函数 void display_week(uchar week) { switch(week) { case 1:write_com(0x80+13);write_data('M');write_data('O');write_data('N');break; case 2:write_com(0x80+13);write_data('T');write_data('U');write_data('S');break; case 3:write_com(0x80+13);write_data('W');write_data('E');write_data('N');break; case 4:write_com(0x80+13);write_data('T');write_data('H');write_data('U');break; case 5:write_com(0x80+13);write_data('F');write_data('R');write_data('I');break; case 6:write_com(0x80+13);write_data('S');write_data('A');write_data('T');break; case 7:write_com(0x80+13);write_data('S');write_data('U');write_data('N');break; } } //BCD码转十进制函数,输入BCD,返回十进制 uchar BCD(uchar bcd) { return(bcd/16*10+bcd%16); } //十进制转十六进制函数 uchar tentosixteen(uchar num) { return(num/10*16+num%10); } //向DS1302中写入初始时间数据 void shijian_init() { write_1302(0x8e,0x00); //允许写,禁止写保护 delay(1); write_1302(0x80,tentosixteen(0)); delay(1); write_1302(0x82,tentosixteen(37)); delay(1); write_1302(0x84,tentosixteen(16)); delay(1); write_1302(0x8a,tentosixteen(1)); delay(1); write_1302(0x86,tentosixteen(29)); delay(1); write_1302(0x88,tentosixteen(7)); delay(1); write_1302(0x8c,tentosixteen(13)); delay(1); write_1302(0x90,0x05); delay(1); write_1302(0x8e,0x80); //打开写保护 } //向DS1302写入闹钟时间数据/ /*void DS_set_atime() { write_1302(0x8e,0x00); //允许写,禁止写保护 delay(1); write_1302(0x80,tentosixteen(amiao)); delay(1); write_1302(0x82,tentosixteen(afen)); deay(1); wrilte_1302(0x84,tentosixteen(ashi)); delay(1); write_1302(0x8a,tentosixteen(aweek)); delay(1); write_1302(0x86,tentosixteen(aday)); delay(1); write_1302(0x88,tentosixteen(amon)); delay(1); write_1302(0x8c,tentosixteen(ayear)); delay(1); write_1302(0x90,0x05); delay(1); write_1302(0x8e,0x80); //打开写保护 } */ //从DS1302中获取时间数据 void DS_gettime() { miao=BCD(read_1302(0x81)); delay(1); fen=BCD(read_1302(0x83)); delay(1); shi=BCD(read_1302(0x85)); delay(1); year=BCD(read_1302(0x8d)); delay(1); mon=BCD(read_1302(0x89)); delay(1); day=BCD(read_1302(0x87)); delay(1); week=BCD(read_1302(0x8b)); } //初始化函数 void init() { uchar num; //DS1302初始化部分 RST=0; SCLK=0; RST=1; //定时器初始化 TMOD|=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; //LCD1602初始化部分 write_com_8bit(0x38); delay(1); write_com_8bit(0x38); delay(1); write_com_8bit(0x28); delay(1); write_com(0x28); delay(1); write_com(0x06); delay(1); write_com(0x0c); delay(1); write_com(0x01); delay(1); write_com(0x80); for(num=0;num<16;num++) { write_data(table[num]); delay(5); } write_com(0x80+0x40); for(num=0;num<12;num++) { write_data(table1[num]); delay(5); } write_com(0x80+0x40+0x13); write_data('O'); write_data('F'); write_data('F'); } void display_time() { write_ymd(4,year); delay(1); write_ymd(7,mon); delay(1); write_ymd(10,day); delay(1); display_week(week); delay(1); write_sfm(4,shi); delay(1); write_sfm(7,fen); delay(1); write_sfm(10,miao); } //键盘使用时对每个月天数做判断 void pingrun() { if((year%4==0&&year%100!=0)||(year%400==0)) flag=1; else flag=0; } //对是否到达闹钟时间进行判断 void alarm() { if(ashi==shi && afen==fen && amiao==miao) flag1=1; else flag1=0; } //主函数 void main() { init(); while(1) { //keyscan(); DS_gettime(); display_time(); /*if(flag1==1) //闹钟时间到达时闹钟响 { flag1=0; wybeep(); delay(20); beep=0; write_com(0x80+0x40+0x13); write_data('O'); write_data('F'); write_data('F'); }*/ } } //定时器0函数 void timer0() interrupt 1 { static unsigned int num; TH0=(65536-50000)/256; TL0=(65536-50000)%256; num++; if(num==20) { num=0; } } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
238 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
629 浏览 0 评论
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】(第三篇)ADC采集+PWM输出
552 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十五章 人脸识别实验
552 浏览 0 评论
1074 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11764 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 00:44 , Processed in 0.596879 second(s), Total 74, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号