標(biāo)題: LCD1602&DS1302時鐘測試程序+仿真圖分享 [打印本頁]

作者: HI-XM    時間: 2018-12-17 16:50
標(biāo)題: LCD1602&DS1302時鐘測試程序+仿真圖分享

comments :
1、八線制驅(qū)動LCD1602B:PB0-PB7為數(shù)據(jù)線,PD3/PD4/PD6控制LCD1602B的RS,RW,EN。
2、設(shè)置和讀取DS1302內(nèi)部時鐘,并通過LCD1602顯示。
3、進(jìn)行此實(shí)驗(yàn)請插上JP1、JP2的所有8個短路塊,PC2、PC3、PC4、PC7短路塊。
4、DS1302芯片接口占用JTAG仿真接口,在做實(shí)驗(yàn)時需要關(guān)閉mega16的JTAG功能,否則
   不正常顯示。

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include <iom16v.h>
  2. #include <macros.h>
  3. #include "ds1302.h"
  4. #include "LCD1602.h"

  5. void main(void)
  6. {
  7.         unsigned char temp;

  8.         Port_init();   //端口初始化
  9.         LCD_init();    //LCD初始化
  10.         LCD_clear();   //清屏
  11.         ds1302_init(); //DS1302初始化
  12.         delay_ms(10);
  13.         ds1302_write_time(); //寫入初始值

  14.         while (1)
  15.         {
  16.                 delay_ms(200);       //每200ms更新一次時間
  17.                 ds1302_read_time();  //讀取時間
  18.                 //LCD_clear();       //清屏
  19.                                
  20.                 temp = (time_buf[0] >> 4) + '0';
  21.                 LCD_write_char(0, 0, temp);/*年*/
  22.                 temp = (time_buf[0] & 0x0F) + '0';
  23.                 LCD_write_char(1, 0, temp);
  24.                 temp = (time_buf[1] >> 4) + '0';
  25.                 LCD_write_char(2, 0, temp);
  26.                 temp = (time_buf[1] & 0x0F) + '0';
  27.                 LCD_write_char(3, 0, temp);
  28.                 LCD_write_char(4, 0, '-');
  29.                
  30.                 temp = (time_buf[2] >> 4) + '0';
  31.                 LCD_write_char(5, 0, temp);/*月*/
  32.                 temp = (time_buf[2] & 0x0F) + '0';
  33.                 LCD_write_char(6, 0, temp);
  34.                 LCD_write_char(7, 0, '-');
  35.                
  36.                 temp = (time_buf[3] >> 4) + '0';
  37.                 LCD_write_char(8, 0, temp);/*日*/
  38.                 temp = (time_buf[3] & 0x0F) + '0';
  39.                 LCD_write_char(9, 0, temp);
  40.                
  41.                 LCD_write_str(0,1,"week:");
  42.                 temp = (time_buf[7]) + '0';
  43.                 LCD_write_char(5, 1, temp);  //周
  44.                
  45.                 temp = (time_buf[4] >> 4) + '0';
  46.                 LCD_write_char(8, 1, temp);  //時
  47.                 temp = (time_buf[4] & 0x0F) + '0';
  48.                 LCD_write_char(9, 1, temp);
  49.                 LCD_write_char(10, 1, ':');
  50.                
  51.                 temp = (time_buf[5] >> 4) + '0';
  52.                 LCD_write_char(11, 1, temp);/*分*/
  53.                 temp = (time_buf[5] & 0x0F) + '0';
  54.                 LCD_write_char(12, 1, temp);
  55.                 LCD_write_char(13, 1, ':');
  56.                
  57.                 temp = (time_buf[6] >> 4) + '0';
  58.                 LCD_write_char(14, 1, temp);/*秒*/
  59.                 temp = (time_buf[6] & 0x0F) + '0';
  60.                 LCD_write_char(15, 1, temp);
  61.         }
  62. }
復(fù)制代碼

所有資料51hei提供下載:
LCD1602&amp;DS1302時鐘測試.zip (183.08 KB, 下載次數(shù): 53)



作者: xiedong77777    時間: 2019-9-11 11:55
沒顯示啊 哥




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1