久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3771|回復: 3
打印 上一主題 下一主題
收起左側

LCD240128(UC1698芯片)驅動程序 C語言 STM32的FSMC

[復制鏈接]
跳轉到指定樓層
樓主
LCD240128(UC1698芯片)驅動采用STM32的FSMC

單片機源程序如下:

  1. /*
  2.           (芯片:UC1698 芯片驅動,參考LCD_240128CFW顯示屏)

  3. */


  4. #include "UC1698.h"
  5. #include "FONT.H"

  6. //LCD重要參數集
  7. typedef struct  
  8. {                                                                                    
  9.         u16 width;                        //LCD 寬度
  10.         u16 height;                        //LCD 高度
  11.         u16 id;                                //LCD ID
  12.         u8  dir;                        //橫屏還是豎屏控制:0,豎屏;1,橫屏。        
  13.         u16        wramcmd;                //開始寫gram指令
  14.         u16  setxcmd;                //設置x坐標指令
  15.         u16  setycmd;                //設置y坐標指令
  16. }lcd_dev;         

  17. /*************LCD 屏的像素LCD_MAX_width * LCD_MAX_height *********************************/
  18. #define LCD_MAX_width        240
  19. #define LCD_MAX_height       128

  20. /*************UC1698寄存器控制命令*********************************/
  21. #define UC1698_CA_LSB(x)    (0x00|(0x0f&x))    //Set Column Address LSB  列地址
  22. #define UC1698_CA_MSB(x)    (0x10|0x0f&(x>>4)) //Set Column Address MSB   列地址
  23. #define UC1698_TC(x)        (0x24|(0x03&x))    //Set Temp. Compensation  溫度補償LSB
  24. #define UC1698_PC(x)        (0x28|(0x03&x))    //Set Power control 功率控制
  25. #define UC1698_RA_LSB(y)    (0x60|(0x0f&y))    //Set row Address LSB      行地址
  26. #define UC1698_RA_MSB(y)    (0x70|0x0f&(y>>4)) //Set Row Address MSB      行地址
  27. #define UC1698_PDC_LC(x)    (0x84|x)           //Set Partial Display Control  
  28. #define UC1698_PM            0x81              //Set VBIAS Potentiometer  設置對比度bf(ContrastLevel)
  29. #define UC1698_RAC_AC(x)    (0x88|(0x07&x))    //Set RAM Address Control  RAM地址控制
  30. #define UC1698_LR_LC(x)     (0xa0|(0x03&x))    //Set Line rate  設置行掃描頻率
  31. #define UC1698_AP_DC(x)     (0xa4|x)           //Set All-Pixel-ON    顯示特性性
  32. #define UC1698_ID_DC(x)     (0xa6|x)           //Set Inverse display  設置方向顯示(0--正、1--反向);
  33. #define UC1698_DE_DC         0xad             //Set Display enable  開顯示
  34. #define UC1698_MC_DC(x)     (0xC0|(0x07&x))    //Set LCD Mapping contro  設置lcd映射控制:LCD映像MY=1,MX=0,LC0=0
  35. #define UC1698_NIV           0xC8             //Set N-Line Inversion  設置M信號為0行翻磚(LCD_WR_REG(0x10); )
  36. #define UC1698_CP_LC(x)     (0xD0|x)           //Set Color pattern彩色數據格式   0/1
  37. #define UC1698_CM_LC(x)     (0xD4|(0X03&x))     //Set Color Mode  彩色數據模式  0x01:12位 0x02:16位
  38. #define UC1698_CSF(x)       (0xd8|(x&0X07))    //Set COM Scan Function  掃描模式
  39. #define UC1698_BR(x)        (0xE8|(x&0X03))    //Set LCD Bias Ratio  設置偏壓比1/10          LCD_WR_REG(0xe9);
  40. #define UC1698_CEN           0xf1             //Set COM End
  41. #define UC1698_DST           0xf2             //Set Partial Display Start
  42. #define UC1698_CDEN          0xf3             //Set  Set Partial Display End
  43. #define UC1698_WPC0          0xf4                                            // Set Window Program Starting Columm Address  窗口左邊界
  44. #define UC1698_WPP0          0xf5                                // Set Window Program Starting Row Address     窗口上邊界
  45. #define UC1698_WPC1          0xf6                                       // Set Window Program Ending Columm Address    窗口右邊界
  46. #define UC1698_WPP1          0xf7                                // Set Window Program Starting Row Address     窗口下邊界
  47. #define UC1698_WPM_AC(x)    (0xf8|x)                                   // Window Program Mode: 0 ->Inside;1-> All area
  48. static vu8 ContrastLevel = 0x2D;  //對比度bf

  49. #if Address_struct==1
  50.         //寫寄存器函數  指令寫入子程序-
  51.         //regval:寄存器值
  52.         void LCD_WR_REG(vu16 regval)
  53.         {   
  54.                 regval=regval;                //使用-O2優化的時候,必須插入的延時
  55.                 LCD->LCD_REG=regval;//寫入要寫的寄存器序號         
  56.         }
  57.         //寫LCD數據    數據寫入子程序
  58.         //data:要寫入的值
  59.         void LCD_WR_DATA(vu16 data)
  60.         {         
  61.                 data=data;                        //使用-O2優化的時候,必須插入的延時
  62.                 LCD->LCD_RAM=data;        
  63.         }

  64.         //讀LCD數據
  65.         //返回值:讀到的值
  66.         u16 LCD_RD_DATA(void)
  67.         {
  68.                 vu16 ram;                        //防止被優化
  69.                 ram=LCD->LCD_RAM;        
  70.                 return ram;         
  71.         }        
  72. #endif

  73. /*************FSMC********************************
  74.         
  75.         
  76.         
  77. *************        *********************************/        
  78.         
  79. void FSMC_Init(void){
  80.         FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  81.   FSMC_NORSRAMTimingInitTypeDef  readWriteTiming;
  82.         FSMC_NORSRAMTimingInitTypeDef  writeTiming;

  83.   readWriteTiming.FSMC_AddressSetupTime = 0XF;         //地址建立時間(ADDSET)為16個HCLK 1/168M=6ns*16=96ns        
  84.   readWriteTiming.FSMC_AddressHoldTime = 0x00;         //地址保持時間(ADDHLD)模式A未用到        
  85.   readWriteTiming.FSMC_DataSetupTime = 60;                        //數據保存時間為60個HCLK        =6*60=360ns
  86.   readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;  //總線恢復時間
  87.   readWriteTiming.FSMC_CLKDivision = 0x00;         // 時鐘分頻因子
  88.   readWriteTiming.FSMC_DataLatency = 0x00;             //數據產生時間
  89.   readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A;         // //FSMC NOR控制器時序:模式A
  90.    
  91.         writeTiming.FSMC_AddressSetupTime =10;              //地址建立時間(ADDSET)為9個HCLK =54ns
  92.   writeTiming.FSMC_AddressHoldTime = 10;         //地址保持時間(A               
  93.   writeTiming.FSMC_DataSetupTime = 10;                 //數據保存時間為6ns*9個HCLK=54ns
  94.   writeTiming.FSMC_BusTurnAroundDuration = 0x00;
  95.   writeTiming.FSMC_CLKDivision = 0x00;
  96.   writeTiming.FSMC_DataLatency = 0x00;
  97.   writeTiming.FSMC_AccessMode = FSMC_AccessMode_A;         //模式A

  98.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;//  這里我們使用NE4 ,也就對應BTCR[6],[7]。--》 nor被分為四塊,其中這個參數是說明對那個塊編程
  99.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // 不復用數據地址--》   地址\數據是否復用
  100.   FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM;  //SRAM   --》   存儲器類型
  101.   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;//存儲器數據寬度為16bit   --》數據總線寬度  8位/16位
  102.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable; --》是否進行成組模式訪問
  103.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;//等待信號有效級性
  104.         
  105.         FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;   //該位決定控制器是否支持把非對齊的AHB成組操作分割成2次線性操作;該位僅在存儲器的成組模式下有效。
  106.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;  //當閃存存儲器處于成組傳輸模式時,NWAIT信號指示從閃存存儲器出來的數據是否有效或是否需要插入等待周期。該位決定存儲器是在等待狀態之前的一個時鐘周期產生NWAIT信號,還是在等待狀態期間產生NWAIT信號。
  107.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;        //  存儲器寫使能----》該位指示FSMC是否允許/禁止對存儲器的寫操作。
  108.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;        //當閃存存儲器處于成組傳輸模式時,這一位允許/禁止通過NWAIT信號插入等待狀態。
  109.   FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;  //設置是否使能在同步傳輸時使用的等待信號,在控制同步類型的NOR或PSRAM時,存儲器可以使用FSMC_NWAIT引腳通知STM32需要等待。
  110.         
  111.         FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  112.         //FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; // 讀寫使用不同的時序 --》該位允許FSMC使用FSMC_BWTR寄存器,即允許讀和寫使用不同的時序。
  113.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //對于處于成組傳輸模式的閃存存儲器,這一位允許/禁止通過NWAIT信號插入等待狀態。讀操作的同步成組傳輸協議使能位是FSMC_BCRx寄存器的BURSTEN位。
  114.         FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming;  //寫時序--->//寫時序配置指針

  115.         FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //讀寫時序--->//讀時序配置指針

  116.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);  //初始化FSMC配置
  117.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);  // 使能BANK1
  118.                
  119. }



  120. //初始化lcd
  121. //該初始化函數可以初始化各種ILI93XX液晶,但是其他函數是基于ILI9320的!!!
  122. //在其他型號的驅動芯片上沒有測試!
  123. void LCD_Init(void)
  124. {         

  125.   GPIO_InitTypeDef  GPIO_InitStructure;

  126.         //************************打開相應的時鐘使能***********************************/
  127.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG, ENABLE);//使能PD,PE,PF,PG時鐘  
  128.   RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);//使能FSMC時鐘  
  129.         
  130.         //************************背光燈的設置***********************************/
  131.   
  132.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通輸出模式
  133.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽輸出
  134.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
  135.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
  136.         
  137.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//GPIOE  PE對應IO口(背光燈)
  138.   GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化GPIO
  139.         GPIO_SetBits(GPIOE,GPIO_Pin_5);//PE5   設置為高,
  140.         //BLK_OFF;
  141.         
  142.                 //************************LCD復位***********************************/
  143.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//GPIOG  PG對應IO口(LCD復位)
  144.   GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化GPIO
  145.         GPIO_SetBits(GPIOG,GPIO_Pin_3);      //  設置為高,

  146.         
  147.         //************************數據總線與使能線的IO配置***********************************/

  148.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//復用輸出
  149.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽輸出
  150.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
  151.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
  152.         
  153.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_14|GPIO_Pin_15;
  154.   GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化  
  155.         
  156.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
  157.   GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化  

  158.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_12;//PF12,FSMC_A6
  159.   GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化

  160. //************************相應管腳映射到FSMC接口 數據總線+使能控制線***********************************/
  161.   GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);    //-->D0
  162.   GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);     //-->D1
  163.         GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);      //-->D2
  164.   GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);      //-->D3
  165.         
  166.   GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);      //-->D4
  167.   GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);      //-->D5
  168.   GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);      //-->D6
  169.   GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);     //-->D7
  170.         
  171.   GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);      //-->RD
  172.   GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);      //-->WR
  173.         
  174.   GPIO_PinAFConfig(GPIOG,GPIO_PinSource12,GPIO_AF_FSMC);     //   -->CS
  175.         GPIO_PinAFConfig(GPIOG,GPIO_PinSource2,GPIO_AF_FSMC);      //->CD(A12)

  176.              FSMC_Init();//FSMC_初始化
  177.         
  178.                                 LCD_RESET_L;
  179.                                 delay_ms(6);
  180.                                 LCD_RESET_H;
  181.                                 delay_ms(80);
  182. ……………………

  183. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

以上3個文件51hei下載,不含工程文件,請自行移植:
LCD_240128CFW顯示屏(FSMC).rar (19.85 KB, 下載次數: 63)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:336670 發表于 2025-4-3 11:26 | 只看該作者
值得借鑒,謝謝
回復

使用道具 舉報

板凳
ID:146324 發表于 2025-6-4 16:49 | 只看該作者
學習一下。謝謝
回復

使用道具 舉報

地板
ID:1064915 發表于 2025-6-5 08:48 | 只看該作者
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#define uchar unsigned char
#define uint unsigned int

#include <SimpleDHT.h>
int pinDHT11 = D5;
SimpleDHT11 dht11(pinDHT11);

int i=0;

int RST =D2;
int sck = D1;
int sda = D0;
int CS = D4;
int CD = D3;

// width: 144, height: 142

unsigned char col[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xf0,0x00,0x00,0x3f,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xf8,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xfc,0x00,0x1f,0xf0,0x00,0x07,0xfc,0x00,0x00,0x1e,0x00,0x00,0x01,0xff,0xff,0xfe,0x07,0xff,0x00,0x00,0x00,0x1f,0x80,0x01,0xff,0xc0,0x00,0x01,0xff,0xff,0xff,0x1f,0xf8,0x00,0x00,0x00,0x07,0xc0,0x07,0xff,0xf0,0x00,0x03,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x78,0x1f,0xff,0xfe,0x00,0x03,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x3e,0x3f,0xff,0xff,0x00,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x0f,0x3f,0xff,0xff,0x80,0x0f,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xc0,0x0f,0xff,0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xc0,0x0f,0xff,0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xc0,0x0f,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xff,0xe0,0x0f,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xf0,0x0f,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xf0,0x0f,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xf8,0x0f,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xf8,0x0f,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xf8,0x0f,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xf8,0x0f,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xf8,0x0f,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xf8,0x0f,0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xf8,0x0f,0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xf8,0x0f,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xf8,0x07,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xf8,0x03,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xf8,0x03,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xf8,0x01,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xf0,0x01,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xf0,0x01,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xf0,0x00,0x7f,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xf0,0x07,0xff,0xe0,0x00,0x3f,0xc0,0x00,0x00,0x00,0x1f,0xe0,0x00,0x00,0x7b,0xf0,0x07,0xff,0xc0,0x00,0x1f,0xc0,0x00,0x00,0x00,0x3f,0xfe,0x00,0x00,0x7f,0xf0,0x03,0xff,0x80,0x00,0x07,0x80,0x00,0x00,0x00,0xdf,0xff,0x86,0x01,0xff,0xe0,0x03,0xff,0x00,0x00,0x01,0x80,0x00,0x00,0x07,0xc0,0xff,0xc7,0x13,0xff,0x80,0x01,0xfe,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x01,0xff,0xff,0x1f,0xff,0xe0,0x01,0xfc,0x00,0x00,0x01,0x00,0x00,0x00,0x38,0x0f,0xff,0xff,0x1f,0xff,0xe0,0x00,0xc0,0x00,0x00,0x03,0x00,0x00,0x00,0x30,0xff,0xff,0xff,0x9f,0xfb,0xf0,0x00,0xc0,0x00,0x00,0x03,0x00,0x00,0x00,0x0f,0xff,0x9f,0xfc,0x3f,0xf1,0xf0,0x00,0xc0,0x00,0x00,0x06,0x00,0x00,0x00,0x0f,0xfe,0x0f,0xf8,0x3f,0xe0,0xe0,0x00,0xc0,0x00,0x00,0x06,0x00,0x00,0x00,0x0f,0xfe,0x07,0xc0,0x1f,0xc0,0xc0,0x00,0xc0,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x7c,0x0f,0x80,0x0f,0xe6,0x00,0x00,0x60,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x01,0xff,0x80,0x0f,0xfe,0x00,0x00,0x60,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x03,0xff,0x00,0x07,0xfe,0x00,0x00,0x60,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x03,0xf8,0x00,0x02,0x3e,0x00,0x00,0x60,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x30,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x30,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x07,0xc0,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x0f,0xc0,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x1f,0xc0,0x00,0x00,0x00,0x00,0xfe,0x01,0xfc,0x1f,0xfc,0x00,0x00,0x1e,0x00,0x3f,0xc0,0x00,0x00,0x00,0x00,0xfe,0x01,0xff,0xff,0x9f,0x00,0x00,0x1f,0x80,0x7f,0xc0,0x00,0x00,0x00,0x03,0xfc,0x00,0xff,0xff,0x1f,0x00,0x00,0x1f,0x80,0x7f,0xc0,0x00,0x00,0x00,0x00,0xf0,0x00,0x3f,0xfe,0x06,0x00,0x00,0x1f,0x80,0xff,0xc0,0x00,0x00,0x00,0x00,0xe0,0x00,0x07,0xf8,0x02,0x00,0x00,0x1f,0xc0,0xff,0xc0,0x00,0x00,0x00,0x00,0xc0,0x00,0x03,0xf0,0x00,0x00,0x00,0x1f,0xc0,0xff,0xe0,0x00,0x00,0x00,0x00,0x40,0x00,0x06,0x00,0x00,0x00,0x00,0x1f,0xe0,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x1f,0xf0,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xf0,0xff,0xf0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xf8,0xff,0xf8,0x00,0x00,0x00,0x00,0x0f,0xf1,0x60,0x00,0x00,0x00,0x00,0x3f,0xf8,0xff,0xf8,0x00,0x00,0x00,0x00,0x07,0xff,0xfc,0x7f,0x80,0x00,0x00,0x3f,0xfc,0xff,0xf8,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xe0,0x00,0x00,0x7f,0xfe,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0x00,0x00,0x7f,0xfe,0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x7f,0xfe,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x0e,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x01,0xd0,0x03,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0x00,0x00,0x3f,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x1f,0xff,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x0f,0xfc,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x07,0xf8,0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x03,0xf0,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };


char shi1[] = {
0x00,0x00,0x00,0x00,0x7F,
      0x49,0x49,0x49,0x49,0x49,
      0x7F,0x00,0x00,0x80,0x00,
      0x00,0x01,0x81,0x41,0x21,
      0x1D,0x21,0x41,0x7F,0x89,
      0x89,0x8D,0x89,0x81,0xC1,
      0x41,0x00
};

char qiu[] = {
/*--  文字:  秋  --*/
/*--  宋體18;  此字體下對應的點陣為:寬x高=24x24   --*/
0x00,0x00,0x00,0x20,0x10,0x10,0x18,0xFC,
      0x06,0x86,0x00,0x80,0x00,0x00,0xD3,0xFF,
      0x02,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x02,0x82,0x63,0x31,0x1F,0xFF,
      0x0D,0x39,0x31,0x03,0x1E,0x80,0xFF,0x3F,
      0xC8,0x06,0x03,0x00,0x00,0x00,0x00,0x00,
      0x00,0x06,0x03,0x00,0x00,0x00,0xF7,0xFF,
      0x00,0xC0,0x60,0x30,0x0C,0x07,0x00,0x00,
      0x01,0x0E,0x38,0x70,0x60,0x40,0x40,0x00};
char one[] =
{
    0x00,0x10,0x10,0x18,0x18,  // -1-
  0xFC,0xFC,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0xFF,0xFF,0x00,
  0x00,0x00,0x00,0x00,0x00,
  0x00,0x20,0x20,0x20,0x3F,
  0x3F,0x20,0x20,0x20,0x00,
  0x00 };
char wen[]={      0x00,0x00,0x00,0xC0,0x80,0x82,0x06,0x1C,      0x80,0x00,0x00,0xFF,0x26,0x26,0x22,0x32,      0x32,0xC2,0xFF,0x03,0x00,0x00,0x00,0x00,      0x00,0x00,0x00,0x00,0x01,0x03,0xE0,0x3E,      0x01,0x70,0xE0,0x27,0x66,0xF2,0x33,0x13,      0xF1,0x11,0x11,0xF8,0x18,0x00,0x00,0x00,      0x00,0x00,0x00,0x0C,0x18,0x1F,0x03,0x00,      0x00,0x00,0x1F,0x10,0x10,0x1F,0x10,0x1C,      0x1F,0x10,0x1E,0x1F,0x10,0x18,0x10,0x00};
char du[]={0x00,0x00,0x00,0x00,0x00,0xF8,0x60,0x20,      0x20,0x60,0xF0,0x33,0x16,0x16,0x10,0xF0,      0x10,0x18,0x98,0x98,0x00,0x00,0x00,0x00,     0x00,0x00,0x00,0x00,0x80,0xFF,0x02,0x02,      0x82,0x82,0xBF,0x93,0xD3,0xD1,0x5D,0xDF,      0xE1,0x41,0x01,0x01,0x01,0x00,0x00,0x00,      0x00,0x80,0x60,0x38,0x0F,0x01,0x00,0x80,     0xC0,0x42,0x22,0x34,0x1C,0x1C,0x33,0x61,      0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x00};
char shi[]={0x00,0x00,0x00,0x00,0x02,0x04,0x1C,0x08,      0x80,0x00,0xFE,0x44,0x44,0x44,0x64,0x64,      0x24,0xE6,0x7E,0x06,0x00,0x00,0x00,0x00,      0x00,0x00,0x01,0x03,0x06,0x06,0xF0,0x1F,      0x00,0xC0,0x87,0x06,0xF6,0x22,0x02,0xFA,      0x12,0x03,0xC2,0x60,0x00,0x00,0x00,0x00,      0x00,0x00,0x08,0x18,0x38,0x3F,0x01,0x20,      0x20,0x20,0x23,0x20,0x3F,0x20,0x20,0x3F,      0x36,0x33,0x30,0x30,0x30,0x20,0x00,0x00};
char abc[]={  0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  0x81,0xC3,0xC3,0x81,0x00,0x00,0x00,0x00,  0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x01,  0x00,0x00,0x00,0x00};
char C[]={ 0xC0,0xF0,0x38,0x0C,0x04,0x04,0x04,0x0C,  0x18,0x38,0x7C,0x00,0xFF,0xFF,0x00,0x00,  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  0x03,0x0F,0x1C,0x30,0x20,0x20,0x20,0x30,  0x18,0x0E,0x06,0x00};

   char H[]={0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x04,  0xFC,0xFC,0x04,0x00,0x00,0xFF,0xFF,0x08,  0x08,0x08,0x08,0x08,0xFF,0xFF,0x00,0x00,  0x20,0x3F,0x3F,0x20,0x00,0x00,0x00,0x20,  0x3F,0x3F,0x20,0x00};

char O[]={0xC0,0xE0,0x20,0x20,0x20,  0xE0,0xC0,0x00,0x07,0x0F,  0x08,0x08,0x08,0x0F,0x07,  0x00};

char num_24_12[][36]=
  {
     // -0-
    {0x00,0xC0,0xF0,0x38,0x0C,    0x04,0x0C,0x38,0xF0,0xC0,    0x00,0x00,0xFF,0xFF,0x00,    0x00,0x00,0x00,0x00,0x00,    0x00,0xFF,0xFF,0x00,0x00,    0x03,0x0F,0x1C,0x30,0x20, 0x30,0x1C,0x0F,0x03,0x00,0x00},
   // -1-
    {0x00,0x10,0x10,0x18,0x18,    0xFC,0xFC,0x00,0x00,0x00,    0x00,0x00,0x00,0x00,0x00,    0x00,0x00,0xFF,0xFF,0x00,    0x00,0x00,0x00,0x00,0x00,    0x00,0x20,0x20,0x20,0x3F,    0x3F,0x20,0x20,0x20,0x00,    0x00},
   // -2-
    {0x60,0xF0,0xF8,0x0C,0x04,    0x04,0x04,0x0C,0x18,0xF0,    0xE0,0x00,0x00,0x00,0x00,    0x80,0xC0,0x60,0x30,0x18,    0x0E,0x07,0x01,0x00,0x38,    0x3E,0x3F,0x33,0x30,0x30,    0x30,0x30,0x30,0x30,0x3C,    0x00},
    // -3-
    {0x00,0x30,0x78,0x78,0x0C,    0x04,0x04,0x0C,0x18,0xF8,    0xF0,0x00,0x00,0x00,0x00,    0x00,0x08,0x08,0x1C,0x16,    0x33,0xE1,0xC0,0x00,0x0C,    0x1E,0x3E,0x30,0x20,0x20,    0x20,0x30,0x18,0x1F,0x0F,    0x00},
   // -4-
    {0x00,0x00,0x00,0x00,0x80,    0xE0,0x38,0xFC,0xFC,0x00,    0x00,0x00,0x80,0xE0,0x38,    0x0E,0x03,0x00,0x00,0xFF,    0xFF,0x00,0x00,0x00,0x01,    0x01,0x01,0x01,0x01,0x21,    0x21,0x3F,0x3F,0x21,0x21,    0x01},
   // -5-
    {0x00,0xFC,0xFC,0x0C,0x0C,    0x0C,0x0C,0x0C,0x0C,0x0C,   0x00,0x00,0x00,0x1F,0x0F,    0x08,0x04,0x02,0x02,0x06,    0x1C,0xF8,0xE0,0x00,0x0C,    0x1E,0x3E,0x30,0x20,0x20,    0x20,0x30,0x1C,0x0F,0x03,    0x00},
  // -6-
    {0xC0,0xF0,0x38,0x0C,0x04,    0x04,0x0C,0x7C,0x78,0x30,    0x00,0x00,0xFF,0xFF,0x08,    0x04,0x02,0x02,0x02,0x06,    0x1C,0xF8,0xE0,0x00,0x03,    0x0F,0x1C,0x30,0x20,0x20,    0x20,0x30,0x1C,0x0F,0x03,    0x00},
   // -7-
    {0x78,0x1C,0x0C,0x0C,0x0C,    0x0C,0x0C,0x0C,0xCC,0x7C,   0x1C,0x00,0x00,0x00,0x00,   0x00,0x80,0xF0,0x7C,0x0F,    0x01,0x00,0x00,0x00,0x00,    0x00,0x00,0x00,0x3F,0x3F,    0x00,0x00,0x00,0x00,0x00,    0x00},
   // -8-
    {0x00,0xF0,0xF8,0x0C,0x04,    0x04,0x04,0x0C,0xF8,0xF0,    0x00,0x00,0xC0,0xE0,0x31,    0x1B,0x0E,0x0C,0x0E,0x1B,    0x31,0xE0,0xC0,0x00,0x07,  0x0F,0x18,0x30,0x20,0x20,    0x20,0x30,0x18,0x0F,0x07,    0x00},
   // -9-
    {0xC0,0xF0,0x38,0x0C,0x04,    0x04,0x04,0x0C,0x38,0xF0,    0xC0,0x00,0x07,0x1F,0x38,    0x60,0x40,0x40,0x40,0x20,    0x10,0xFF,0xFF,0x00,0x00,    0x0C,0x1E,0x3E,0x30,0x20,    0x20,0x30,0x1C,0x0F,0x03,    0x00},
};


char num_16_8[][16]=
{
   // -0-
  {0xF8,0xFC,0x04,0xC4,0x24,  0xFC,0xF8,0x00,0x07,0x0F,  0x09,0x08,0x08,0x0F,0x07,  0x00},
    // -1-
  {0x00,0x10,0x18,0xFC,0xFC,  0x00,0x00,0x00,0x00,0x08,  0x08,0x0F,0x0F,0x08,0x08,  0x00},
    // -2-
  {0x08,0x0C,0x84,0xC4,0x64,  0x3C,0x18,0x00,0x0E,0x0F,  0x09,0x08,0x08,0x0C,0x0C,  0x00},
  // -3-
  {0x08,0x0C,0x44,0x44,0x44,  0xFC,0xB8,0x00,0x04,0x0C,  0x08,0x08,0x08,0x0F,0x07,  0x00},
// -4-
  {0xC0,0xE0,0xB0,0x98,0xFC,  0xFC,0x80,0x00,0x00,0x00,  0x00,0x08,0x0F,0x0F,0x08,  0x00},
  // -5-
  {0x7C,0x7C,0x44,0x44,0xC4,  0xC4,0x84,0x00,0x04,0x0C,  0x08,0x08,0x08,0x0F,0x07,  0x00},
  // -6-
  {0xF0,0xF8,0x4C,0x44,0x44,  0xC0,0x80,0x00,0x07,0x0F,  0x08,0x08,0x08,0x0F,0x07,  0x00},
// -7-
  {0x0C,0x0C,0x04,0x84,0xC4,  0x7C,0x3C,0x00,0x00,0x00,  0x0F,0x0F,0x00,0x00,0x00,  0x00},
// -8-
  {0xB8,0xFC,0x44,0x44,0x44,  0xFC,0xB8,0x00,0x07,0x0F,  0x08,0x08,0x08,0x0F,0x07,  0x00},
  // -9-
  {0x38,0x7C,0x44,0x44,0x44,  0xFC,0xF8,0x00,0x00,0x08,  0x08,0x08,0x0C,0x07,0x03,  0x00},
  };

void num_str_2412(char x,char y,int data)
{
  int ge=data%10;
  int shi=data/10;
  words_2424(x, y, 1, num_24_12[shi]);
  words_2424(x+4, y, 1, num_24_12[ge]);

  }

void write_160160(bool flag, uchar dat)
{
  uchar i;
  digitalWrite(CD, flag);//flag=0,write command;flag=1,write data
  digitalWrite(CS, 0);
  for(i = 0; i < 8; i++)
  {  
    if(dat&0x80)
    {
      digitalWrite(sda, 1);
    }
    else
    {
      digitalWrite(sda, 0);
    }
    dat<<=1;     
    digitalWrite(sck, 1);   
    digitalWrite(sck, 0);
  }
  digitalWrite(CS,1);
}

void LCD_SetAddress(int x, int y)
{
  x = 0x25 + x / 3; //計算出該點所在的列地址,注意該液晶每3個點共有一個地址
  write_160160(0, 0x60 | (y & 0x0f)); //寫行地址低位
  write_160160(0, 0x70 | (y >> 4)); //寫行地址高位
  write_160160(0, x & 0x0f); //寫列地址低位
  write_160160(0, 0x10 | (x >> 4)); //寫列地址高位
}

void init160160(void)
{
  digitalWrite(CS, 0);
  /*************************reset*************************/
  digitalWrite(RST, 0);
  delay(2);      //power on reset
  digitalWrite(RST, 1);
  delay(800);
  write_160160(0, 0xe2);     //reset by command
  delay(2);
  /**********************power control*********************/
  write_160160(0, 0xe9);     //Bias Ratio:1/10 bias LCD 偏壓比  偏壓比設置為1/10
  write_160160(0, 0x2b);     //Bias Ratio:1/10 bias LCD 偏壓比  偏壓比設置為1/10
  write_160160(0, 0x24);     //set temperate compensation as 0%  溫度補償   設置驅動偏壓(VBIAS)的溫度補償系TC
  write_160160(0, 0x81);     //electronic potentionmeter   設置對比度調節值 取值范圍為0 ~255
  write_160160(0, 198);   //0xc6不起作用
/**********************display control*******************/
  write_160160(0, 0xa4); //0xa4 關閉所有像素    0xa5  啟動全顯示功能   
  write_160160(0, 0xa6); //關閉像素反顯 決定屏幕反顯     a6為正性顯示;a7為負性顯示
  //write_160160(0, 0xa8);//..顯示使能  開關灰度

  /*************************lcd control********************/
   write_160160(0,0xc0);      //partial display and MX disable,MY enable設置顯示RAM 驅動數據的輸出與驅動行COM 端和驅動列SEG 端的對應關系
  //  write(0,0xc7);//
  //write_160160(0, 0xe2);    //系統初始化,啟用此選項屏變淡
  write_160160(0, 0xa3);     //line rate 15.2klps 設置幀頻率
  write_160160(0, 0xd1);     //rgb-rgb 顯示數據格式
  write_160160(0, 0xd5);     //4k color mode  12-bit/RGB
  write_160160(0, 0x84);     //partial display control disable 局部顯示控制
  /********************n-line inversion********************/
  write_160160(0, 0xc8);  //set n-line inversion
  write_160160(0,0x10);      //enable NIV
  /********************com scan fuction********************/
  write_160160(0, 0xd8);     //enable FRC,PWM,LRM sequence設置COM 掃描模式

    /***********************window***區域操作指令*************************
  *column and row set fix the display district,for example
  *when AC[0]=1,AC[1]=0;(automatic wraparound,column first)
  *column auto_icrement will restart after the end address
  *顯示窗口大小設置
  *********************************************************/
  write_160160(0, 0xf4);     //wpc0:column   操作窗口的左邊界列地址
  write_160160(0, 0x25);     //start from 130  
  write_160160(0, 0xf6);     //wpc1       ending column address   操作窗口右邊界(結束列地址)設置
  write_160160(0, 0x5A);     //end:272      90
  //因為列開始到結尾共90-37=53個數所以 一個數代表160/53=3個像素
  write_160160(0, 0xf5);     //wpp0:row     starting row address   操作窗口上邊界(起始行地址)設置
  write_160160(0, 0x00);     //start from 0
  write_160160(0, 0xf7);     //wpp1       ending  row address    操作窗口下邊界(結束行地址)設置
  write_160160(0, 0x9F);     //end 160  0x9F=159
  //行開始到結束共160個數所以一個數代表160/160=1個像素
  write_160160(0, 0xf8);     //inside mode   窗口操作的使能   0xf9:使能無效
  write_160160(0, 0x89);     //RAM control   地址自動加一    AC1=0 列先增加    AC2=0  控制行增加+1還是-1   AC0=1
  write_160160(0, 0x8b);    //是0x89的90°翻轉顯示      AC1=1 行先增加                 AC0=1
  write_160160(0,0x8d);     //                 AC1=0             AC2=1  控制行增加+1還是-1   AC0=1
  write_160160(0,0x8a);     //這四行控制一次性寫入時地址增加方向  直接向地址中寫數據時不管用....

  write_160160(0, 0xad);     //display on,select on/off mode.Green Enhance mode disable     顯示使能設置 關灰度,增強模式無效  背景深黑雪花
    /***************卷動指令*********scroll line**********滾動行***********/
  write_160160(0, 0x40);     //低4位卷動行號
  write_160160(0, 0x50);     //高4位卷動行號
  write_160160(0, 0xc4);     //19,enable FLT and FLB   set lcd Mapping control
  write_160160(0, 0x90);     //14:FLT,FLB set     局部卷動功能而分解卷動區域和固定區域,FLT,FLB 為固定區域
  write_160160(0, 0x00);
    /**********************partial display*******區域操作指令***********/
  write_160160(0, 0x84);     //12,set partial display controlff  控制局部顯示功能 0x84: 局部顯示無效;0x85:局部顯示使能
  write_160160(0, 0xf1);     //com end      COM 掃描結束行設置
  write_160160(0, 0x9f);     //160           取值范圍0~9F。復位后默認為9FH。
  write_160160(0, 0xf2);     //display start      局部顯示起始行設置
  write_160160(0, 0);      //0
  write_160160(0, 0xf3);     //display end     局部顯示結束行設置
  write_160160(0, 159);    //160
}

void cleadlCD()
{
  uint i;
  write_160160(0,0xf4); write_160160(0,0x25); //設置操作窗口左邊界 0--53
  write_160160(0,0xf5); write_160160(0,0x00); //設置操作窗口上邊界
  write_160160(0,0xf6); write_160160(0,0x5a); //設置操作窗口右邊界
  write_160160(0,0xf7); write_160160(0,0x9f); //設置操作窗口下邊界
  write_160160(0,0xf8); //設置窗口操作使能
  write_160160(0,0x05);write_160160(0,0x12); //設置起始列地址
  write_160160(0,0x60); write_160160(0,0x70); //設置起始行地址

  for (i=0;i<160*28;i++) //循環總的數據量(列塊x 行數)
  {
    write_160160(1,0x00); //寫入數據pixel1,pixel2
    write_160160(1,0x00); //寫入數據pixel3,pixel4
    write_160160(1,0x00); //寫入數據pixel5,pixel6
  }
}

void cleadlCD1()
{
  uint i;
  write_160160(0,0xf4); write_160160(0,0x25); //設置操作窗口左邊界 0--53
  write_160160(0,0xf5); write_160160(0,0x00); //設置操作窗口上邊界
  write_160160(0,0xf6); write_160160(0,0x5a); //設置操作窗口右邊界
  write_160160(0,0xf7); write_160160(0,0x9f); //設置操作窗口下邊界
  write_160160(0,0xf8); //設置窗口操作使能
  write_160160(0,0x05);write_160160(0,0x12); //設置起始列地址
  write_160160(0,0x60); write_160160(0,0x70); //設置起始行地址

  for (i=0;i<160*28;i++) //循環總的數據量(列塊x 行數)
  {
    write_160160(1,0xff); //寫入數據pixel1,pixel2
    write_160160(1,0xff); //寫入數據pixel3,pixel4
    write_160160(1,0xff); //寫入數據pixel5,pixel6
  }
}

void lcdscan(uchar dat1,uchar dat2)
{
  uchar i,j;
  write_160160(0,0x60); write_160160(0,0x25); //設置操作窗口左邊界 0--53
  write_160160(0,0x70); write_160160(0,0x00); //設置操作窗口上邊界
  write_160160(0,0x05); write_160160(0,0x5a); //設置操作窗口右邊界
  write_160160(0,0x12); write_160160(0,0x9f); //設置操作窗口下邊界
  write_160160(0,0xf8);//設置窗口操作使能
  write_160160(0,0x05);write_160160(0,0x12); //設置起始列地址
  write_160160(0,0x60); write_160160(0,0x70); //設置起始行地址
  for(j=0;j<160;j++)
  {
    for(i=0;i<27;i++)
    {
      if(j%2==0)
      {
        write_160160(1,dat1);
        write_160160(1,dat1);
        write_160160(1,dat1);
      }
      else
      {
        write_160160(1,dat2);
        write_160160(1,dat2);
        write_160160(1,dat2);
      }
    }
  }
}


void words_1616(char x, char y, char type, char *p) //type=1,ascii;type=2,Chinese character   顯示16*16像素 漢字  小四
{ //x控制列顯示地址  y控制行顯示地址  
  //漢字取模方式 16*16 從左到右從上到下 縱向8點下高位
  char i, k, j, m, n, l, x0, dat0, dat1, dat2, dat3, dat6;
  x = 37 + x; //控制LCD RAM地址用
  x0 = 0x00 | (x & 0x0f);
  x = 0x10 | ((x & 0xf0) >> 4);
  for (i = 0; i < 2; i++) //橫向 2個字節 因為是縱向取模 所以橫向 共2*8=16個像素點  i的上限為字符寬度/8 eg:16/8=2
  { //i的值控制著字符寬度若顯示48*24則for(i=0;i<6;i++)
    n = i * 8 * type; //縱向 type==2時為漢字 因為是16*16尺寸的漢字所以縱向每次需要16個bit
    //n的值控制著字符高度像素若顯示24*48則n=i*24*type (type==2時顯示漢字)
    for (j = 0; j < 8; j++) //j的8次循環負責將取模字節中的數據還原成8bit像素數據
    {
      m = i * 8 + j; //控制LCD RAM的地址
      write_160160(0, 0x89); //地址自動加一
      write_160160(0, x0); // write display address   area
      write_160160(0, x); //  write display address   area
      write_160160(0, 0x60 | ((y + m) & 0x0f)); //  write display address   area
      write_160160(0, 0x70 | (((y + m) & 0xf0) >> 4)); //  write display address   area
      for (k = 0; k < 2 * type; k++) //此循環顯示漢字的時候執行4*4=16個字節(for循環中用dat0-dat4計算字模中的4個字節)
      {
        l = k * 4 + n; //l和n聯合控制漢字高度因為是24*24所以每次執行4*4=16個循環  其中(4表示k的數據范圍 4表示k的公倍數)
        dat6 = 0x01 << j; //通過上一層j的for循環來取出沒個字節中的8bit數據
        dat0 = (*(p + l))&dat6;
        dat0 = dat0 >> j;
        dat0 <<= 7; //取出字模數組中第p+l個字節的第j位并移到第8位上
        dat1 = (*(p + l + 1))&dat6;
        dat1 = dat1 >> j;
        dat1 <<= 3; //取出字模數組中第p+l+1個字節的第j位并移到第4位上
        dat2 = *(p + 2 + l)&dat6;
        dat2 = dat2 >> j;
        dat2 <<= 7; //取出字模數組中第p+l+2個字節的第j位并移到第8位上
        dat3 = (*(p + 3 + l))&dat6;
        dat3 = dat3 >> j;
        dat3 <<= 3; //取出字模數組中第p+l+3個字節的第j位并移到第8位上
        write_160160(1, dat0 | dat1); //寫入的數據是16進制包含2個字節數據  將dat0放到高4位 dat1放到第4位
        write_160160(1, dat2 | dat3);
      }
      write_160160(0, 0x88);
    }
  }
  write_160160(0, 0x89);
}



void words_2424(char x, char y, char type, char *p)
{ //x控制列顯示地址  y控制行顯示地址 type=1,ascii;type=2,Chinese character   顯示24*24像素   宋體 小二
  //漢字取模方式 24*24 縱向取模  從上往下一次八個點,從左往右  每個ascii加4
  char i, k, j, m, n, l, x0, dat0, dat1, dat2, dat3, dat4, dat5, dat6;
  x = 37 + x;
  x0 = 0x00 | (x & 0x0f);
  x = 0x10 | ((x & 0xf0) >> 4);

  for (i = 0; i < 3; i++) //橫向 3個字節 因為是縱向取模 所以橫向 共3*8=24個像素點  i的上限為字符寬度/8 eg:24/8=3
  { //i的值控制著字符寬度若顯示48*24則for(i=0;i<6;i++)
    n = i * 12 * type; //縱向 type==2時為漢字 因為是24*24尺寸的漢字所以縱向每次需要24個bit
    //n的值控制著字符高度像素若顯示24*48則n=i*24*type (type==2時顯示漢字)
    for (j = 0; j < 8; j++) //j的8次循環負責將取模字節中的數據還原成8bit像素數據
    {
      m = i * 8 + j; //控制LCD RAM的地址
      write_160160(0, 0x89); //地址自動加一
      write_160160(0, x0); // write display address   area
      write_160160(0, x); //  write display address   area
      write_160160(0, 0x60 | ((y + m) & 0x0f)); //  write display address   area
      write_160160(0, 0x70 | (((y + m) & 0xf0) >> 4)); //  write display address   area
      for (k = 0; k < 2 * type; k++) //此循環顯示漢字的時候執行4*6=24個字節(for循環中用dat0-dat6計算字模中的6個字節)
      {
        l = k * 6 + n; //l和n聯合控制漢字高度因為是24*24所以每次執行4*6=24個循環  其中(4表示k的數據范圍 6表示k的公倍數)
        dat6 = 0x01 << j; //通過上一層j的for循環來取出沒個字節中的8bit數據
        dat0 = (*(p + l))&dat6;
        dat0 = dat0 >> j;
        dat0 <<= 7; //取出字模數組中第p+l個字節的第j位并移到第8位上
        dat1 = (*(p + l + 1))&dat6;
        dat1 = dat1 >> j;
        dat1 <<= 3; //取出字模數組中第p+l+1個字節的第j位并移到第4位上
        dat2 = *(p + 2 + l)&dat6;
        dat2 = dat2 >> j;
        dat2 <<= 7; //取出字模數組中第p+2個字節的第j位并移到第8位上
        dat3 = (*(p + 3 + l))&dat6;
        dat3 = dat3 >> j;
        dat3 <<= 3; //取出字模數組中第p+l+3個字節的第j位并移到第4位上
        dat4 = (*(p + 4 + l))&dat6;
        dat4 = dat4 >> j;
        dat4 <<= 7; //取出字模數組中第p+l+4個字節的第j位并移到第8位上
        dat5 = (*(p + 5 + l))&dat6;
        dat5 = dat5 >> j;
        dat5 <<= 3; //取出字模數組中第p+l+5個字節的第j位并移到第4位上
        write_160160(1, dat0 | dat1); //寫入的數據是16進制包含2個字節數據  將dat0放到高4位 dat1放到第4位
        write_160160(1, dat2 | dat3);
        write_160160(1, dat4 | dat5);
      }
      write_160160(0, 0x88); //
    }
  }
  write_160160(0, 0x89);
}

//--圖形寫入函數-------------------
// 圖形格式要求:水平方向寬度要以3 和8 的倍數出現
// 8 的倍數是數據以字節形式出現
// 3 的倍數是因為DDRAM 列地址以列塊形式計算的,即3 點像素數據為一個列塊
void ShowBMP(uchar x,uchar y,uchar width,uchar high,uchar bmp[])
{
  // 坐標X 為像素列塊0-79 列塊,3 像素點數據/列塊
  // 坐標Y 為像素點行數0-159
  // 圖形寬度width 為水平方向點列數,要求該值為3 和8 的倍數
  // 圖形高度high 為垂直方向點行數,取值為0-159
  // 圖形數組bmp[]為所要寫入的圖形數據,以1bpp(8dots/byte)、水平排列格式表示
  uint p;
  uchar i,j,k,m,Ddata;
    write_160160(0,0xf4);  write_160160(0,0x25+x);        // 設置操作窗口左邊界
    write_160160(0,0xf5);  write_160160(0,y);             // 設置操作窗口上邊界
    write_160160(0,0xf6);  write_160160(0,0x25+x+width/3-1);  // 設置操作窗口右邊界
    write_160160(0,0xf7);  write_160160(0,high-1+y);        // 設置操作窗口下邊界
    write_160160(0,0xf8);                          // 設置窗口操作使能
    x=x+0x25;
    write_160160(0,x&0x0f);  write_160160(0,0x10|(x>>4)); // 設置起始列地址
    write_160160(0,0x60+(y&0x0f));   write_160160(0,0x70+(y>>4)); // 設置起始行地址
  p=0; // 數組指針初始化
  for(i=0;i<high;i++) // 循環行數數據量
  {
    for ( j=0;j<width/8;j++) // 循環字節數/行
    {
      k=bmp[p++]; // 取圖形數據
      for (m=0;m<4;m++) // 1 字節轉換成4 字節數據寫入
      {
        switch (k&0xc0) // 根據數據位值設置顯示數據
        {
          case 0x00 : Ddata=0x00;break;
          case 0x40 : Ddata=0x0f;break;
          case 0x80 : Ddata=0xf0;break;
          case 0xc0 : Ddata=0xff;break;
        }
          write_160160(1,Ddata); // 寫入數據
        k=k<<2;
      }
    }
    switch (width%3)
    {
      case 0 : break;
      case 1 : write_160160(1,0x00);break; //補充余數據為0
      case 2 : write_160160(1,0x00); write_160160(1,0x00);break;// 補充余數據為0
    }
  }
}


void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(RST, OUTPUT);
  pinMode(sda, OUTPUT);
  pinMode(sck, OUTPUT);
  pinMode(CS, OUTPUT);
  pinMode(CD, OUTPUT);

  pinMode(pinDHT11, OUTPUT);

  Serial.begin(115200);

  init160160();
  words_1616(8,24,2,shi);
  cleadlCD();
  Serial.println("初始化完成");
   }

void loop() {

  words_2424(10, 1, 2, wen);
  words_2424(18, 1, 2, du);
  words_2424(26, 1, 1, abc);
  words_2424(10, 25, 2, shi);
  words_2424(18, 25, 2, du);
  words_2424(26, 25, 1, abc);

  Serial.println("=================================");
  Serial.println("Sample DHT11...");

  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
   Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
   return;
  }
  
  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" H");
  delay(1500);
  num_str_2412(30,1,(int)temperature);
words_1616(39, 0, 1, O);
  words_2424(42, 1, 1, C);

  num_str_2412(30,25,(int)humidity);
  words_2424(39, 25, 1, H);


num_str_2412(0,0,i);
i++;
if(i>30) i=0;

  ShowBMP(10,50,120,110,col);
  delay(1000);


  Serial.println("start");
}
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美电影免费观看 | 日韩免费福利视频 | 91 久久| 羞羞视频免费在线 | 国产精品久久国产精品 | 精品毛片视频 | 一级片视频免费观看 | 天堂色网 | 国产人成精品一区二区三 | 亚洲成人av | 国产精品一区二区福利视频 | 丝袜一区二区三区 | 天天操操操操操 | 成年视频在线观看福利资源 | 国产 日韩 欧美 中文 在线播放 | 999免费视频 | 在线观看免费高清av | 欧美专区在线视频 | 一区二区三区国产精品 | 综合在线视频 | 亚洲成人午夜电影 | 天天操妹子 | 国产精品a免费一区久久电影 | 成人在线视频一区 | 国产成人精品一区二区三区四区 | 亚洲一区二区三区免费在线观看 | 亚洲视频在线观看一区二区三区 | www亚洲精品| 中文字幕av在线 | 黄色三级毛片 | 99精品欧美一区二区蜜桃免费 | 黄色片网此 | 中文字幕日本一区二区 | 久久精品国产亚洲a | 伊人久久大香线 | 三级视频在线观看 | 成人免费观看视频 | 欧美一区免费 | 91福利网| 国产成人免费视频网站视频社区 | 精品一区二区三区在线观看 |