原创
ATmega16_App_V1.0开发板范例5:LCD1602&DS1302时钟实验(ICC)
一、
程序结构
二、
仿真效果
三、main主函数
- /*******************************************************************************
- Platform : ATmega16_App_V1.0开发板(http://bbs.armavr.com)
- Project : 范例5:LCD1602&DS1302时钟实验(ICC)
- Clock F : 内部8M
- Software : ICCAVR7.14C+proteus7.5
- Author : 林夕依然
- Version : 09.11.03
- Updata :
- comments :
- 1、八线制驱动LCD1602B:PB0-PB7为数据线,PD3/PD4/PD6控制LCD1602B的RS,RW,EN。
- 2、设置和读取DS1302内部时钟,并通过LCD1602显示。
- 3、进行此实验请插上JP12的第1、2针短路块,并将LCD1602插在相应的座上,注意方向。
- 4、DS1302芯片接口占用JTAG仿真接口,在程序烧录时需要关闭mega16的JTAG功能,否则
- 不正常显示。
- *******************************************************************************/
- #include <iom16v.h>
- #include <macros.h>
- #include "ds1302.h"
- #include "LCD1602.h"
- void main(void)
- {
- unsigned char temp;
- delay_ms(200); //延时,使用上电稳定
- Port_init(); //端口初始化
- LCD_init(); //LCD初始化
- LCD_clear();
- ds1302_init(); //DS1302初始化
- delay_ms(10);
- ds1302_write_time(); //写入初始值
- while (1)
- {
- delay_ms(200); //每200ms更新一次时间
- 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);
- LCD_write_str(0,1,"week:");
- temp = (time_buf[7]) + '0';
- LCD_write_char(5, 1, 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);
- }
- }
四、完整项目文件
https://static.assets-stash.eet-china.com/album/old-resources/2009/11/9/f58873eb-f961-43c2-9308-c5a660af021d.rar
用户377235 2011-12-28 19:36