📄 main.c
字号:
/*
实验十四:
DS1302时钟实险,LCD1602显示。
1、设置和读取DS1302内部时钟,并通过LCD1602显示。
2、内部1 M晶振,程序采用单任务方式,软件延时。
3、进行此实验请插上JP1、JP2的所有8个短路块,PC2、PC3、PC4、PC7短路块。
4、DS1302芯片接口占用JTAG仿真接口,在做实验时需要关闭mega16的JTAG功能。
5、此实验需要有LCD1602显示屏才可以显示。
6、此实验对硬件及芯片的综合知识要求比较高,所以建议大家把此实验放到后面。
此实验参照了版主tonghe的DS1302时钟程序。
AVR mega16学习板
www.iccavr.com
10:44 2007-5-10
*/
#include "iom16v.h"
#include "ds1302.h"
#include "lcd1602.h"
void main(void) {
unsigned char temp;
PORTA = 0xFF; /*打开上拉*/
DDRA = 0x00; /*方向输入*/
PORTB = 0xF0; /*电平设置*/
DDRB = 0xFF; /*方向输出*/
PORTC = 0x7F;
DDRC = 0x80;
PORTD = 0xFF;
DDRD = 0x00;
delay_ms(200);
LCD_init();
ds1302_init();
delay_ms(10);
ds1302_write_time();
while (1) {
delay_ms(200);
ds1302_read_time();
LCD_clear();
temp = (time_buf[0] >> 4) + '0';
LCD_write_char(0, 0, temp);/*年*/
temp = (time_buf[0] & 0x0F) + '0';
LCD_write_char(1, 0, temp);
temp = (time_buf[1] >> 4) + '0';
LCD_write_char(2, 0, temp);
temp = (time_buf[1] & 0x0F) + '0';
LCD_write_char(3, 0, temp);
LCD_write_char(4, 0, '-');
temp = (time_buf[2] >> 4) + '0';
LCD_write_char(5, 0, temp);/*月*/
temp = (time_buf[2] & 0x0F) + '0';
LCD_write_char(6, 0, temp);
LCD_write_char(7, 0, '-');
temp = (time_buf[3] >> 4) + '0';
LCD_write_char(8, 0, temp);/*日*/
temp = (time_buf[3] & 0x0F) + '0';
LCD_write_char(9, 0, temp);
temp = (time_buf[4] >> 4) + '0';
LCD_write_char(8, 1, temp);/*时*/
temp = (time_buf[4] & 0x0F) + '0';
LCD_write_char(9, 1, temp);
LCD_write_char(10, 1, ':');
temp = (time_buf[5] >> 4) + '0';
LCD_write_char(11, 1, temp);/*分*/
temp = (time_buf[5] & 0x0F) + '0';
LCD_write_char(12, 1, temp);
LCD_write_char(13, 1, ':');
temp = (time_buf[6] >> 4) + '0';
LCD_write_char(14, 1, temp);/*秒*/
temp = (time_buf[6] & 0x0F) + '0';
LCD_write_char(15, 1, temp);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -