用串口1打印出年与日时分秒。亲测无误,普通IO模拟I2C
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "usmart.h"
- #include "24cxx.h"
- #include "myiic.h"
- #define SIZE sizeof(TEXT_Buffer)
- int main(void)
- {
- int second,minute,hour,week,day,month,year;
- delay_init(); //延时函数初始化
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(9600); //串口初始化为9600
- usmart_dev.init(72); //初始化USMART
- AT24CXX_Init(); //IIC初始化
- Write1307(0x00,0x00);
- Write1307(0x01,0x00);
- Write1307(0x02,0x00);
- Write1307(0x03,0x00);
- Write1307(0x04,0x0b);
- Write1307(0x05,0x09);
- Write1307(0x06,0x12);
- while(1)//检测不到24c02
- {
- second=Read1307(0x00);
- minute=Read1307(0x01);
- hour=Read1307(0x02);
- week=Read1307(0x03);
- day=Read1307(0x04);
- month=Read1307(0x05);
- year=Read1307(0x06);
- printf("%d.%d.%d\n",year,month,day);
- printf("%d:%d:%d",hour,minute,second);
- delay_ms(1000);
- // printf("11111\n");
- }
- }
复制代码
所有资料51hei提供下载:
ds1307.rar
(323.62 KB, 下载次数: 333)
|