单片机--ds1302
来源:互联网 发布:mac 显卡驱动 编辑:程序博客网 时间:2024/05/17 19:21
ds1302.h
#include "myhead.h"#define ds1302_sec_add 0x80 //??êy?Yµ??·#define ds1302_min_add 0x82 //·?êy?Yµ??·#define ds1302_hr_add 0x84 //ê±êy?Yµ??·#define ds1302_date_add 0x86 //è?êy?Yµ??·#define ds1302_month_add 0x88 //??êy?Yµ??·#define ds1302_day_add 0x8a //D??úêy?Yµ??·#define ds1302_year_add 0x8c //?êêy?Yµ??·#define ds1302_control_add 0x8e //????êy?Yµ??·#define ds1302_charger_add 0x90 #define ds1302_clkburst_add 0xbeunsigned char timebuf[3] = {17,59,5};unsigned char datebuf[3] = {16,8,17};unsigned char daybuf = 3;unsigned char writebuf[3] = {0};unsigned char readbuf[3] = {0};unsigned char disbuf[3] = {0};unsigned char writebuf1[3] = {0};unsigned char readbuf1[3] = {0};unsigned char disbuf1[3] = {0};unsigned char writebuf2 = 0;unsigned char readbuf2 = 0;unsigned char disbuf2 = 0;// void ds1302_write_byte(unsigned char addr,unsigned char byte)// {// unsigned char i;// // addr = addr & 0xfe;// SCK = 0;// RST = 0;// RST = 1;// for(i = 0;i < 8;i++)// {// IO = addr & 0x01;// SCK = 0;// SCK = 1;// addr >>= 1;// }// // for(i = 0;i < 8;i++)// {// IO = byte & 0x01;// SCK = 0;// SCK = 1;// byte >>= 1;// }// // SCK = 0;// RST = 0;// }unsigned char ds1302_read_byte(unsigned char addr){ unsigned char i; unsigned char temp; addr = addr & 0xfe; SCK = 0; RST = 0; RST = 1; addr = addr + 1; for(i = 0;i < 8;i++) { IO = addr & 0x01; SCK = 0; SCK = 1; addr >>= 1; } for(i = 0;i < 8;i++) { SCK = 1; SCK = 0; temp >>= 1; if(IO) { temp += 0x80; } } RST = 0; return temp;}// void ds1302_write_time()// {// unsigned char i;// unsigned char temp;// unsigned char temp1;// // for(i = 0;i < 3;i++)// {// temp = timebuf[i] / 10;// temp1 = timebuf[i] % 10;// writebuf[i] = (temp << 4) | temp1; // }// ds1302_write_byte(ds1302_control_add,0x00);// ds1302_write_byte(ds1302_hr_add,writebuf[0]);// ds1302_write_byte(ds1302_min_add,writebuf[1]);// ds1302_write_byte(ds1302_sec_add,writebuf[2]);// ds1302_write_byte(ds1302_control_add,0x80);// }void ds1302_read_time(){ unsigned char i; unsigned char temp; unsigned char temp1; readbuf[0] = ds1302_read_byte(ds1302_hr_add); readbuf[1] = ds1302_read_byte(ds1302_min_add); readbuf[2] = ds1302_read_byte(ds1302_sec_add); for(i = 0;i < 3;i++) { temp = readbuf[i] >> 4; temp1 = readbuf[i] & 0x0f; disbuf[i] = temp * 10 + temp1; }}void lcd_dis_time1(){ unsigned char lcdbuf[9] = {0}; lcdbuf[0] = (disbuf[0] / 10) + 0x30; lcdbuf[1] = (disbuf[0] % 10) + 0x30; lcdbuf[2] = ':'; lcdbuf[3] = (disbuf[1] / 10) + 0x30; lcdbuf[4] = (disbuf[1] % 10) + 0x30; lcdbuf[5] = ':'; lcdbuf[6] = (disbuf[2] / 10) + 0x30; lcdbuf[7] = (disbuf[2] % 10) + 0x30; lcd_dis_str(0,0,lcdbuf);}// void ds1302_write_day()// {// writebuf2 = daybuf % 10;// // ds1302_write_byte(ds1302_control_add,0x00);// ds1302_write_byte(ds1302_day_add,writebuf2);// ds1302_write_byte(ds1302_control_add,0x80);// }void ds1302_read_day(){ readbuf2 = ds1302_read_byte(ds1302_day_add); disbuf2 = readbuf2 & 0x0f;}void lcd_dis_day(){ switch(disbuf2) { case 0x01: { lcd_dis_str(13,1,"Mon"); break; } case 0x02: { lcd_dis_str(13,1,"Tue"); break; } case 0x03: { lcd_dis_str(13,1,"Wed"); break; } case 0x04: { lcd_dis_str(13,1,"Thu"); break; } case 0x05: { lcd_dis_str(13,1,"Fri"); break; } case 0x06: { lcd_dis_str(13,1,"Sat"); break; } case 0x07: { lcd_dis_str(13,1,"Sun"); break; } }}// void ds1302_write_date()// {// unsigned char i;// unsigned char temp;// unsigned char temp1;// // for(i = 0;i < 3;i++)// {// temp = datebuf[i] / 10;// temp1 = datebuf[i] % 10;// writebuf1[i] = (temp << 4) | temp1; // }// ds1302_write_byte(ds1302_control_add,0x00);// ds1302_write_byte(ds1302_year_add,writebuf1[0]);// ds1302_write_byte(ds1302_month_add,writebuf1[1]);// ds1302_write_byte(ds1302_date_add,writebuf1[2]);// ds1302_write_byte(ds1302_control_add,0x80);// }void ds1302_read_date(){ unsigned char i; unsigned char temp; unsigned char temp1; readbuf1[0] = ds1302_read_byte(ds1302_year_add); readbuf1[1] = ds1302_read_byte(ds1302_month_add); readbuf1[2] = ds1302_read_byte(ds1302_date_add); for(i = 0;i < 3;i++) { temp = readbuf1[i] >> 4; temp1 = readbuf1[i] & 0x0f; disbuf1[i] = temp * 10 + temp1; }}void lcd_dis_date(){ unsigned char lcdbuf[9] = {0}; lcdbuf[0] = (disbuf1[0] / 10) + 0x30; lcdbuf[1] = (disbuf1[0] % 10) + 0x30; lcdbuf[2] = '-'; lcdbuf[3] = (disbuf1[1] / 10) + 0x30; lcdbuf[4] = (disbuf1[1] % 10) + 0x30; lcdbuf[5] = '-'; lcdbuf[6] = (disbuf1[2] / 10) + 0x30; lcdbuf[7] = (disbuf1[2] % 10) + 0x30; lcd_dis_str(0,1,lcdbuf);}void ds1302(){ unsigned char flag = 1; unsigned char key; lcd_init(); //ds1302_write_time(); //ds1302_write_date(); //ds1302_write_day(); while(flag) { ds1302_read_time(); ds1302_read_date(); ds1302_read_day(); lcd_dis_time1(); lcd_dis_date(); lcd_dis_day(); key = key_scan(); if(0xe7 == key) { lcd_init(); lcd_over(); flag = 0; } }}
ds1302.h
#ifndef _DS1302_H#define _DS1302_Hextern void ds1302_write_byte(unsigned char addr,unsigned char byte);extern unsigned char ds1302_read_byte(unsigned char addr);//extern void ds1302_write_time();extern void ds1302_read_time();extern void lcd_dis_time1();//extern void ds1302_write_day();extern void ds1302_read_day();extern void ds1302_dis_day();//extern void ds1302_write_date();extern void ds1302_read_date();extern void lcd_dis_date();extern void ds1302();#endif
0 0
- 单片机--ds1302
- 【单片机】DS1302
- STC单片机 DS1302
- stc15f204单片机使用ds1302调试
- 单片机——ds1302代码
- 51单片机(AT89C52)DS1302时钟芯片程序
- AVR单片机(ATMEGA16)DS1302时钟芯片程序
- PIC单片机(PIC16F877A)DS1302芯片程序
- DS1302 中文资料+代码 单片机制作时钟
- STC单片机学习------DS1302时钟芯片
- 单片机复习笔记005 -- DS1302时钟芯片
- 51单片机DS1302实时时钟驱动程序
- 单片机笔记之DS1302实时时钟
- 51单片机的DS1302的驱动程序
- 单片机——ds1302时钟芯片
- 51单片机DS1302时钟芯片简单程序
- 单片机时钟程序(4)ds1302.c
- 单片机时钟程序(5)ds1302.h
- 微信api退款及退款查询
- 聊聊Android图像格式类及图像转换方法
- 学习态度
- 人见人爱A^B(HDU2035)
- 51nod 最长回文子串 V2(Manacher算法)
- 单片机--ds1302
- C++复习(2)派生类成员的标志与访问
- 文件输入/输出
- Android开发项目经验
- 为什么Java中1000==1000为false而100==100为true?
- 大时代势不可挡,隔行扫描已经消失。BT.709色彩空间也开始离我们远去
- 单片机之利用按键来使数码管上两位示数增加
- 如何学习基于ARM平台的嵌入式系统
- python的&众不同之处(2)