找回密码
 立即注册

QQ登录

只需一步,快速开始

帖子
查看: 3721|回复: 3
收起左侧

LCD240128(UC1698芯片)驱动程序 C语言 STM32的FSMC

[复制链接]
ID:848886 发表于 2021-6-16 10:09 | 显示全部楼层 |阅读模式
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黑下载附件…………
复制代码
51hei.png
以上3个文件51hei下载,不含工程文件,请自行移植:
LCD_240128CFW显示屏(FSMC).rar (19.85 KB, 下载次数: 63)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

举报

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 单片机教程网

快速回复 返回顶部 返回列表