標(biāo)題: 51單片機(jī)ILI9341彩屏版萬(wàn)年歷仿真(DS3231時(shí)鐘 240128LCD驅(qū)動(dòng)源程序) [打印本頁(yè)]

作者: zh123456    時(shí)間: 2018-1-21 14:35
標(biāo)題: 51單片機(jī)ILI9341彩屏版萬(wàn)年歷仿真(DS3231時(shí)鐘 240128LCD驅(qū)動(dòng)源程序)
ILI9341tft屏幕的單片機(jī)驅(qū)動(dòng)給廣大網(wǎng)友做參考,由于時(shí)間寫的參促,難免有錯(cuò)希望大家指出.
單片機(jī)彩屏版萬(wàn)年歷仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)



單片機(jī)源程序如下(主程序):

  1. #include <REGX55.H>
  2. #include "TFT.H"
  3. #include "TFT_GDI.H"
  4. #include "DS3231.h" //如果不測(cè)試時(shí)間請(qǐng)注銷它
  5. void Travel_time();
  6. void Display_stc(void);
  7. void Display_dyn_time(void);//顯示需更新的界面
  8. void Display_dyn_rili(void);//顯示需更新的界面
  9. //=========================================================================
  10. //本程序用來(lái)學(xué)習(xí)彩屏應(yīng)用,以及時(shí)鐘寫法,學(xué)習(xí)鐘能深入了解51編程,讓你展握編輯思想.
  11. //時(shí)間調(diào)整程序,留給各位網(wǎng)友,發(fā)揮自己想象
  12. //如果有能力,可以采用GPS調(diào)時(shí).
  13. //=========================================================================
  14. void main()
  15. {
  16.         //寫時(shí)間為了測(cè)試用,
  17.         IIC_single_byte_write(0x00,0x54);
  18.         IIC_single_byte_write(0x01,0x59);
  19.         IIC_single_byte_write(0x02,0x23);
  20.         
  21.         IIC_single_byte_write(0x04,0x15);
  22.         IIC_single_byte_write(0x05,0x02);
  23.         IIC_single_byte_write(0x06,0x18);
  24.         //不用測(cè)試時(shí)間請(qǐng)注銷
  25.         LCD_Init();
  26.         Display_stc();
  27.         Display_dyn_time();
  28.         Display_dyn_rili();
  29.         
  30.         while(1)
  31.         {
  32.                 Travel_time();
  33.         }
  34. }
復(fù)制代碼
TFT_GDI.C
  1. #include "TFT.H"
  2. #include "TFT_GDI.H"

  3. void LcdPutStr(RECT rect,unsigned int color,unsigned int bkcolor,unsigned char* GB_font,unsigned int font_num)
  4. {//四個(gè)參數(shù)分別起啟地址X與Y,字體顏色,字體背景色,要顯示數(shù)字
  5.         unsigned char i,j;
  6.         LCD_SetArea(rect);
  7.         LCD_WR_REG(0x2C);//寫儲(chǔ)存器命令
  8.         for(i=0;i<font_num;i++)
  9.         {
  10.                  for(j=8;j>0;j--)
  11.                 {
  12.                                 if(1==(GB_font[i]>>j-1&0x01))//判斷字符位置是否有像素//--有
  13.                                 {
  14.                                         LcdWirteColorData(color);//寫入字體顏色
  15.                                 }
  16.                                 else //沒(méi)有
  17.                                 {
  18.                                                 LcdWirteColorData(bkcolor);//沒(méi)有則寫入背景色

  19.                     }
  20.                 }
  21.                
  22.         }
  23. }
  24. void show816(unsigned int num_X, unsigned int num_Y,unsigned char* GB_font)
  25. {
  26.                 RECT rect;//屏顯示范圍
  27.                 num_Y=239-num_Y-15;//屏坐標(biāo)轉(zhuǎn)換
  28.                 rect.top=num_X;
  29.                 rect.left=num_Y;
  30.                 rect.right=num_Y+15;
  31.                 rect.bottom=num_X+15;
  32.                 LcdPutStr(rect,0XF800,0XFfff,GB_font,16);
  33. }
  34. void show3216(unsigned int num_X, unsigned int num_Y,unsigned char* GB_font)
  35. {//調(diào)用該涵數(shù),num_X最大不要超過(guò)224,num_Y不超304
  36.                 RECT rect;//屏顯示范圍
  37.                 num_Y=239-num_Y-15;//屏坐標(biāo)轉(zhuǎn)換
  38.                 rect.top=num_X;
  39.                 rect.left=num_Y;
  40.                 rect.right=num_Y+15;
  41.                 rect.bottom=num_X+31;
  42.                 LcdPutStr(rect,0XF800,0XFfff,GB_font,32);
  43. }
  44. void show3264(unsigned int num_X, unsigned int num_Y,unsigned char* GB_font)
  45. {
  46.                 RECT rect;//屏顯示范圍
  47.                 num_Y=239-num_Y-63;//屏坐標(biāo)轉(zhuǎn)換
  48.                 rect.top=num_X;
  49.                 rect.left=num_Y;
  50.                 rect.right=num_Y+63;
  51.                 rect.bottom=num_X+31;        
  52.                 LcdPutStr(rect,0XF800,0XFfff,GB_font,255);
  53. }
復(fù)制代碼

DS3231.c單片機(jī)源程序如下:
  1. #include <REGX55.H>
  2. #include "DS3231.h"
  3. #include <intrins.h>
  4. sbit SCL        =        P3^0;  //時(shí)鐘
  5. sbit SDA        =        P3^1;  //數(shù)據(jù)
  6. void delay_IIC(void)   
  7. {//IIC總線限速延時(shí)函數(shù)。
  8. //該函數(shù)是空函數(shù),延時(shí)4個(gè)機(jī)器周期。
  9. _nop_();_nop_();_nop_();_nop_();
  10. }
  11. //void IIC_Init(void)
  12. //{//IIC總線初始化函數(shù)

  13. //   SDA=1;//釋放IIC總線的數(shù)據(jù)線。
  14. //   SCL=1;//釋放IIC總線的時(shí)鐘線。
  15. //}
  16. void IIC_start(void)
  17. {//IIC總線產(chǎn)生起始信號(hào)函數(shù)
  18.      
  19.      SDA=1;//拉高數(shù)據(jù)線
  20.      SCL=1;//拉高時(shí)鐘線
  21.      delay_IIC();
  22.      SDA=0;//在時(shí)鐘線為高電平時(shí),拉低數(shù)據(jù)線,產(chǎn)生起始信號(hào)。
  23.      delay_IIC();
  24.      SCL=0;//拉低時(shí)鐘線
  25. }
  26. void IIC_stop(void)
  27. {//IIC總線產(chǎn)生停止信號(hào)函數(shù)
  28.     SDA=0;//拉低數(shù)據(jù)線
  29.     delay_IIC();
  30.     SCL=1;//拉高時(shí)鐘線。
  31.     delay_IIC();
  32.     SDA=1;//時(shí)鐘時(shí)線為高電平時(shí),拉高數(shù)據(jù)線,產(chǎn)生停止信號(hào)。
  33.     delay_IIC();
  34. }
  35. bit IIC_Tack(void)
  36. {//接收應(yīng)答信號(hào)函數(shù)
  37.     bit ack;//定義一個(gè)位變量,來(lái)暫存應(yīng)答狀態(tài)。
  38.     SDA=1;//釋放數(shù)據(jù)總線,準(zhǔn)備接收應(yīng)答信號(hào)。
  39.     delay_IIC();
  40.     SCL=1;//拉高時(shí)鐘線。
  41.     delay_IIC();
  42.     ack=SDA;//讀取應(yīng)答信號(hào)的狀態(tài)。
  43.     delay_IIC();
  44.     SCL=0;//拉低時(shí)鐘線。
  45.     delay_IIC();
  46.     return ack;//返回應(yīng)答信號(hào)的狀態(tài),0表示應(yīng)答,1表示非應(yīng)答。
  47. }
  48. void IIC_write_byte(unsigned char Data)
  49. {//向IIC總線寫入一個(gè)字節(jié)的數(shù)據(jù)函數(shù)
  50.     unsigned char i;
  51.      for(i=0;i<8;i++)//有8位數(shù)據(jù)
  52.     {
  53.         SDA=Data&0x80;//寫最高位的數(shù)據(jù)
  54.           delay_IIC();
  55.           SCL=1; //拉高時(shí)鐘線,將數(shù)寫入到設(shè)備中。
  56.         delay_IIC();
  57.         SCL=0;//拉低時(shí)鐘線,允許改變數(shù)據(jù)線的狀態(tài)
  58.         delay_IIC();
  59.         Data=Data<<1;//數(shù)據(jù)左移一位,把次高位放在最高位,為寫入次高位做準(zhǔn)備
  60.     }
  61. }
  62. unsigned char IIC_read_byte()
  63. {//從IIC總線讀取一個(gè)字節(jié)的數(shù)據(jù)函數(shù)
  64.     unsigned char i;
  65.     unsigned char Data;       //定義一個(gè)緩沖寄存器。
  66.     for(i=0;i<8;i++)//有8位數(shù)據(jù)
  67.     {
  68.         SCL=1;//拉高時(shí)鐘線,為讀取下一位數(shù)據(jù)做準(zhǔn)備。
  69.         delay_IIC();
  70.         Data=Data<<1;//將緩沖字節(jié)的數(shù)據(jù)左移一位,準(zhǔn)備讀取數(shù)據(jù)。
  71.         delay_IIC();
  72.       
  73.         if(SDA)//如果數(shù)據(jù)線為高平電平。
  74.             Data=Data|0x01;//則給緩沖字節(jié)的最低位寫1。
  75.         SCL=0;//拉低時(shí)鐘線,為讀取下一位數(shù)據(jù)做準(zhǔn)備。
  76.         delay_IIC();
  77.     }
  78.     return Data;//返回讀取的一個(gè)字節(jié)數(shù)據(jù)。
  79. }

  80. void IIC_single_byte_write(unsigned char Waddr,unsigned char Data)
  81. {//向任意地址寫入一個(gè)字節(jié)數(shù)據(jù)函數(shù)
  82.     IIC_start();//產(chǎn)生起始信號(hào)
  83.     IIC_write_byte(0xd0);//寫入設(shè)備地址(寫)
  84.     IIC_Tack();//等待設(shè)備的應(yīng)答
  85.     IIC_write_byte(Waddr);//寫入要操作的單元地址。
  86.     IIC_Tack();//等待設(shè)備的應(yīng)答。
  87.     IIC_write_byte(Data);//寫入數(shù)據(jù)。
  88.     IIC_Tack();//等待設(shè)備的應(yīng)答。
  89.     IIC_stop();//產(chǎn)生停止符號(hào)。
  90. }
  91. unsigned char IIC_single_byte_read(unsigned char Waddr)
  92. {//從任意地址讀取一個(gè)字節(jié)數(shù)據(jù)函數(shù)
  93.     unsigned char Data;//定義一個(gè)緩沖寄存器。
  94.         
  95.     IIC_start();//產(chǎn)生起始信號(hào)
  96.     IIC_write_byte(0xd0);//寫入設(shè)備地址(寫)
  97.     IIC_Tack();//等待設(shè)備的應(yīng)答
  98.     IIC_write_byte(Waddr);//寫入要操作的單元地址。
  99.     IIC_Tack();//等待設(shè)備的應(yīng)答。
  100.     IIC_stop();//產(chǎn)生停止符號(hào)。

  101.     IIC_start();//產(chǎn)生起始信號(hào)

  102.         
  103.     IIC_write_byte(0xd1);//寫入設(shè)備地址(寫)
  104.     IIC_Tack();//等待設(shè)備的應(yīng)答
  105. ……………………

  106. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
51萬(wàn)年歷彩屏版.7z (109.57 KB, 下載次數(shù): 456)



作者: 937166474    時(shí)間: 2018-5-13 17:31
剛好需要,找了一波,可以的,感謝
作者: mikezhao0769    時(shí)間: 2018-7-14 19:54
下載后需要用winrar才能解壓
作者: jy981    時(shí)間: 2018-7-15 10:18
能不能發(fā)個(gè)完整版的。
作者: touya    時(shí)間: 2018-7-23 22:23
我也要下載,謝謝樓主
作者: yongjun    時(shí)間: 2018-12-3 10:08
剛好需要
作者: zhaofangfang    時(shí)間: 2018-12-8 21:45
可以用

作者: ch5320    時(shí)間: 2019-7-25 11:51
下載了打不開(kāi)
作者: 別愛(ài)我    時(shí)間: 2019-11-23 14:09
謝謝大佬,太牛逼了
作者: jemery1030    時(shí)間: 2020-10-1 16:05
正常玩TFT,剛好可以測(cè)試,測(cè)試完再報(bào)告結(jié)果。
作者: jemery1030    時(shí)間: 2020-10-1 16:14
板子不一樣,沒(méi)辦法正確驅(qū)動(dòng),不過(guò)依然感謝你。
作者: hnqylgq    時(shí)間: 2021-2-20 10:23
看著很好,點(diǎn)贊支持,謝謝分享,學(xué)習(xí)了
作者: sy_lm    時(shí)間: 2021-3-2 21:00
真是學(xué)習(xí)好去處
作者: tt98    時(shí)間: 2021-7-11 17:40
這個(gè)屏哪有?
作者: gemxie    時(shí)間: 2024-12-24 22:12

我也要下載,謝謝樓主




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