欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
LCD240128(UC1698芯片)驅(qū)動(dòng)程序 C語(yǔ)言 STM32的FSMC
[打印本頁(yè)]
作者:
tqtetgpv
時(shí)間:
2021-6-16 10:09
標(biāo)題:
LCD240128(UC1698芯片)驅(qū)動(dòng)程序 C語(yǔ)言 STM32的FSMC
LCD240128(UC1698芯片)驅(qū)動(dòng)采用STM32的FSMC
單片機(jī)源程序如下:
/*
(芯片:UC1698 芯片驅(qū)動(dòng),參考LCD_240128CFW顯示屏)
*/
#include "UC1698.h"
#include "FONT.H"
//LCD重要參數(shù)集
typedef struct
{
u16 width; //LCD 寬度
u16 height; //LCD 高度
u16 id; //LCD ID
u8 dir; //橫屏還是豎屏控制:0,豎屏;1,橫屏。
u16 wramcmd; //開(kāi)始寫(xiě)gram指令
u16 setxcmd; //設(shè)置x坐標(biāo)指令
u16 setycmd; //設(shè)置y坐標(biāo)指令
}lcd_dev;
/*************LCD 屏的像素LCD_MAX_width * LCD_MAX_height *********************************/
#define LCD_MAX_width 240
#define LCD_MAX_height 128
/*************UC1698寄存器控制命令*********************************/
#define UC1698_CA_LSB(x) (0x00|(0x0f&x)) //Set Column Address LSB 列地址
#define UC1698_CA_MSB(x) (0x10|0x0f&(x>>4)) //Set Column Address MSB 列地址
#define UC1698_TC(x) (0x24|(0x03&x)) //Set Temp. Compensation 溫度補(bǔ)償LSB
#define UC1698_PC(x) (0x28|(0x03&x)) //Set Power control 功率控制
#define UC1698_RA_LSB(y) (0x60|(0x0f&y)) //Set row Address LSB 行地址
#define UC1698_RA_MSB(y) (0x70|0x0f&(y>>4)) //Set Row Address MSB 行地址
#define UC1698_PDC_LC(x) (0x84|x) //Set Partial Display Control
#define UC1698_PM 0x81 //Set VBIAS Potentiometer 設(shè)置對(duì)比度bf(ContrastLevel)
#define UC1698_RAC_AC(x) (0x88|(0x07&x)) //Set RAM Address Control RAM地址控制
#define UC1698_LR_LC(x) (0xa0|(0x03&x)) //Set Line rate 設(shè)置行掃描頻率
#define UC1698_AP_DC(x) (0xa4|x) //Set All-Pixel-ON 顯示特性性
#define UC1698_ID_DC(x) (0xa6|x) //Set Inverse display 設(shè)置方向顯示(0--正、1--反向);
#define UC1698_DE_DC 0xad //Set Display enable 開(kāi)顯示
#define UC1698_MC_DC(x) (0xC0|(0x07&x)) //Set LCD Mapping contro 設(shè)置lcd映射控制:LCD映像MY=1,MX=0,LC0=0
#define UC1698_NIV 0xC8 //Set N-Line Inversion 設(shè)置M信號(hào)為0行翻磚(LCD_WR_REG(0x10); )
#define UC1698_CP_LC(x) (0xD0|x) //Set Color pattern彩色數(shù)據(jù)格式 0/1
#define UC1698_CM_LC(x) (0xD4|(0X03&x)) //Set Color Mode 彩色數(shù)據(jù)模式 0x01:12位 0x02:16位
#define UC1698_CSF(x) (0xd8|(x&0X07)) //Set COM Scan Function 掃描模式
#define UC1698_BR(x) (0xE8|(x&0X03)) //Set LCD Bias Ratio 設(shè)置偏壓比1/10 LCD_WR_REG(0xe9);
#define UC1698_CEN 0xf1 //Set COM End
#define UC1698_DST 0xf2 //Set Partial Display Start
#define UC1698_CDEN 0xf3 //Set Set Partial Display End
#define UC1698_WPC0 0xf4 // Set Window Program Starting Columm Address 窗口左邊界
#define UC1698_WPP0 0xf5 // Set Window Program Starting Row Address 窗口上邊界
#define UC1698_WPC1 0xf6 // Set Window Program Ending Columm Address 窗口右邊界
#define UC1698_WPP1 0xf7 // Set Window Program Starting Row Address 窗口下邊界
#define UC1698_WPM_AC(x) (0xf8|x) // Window Program Mode: 0 ->Inside;1-> All area
static vu8 ContrastLevel = 0x2D; //對(duì)比度bf
#if Address_struct==1
//寫(xiě)寄存器函數(shù) 指令寫(xiě)入子程序-
//regval:寄存器值
void LCD_WR_REG(vu16 regval)
{
regval=regval; //使用-O2優(yōu)化的時(shí)候,必須插入的延時(shí)
LCD->LCD_REG=regval;//寫(xiě)入要寫(xiě)的寄存器序號(hào)
}
//寫(xiě)LCD數(shù)據(jù) 數(shù)據(jù)寫(xiě)入子程序
//data:要寫(xiě)入的值
void LCD_WR_DATA(vu16 data)
{
data=data; //使用-O2優(yōu)化的時(shí)候,必須插入的延時(shí)
LCD->LCD_RAM=data;
}
//讀LCD數(shù)據(jù)
//返回值:讀到的值
u16 LCD_RD_DATA(void)
{
vu16 ram; //防止被優(yōu)化
ram=LCD->LCD_RAM;
return ram;
}
#endif
/*************FSMC********************************
************* *********************************/
void FSMC_Init(void){
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
FSMC_NORSRAMTimingInitTypeDef writeTiming;
readWriteTiming.FSMC_AddressSetupTime = 0XF; //地址建立時(shí)間(ADDSET)為16個(gè)HCLK 1/168M=6ns*16=96ns
readWriteTiming.FSMC_AddressHoldTime = 0x00; //地址保持時(shí)間(ADDHLD)模式A未用到
readWriteTiming.FSMC_DataSetupTime = 60; //數(shù)據(jù)保存時(shí)間為60個(gè)HCLK =6*60=360ns
readWriteTiming.FSMC_BusTurnAroundDuration = 0x00; //總線(xiàn)恢復(fù)時(shí)間
readWriteTiming.FSMC_CLKDivision = 0x00; // 時(shí)鐘分頻因子
readWriteTiming.FSMC_DataLatency = 0x00; //數(shù)據(jù)產(chǎn)生時(shí)間
readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; // //FSMC NOR控制器時(shí)序:模式A
writeTiming.FSMC_AddressSetupTime =10; //地址建立時(shí)間(ADDSET)為9個(gè)HCLK =54ns
writeTiming.FSMC_AddressHoldTime = 10; //地址保持時(shí)間(A
writeTiming.FSMC_DataSetupTime = 10; //數(shù)據(jù)保存時(shí)間為6ns*9個(gè)HCLK=54ns
writeTiming.FSMC_BusTurnAroundDuration = 0x00;
writeTiming.FSMC_CLKDivision = 0x00;
writeTiming.FSMC_DataLatency = 0x00;
writeTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;// 這里我們使用NE4 ,也就對(duì)應(yīng)BTCR[6],[7]。--》 nor被分為四塊,其中這個(gè)參數(shù)是說(shuō)明對(duì)那個(gè)塊編程
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // 不復(fù)用數(shù)據(jù)地址--》 地址\數(shù)據(jù)是否復(fù)用
FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM; //SRAM --》 存儲(chǔ)器類(lèi)型
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;//存儲(chǔ)器數(shù)據(jù)寬度為16bit --》數(shù)據(jù)總線(xiàn)寬度 8位/16位
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable; --》是否進(jìn)行成組模式訪(fǎng)問(wèn)
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;//等待信號(hào)有效級(jí)性
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; //該位決定控制器是否支持把非對(duì)齊的AHB成組操作分割成2次線(xiàn)性操作;該位僅在存儲(chǔ)器的成組模式下有效。
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; //當(dāng)閃存存儲(chǔ)器處于成組傳輸模式時(shí),NWAIT信號(hào)指示從閃存存儲(chǔ)器出來(lái)的數(shù)據(jù)是否有效或是否需要插入等待周期。該位決定存儲(chǔ)器是在等待狀態(tài)之前的一個(gè)時(shí)鐘周期產(chǎn)生NWAIT信號(hào),還是在等待狀態(tài)期間產(chǎn)生NWAIT信號(hào)。
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; // 存儲(chǔ)器寫(xiě)使能----》該位指示FSMC是否允許/禁止對(duì)存儲(chǔ)器的寫(xiě)操作。
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //當(dāng)閃存存儲(chǔ)器處于成組傳輸模式時(shí),這一位允許/禁止通過(guò)NWAIT信號(hào)插入等待狀態(tài)。
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable; //設(shè)置是否使能在同步傳輸時(shí)使用的等待信號(hào),在控制同步類(lèi)型的NOR或PSRAM時(shí),存儲(chǔ)器可以使用FSMC_NWAIT引腳通知STM32需要等待。
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
//FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; // 讀寫(xiě)使用不同的時(shí)序 --》該位允許FSMC使用FSMC_BWTR寄存器,即允許讀和寫(xiě)使用不同的時(shí)序。
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //對(duì)于處于成組傳輸模式的閃存存儲(chǔ)器,這一位允許/禁止通過(guò)NWAIT信號(hào)插入等待狀態(tài)。讀操作的同步成組傳輸協(xié)議使能位是FSMC_BCRx寄存器的BURSTEN位。
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming; //寫(xiě)時(shí)序--->//寫(xiě)時(shí)序配置指針
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //讀寫(xiě)時(shí)序--->//讀時(shí)序配置指針
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); // 使能BANK1
}
//初始化lcd
//該初始化函數(shù)可以初始化各種ILI93XX液晶,但是其他函數(shù)是基于ILI9320的!!!
//在其他型號(hào)的驅(qū)動(dòng)芯片上沒(méi)有測(cè)試!
void LCD_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//************************打開(kāi)相應(yīng)的時(shí)鐘使能***********************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG, ENABLE);//使能PD,PE,PF,PG時(shí)鐘
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);//使能FSMC時(shí)鐘
//************************背光燈的設(shè)置***********************************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通輸出模式
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//GPIOE PE對(duì)應(yīng)IO口(背光燈)
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化GPIO
GPIO_SetBits(GPIOE,GPIO_Pin_5);//PE5 設(shè)置為高,
//BLK_OFF;
//************************LCD復(fù)位***********************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//GPIOG PG對(duì)應(yīng)IO口(LCD復(fù)位)
GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化GPIO
GPIO_SetBits(GPIOG,GPIO_Pin_3); // 設(shè)置為高,
//************************數(shù)據(jù)總線(xiàn)與使能線(xiàn)的IO配置***********************************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//復(fù)用輸出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_14|GPIO_Pin_15;
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_12;//PF12,FSMC_A6
GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化
//************************相應(yīng)管腳映射到FSMC接口 數(shù)據(jù)總線(xiàn)+使能控制線(xiàn)***********************************/
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC); //-->D0
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC); //-->D1
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC); //-->D2
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC); //-->D3
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC); //-->D4
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC); //-->D5
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC); //-->D6
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC); //-->D7
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC); //-->RD
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC); //-->WR
GPIO_PinAFConfig(GPIOG,GPIO_PinSource12,GPIO_AF_FSMC); // -->CS
GPIO_PinAFConfig(GPIOG,GPIO_PinSource2,GPIO_AF_FSMC); //->CD(A12)
FSMC_Init();//FSMC_初始化
LCD_RESET_L;
delay_ms(6);
LCD_RESET_H;
delay_ms(80);
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
51hei.png
(5.26 KB, 下載次數(shù): 45)
下載附件
2021-6-16 20:05 上傳
以上3個(gè)文件51hei下載,不含工程文件,請(qǐng)自行移植:
LCD_240128CFW顯示屏(FSMC).rar
(19.85 KB, 下載次數(shù): 63)
2021-6-16 10:09 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
老二不怕黑
時(shí)間:
2025-4-3 11:26
值得借鑒,謝謝
作者:
突然想學(xué)習(xí)
時(shí)間:
2025-6-4 16:49
學(xué)習(xí)一下。謝謝
作者:
joyb
時(shí)間:
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; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬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; //計(jì)算出該點(diǎn)所在的列地址,注意該液晶每3個(gè)點(diǎn)共有一個(gè)地址
write_160160(0, 0x60 | (y & 0x0f)); //寫(xiě)行地址低位
write_160160(0, 0x70 | (y >> 4)); //寫(xiě)行地址高位
write_160160(0, x & 0x0f); //寫(xiě)列地址低位
write_160160(0, 0x10 | (x >> 4)); //寫(xiě)列地址高位
}
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 偏壓比 偏壓比設(shè)置為1/10
write_160160(0, 0x2b); //Bias Ratio:1/10 bias LCD 偏壓比 偏壓比設(shè)置為1/10
write_160160(0, 0x24); //set temperate compensation as 0% 溫度補(bǔ)償 設(shè)置驅(qū)動(dòng)偏壓(VBIAS)的溫度補(bǔ)償系TC
write_160160(0, 0x81); //electronic potentionmeter 設(shè)置對(duì)比度調(diào)節(jié)值 取值范圍為0 ~255
write_160160(0, 198); //0xc6不起作用
/**********************display control*******************/
write_160160(0, 0xa4); //0xa4 關(guān)閉所有像素 0xa5 啟動(dòng)全顯示功能
write_160160(0, 0xa6); //關(guān)閉像素反顯 決定屏幕反顯 a6為正性顯示;a7為負(fù)性顯示
//write_160160(0, 0xa8);//..顯示使能 開(kāi)關(guān)灰度
/*************************lcd control********************/
write_160160(0,0xc0); //partial display and MX disable,MY enable設(shè)置顯示RAM 驅(qū)動(dòng)數(shù)據(jù)的輸出與驅(qū)動(dòng)行COM 端和驅(qū)動(dòng)列SEG 端的對(duì)應(yīng)關(guān)系
// write(0,0xc7);//
//write_160160(0, 0xe2); //系統(tǒng)初始化,啟用此選項(xiàng)屏變淡
write_160160(0, 0xa3); //line rate 15.2klps 設(shè)置幀頻率
write_160160(0, 0xd1); //rgb-rgb 顯示數(shù)據(jù)格式
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設(shè)置COM 掃描模式
/***********************window***區(qū)域操作指令*************************
*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
*顯示窗口大小設(shè)置
*********************************************************/
write_160160(0, 0xf4); //wpc0:column 操作窗口的左邊界列地址
write_160160(0, 0x25); //start from 130
write_160160(0, 0xf6); //wpc1 ending column address 操作窗口右邊界(結(jié)束列地址)設(shè)置
write_160160(0, 0x5A); //end:272 90
//因?yàn)榱虚_(kāi)始到結(jié)尾共90-37=53個(gè)數(shù)所以 一個(gè)數(shù)代表160/53=3個(gè)像素
write_160160(0, 0xf5); //wpp0:row starting row address 操作窗口上邊界(起始行地址)設(shè)置
write_160160(0, 0x00); //start from 0
write_160160(0, 0xf7); //wpp1 ending row address 操作窗口下邊界(結(jié)束行地址)設(shè)置
write_160160(0, 0x9F); //end 160 0x9F=159
//行開(kāi)始到結(jié)束共160個(gè)數(shù)所以一個(gè)數(shù)代表160/160=1個(gè)像素
write_160160(0, 0xf8); //inside mode 窗口操作的使能 0xf9:使能無(wú)效
write_160160(0, 0x89); //RAM control 地址自動(dòng)加一 AC1=0 列先增加 AC2=0 控制行增加+1還是-1 AC0=1
write_160160(0, 0x8b); //是0x89的90°翻轉(zhuǎn)顯示 AC1=1 行先增加 AC0=1
write_160160(0,0x8d); // AC1=0 AC2=1 控制行增加+1還是-1 AC0=1
write_160160(0,0x8a); //這四行控制一次性寫(xiě)入時(shí)地址增加方向 直接向地址中寫(xiě)數(shù)據(jù)時(shí)不管用....
write_160160(0, 0xad); //display on,select on/off mode.Green Enhance mode disable 顯示使能設(shè)置 關(guān)灰度,增強(qiáng)模式無(wú)效 背景深黑雪花
/***************卷動(dòng)指令*********scroll line**********滾動(dòng)行***********/
write_160160(0, 0x40); //低4位卷動(dòng)行號(hào)
write_160160(0, 0x50); //高4位卷動(dòng)行號(hào)
write_160160(0, 0xc4); //19,enable FLT and FLB set lcd Mapping control
write_160160(0, 0x90); //14:FLT,FLB set 局部卷動(dòng)功能而分解卷動(dòng)區(qū)域和固定區(qū)域,F(xiàn)LT,FLB 為固定區(qū)域
write_160160(0, 0x00);
/**********************partial display*******區(qū)域操作指令***********/
write_160160(0, 0x84); //12,set partial display controlff 控制局部顯示功能 0x84: 局部顯示無(wú)效;0x85:局部顯示使能
write_160160(0, 0xf1); //com end COM 掃描結(jié)束行設(shè)置
write_160160(0, 0x9f); //160 取值范圍0~9F。復(fù)位后默認(rèn)為9FH。
write_160160(0, 0xf2); //display start 局部顯示起始行設(shè)置
write_160160(0, 0); //0
write_160160(0, 0xf3); //display end 局部顯示結(jié)束行設(shè)置
write_160160(0, 159); //160
}
void cleadlCD()
{
uint i;
write_160160(0,0xf4); write_160160(0,0x25); //設(shè)置操作窗口左邊界 0--53
write_160160(0,0xf5); write_160160(0,0x00); //設(shè)置操作窗口上邊界
write_160160(0,0xf6); write_160160(0,0x5a); //設(shè)置操作窗口右邊界
write_160160(0,0xf7); write_160160(0,0x9f); //設(shè)置操作窗口下邊界
write_160160(0,0xf8); //設(shè)置窗口操作使能
write_160160(0,0x05);write_160160(0,0x12); //設(shè)置起始列地址
write_160160(0,0x60); write_160160(0,0x70); //設(shè)置起始行地址
for (i=0;i<160*28;i++) //循環(huán)總的數(shù)據(jù)量(列塊x 行數(shù))
{
write_160160(1,0x00); //寫(xiě)入數(shù)據(jù)pixel1,pixel2
write_160160(1,0x00); //寫(xiě)入數(shù)據(jù)pixel3,pixel4
write_160160(1,0x00); //寫(xiě)入數(shù)據(jù)pixel5,pixel6
}
}
void cleadlCD1()
{
uint i;
write_160160(0,0xf4); write_160160(0,0x25); //設(shè)置操作窗口左邊界 0--53
write_160160(0,0xf5); write_160160(0,0x00); //設(shè)置操作窗口上邊界
write_160160(0,0xf6); write_160160(0,0x5a); //設(shè)置操作窗口右邊界
write_160160(0,0xf7); write_160160(0,0x9f); //設(shè)置操作窗口下邊界
write_160160(0,0xf8); //設(shè)置窗口操作使能
write_160160(0,0x05);write_160160(0,0x12); //設(shè)置起始列地址
write_160160(0,0x60); write_160160(0,0x70); //設(shè)置起始行地址
for (i=0;i<160*28;i++) //循環(huán)總的數(shù)據(jù)量(列塊x 行數(shù))
{
write_160160(1,0xff); //寫(xiě)入數(shù)據(jù)pixel1,pixel2
write_160160(1,0xff); //寫(xiě)入數(shù)據(jù)pixel3,pixel4
write_160160(1,0xff); //寫(xiě)入數(shù)據(jù)pixel5,pixel6
}
}
void lcdscan(uchar dat1,uchar dat2)
{
uchar i,j;
write_160160(0,0x60); write_160160(0,0x25); //設(shè)置操作窗口左邊界 0--53
write_160160(0,0x70); write_160160(0,0x00); //設(shè)置操作窗口上邊界
write_160160(0,0x05); write_160160(0,0x5a); //設(shè)置操作窗口右邊界
write_160160(0,0x12); write_160160(0,0x9f); //設(shè)置操作窗口下邊界
write_160160(0,0xf8);//設(shè)置窗口操作使能
write_160160(0,0x05);write_160160(0,0x12); //設(shè)置起始列地址
write_160160(0,0x60); write_160160(0,0x70); //設(shè)置起始行地址
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點(diǎn)下高位
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個(gè)字節(jié) 因?yàn)槭强v向取模 所以橫向 共2*8=16個(gè)像素點(diǎn) i的上限為字符寬度/8 eg:16/8=2
{ //i的值控制著字符寬度若顯示48*24則for(i=0;i<6;i++)
n = i * 8 * type; //縱向 type==2時(shí)為漢字 因?yàn)槭?6*16尺寸的漢字所以縱向每次需要16個(gè)bit
//n的值控制著字符高度像素若顯示24*48則n=i*24*type (type==2時(shí)顯示漢字)
for (j = 0; j < 8; j++) //j的8次循環(huán)負(fù)責(zé)將取模字節(jié)中的數(shù)據(jù)還原成8bit像素?cái)?shù)據(jù)
{
m = i * 8 + j; //控制LCD RAM的地址
write_160160(0, 0x89); //地址自動(dòng)加一
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++) //此循環(huán)顯示漢字的時(shí)候執(zhí)行4*4=16個(gè)字節(jié)(for循環(huán)中用dat0-dat4計(jì)算字模中的4個(gè)字節(jié))
{
l = k * 4 + n; //l和n聯(lián)合控制漢字高度因?yàn)槭?4*24所以每次執(zhí)行4*4=16個(gè)循環(huán) 其中(4表示k的數(shù)據(jù)范圍 4表示k的公倍數(shù))
dat6 = 0x01 << j; //通過(guò)上一層j的for循環(huán)來(lái)取出沒(méi)個(gè)字節(jié)中的8bit數(shù)據(jù)
dat0 = (*(p + l))&dat6;
dat0 = dat0 >> j;
dat0 <<= 7; //取出字模數(shù)組中第p+l個(gè)字節(jié)的第j位并移到第8位上
dat1 = (*(p + l + 1))&dat6;
dat1 = dat1 >> j;
dat1 <<= 3; //取出字模數(shù)組中第p+l+1個(gè)字節(jié)的第j位并移到第4位上
dat2 = *(p + 2 + l)&dat6;
dat2 = dat2 >> j;
dat2 <<= 7; //取出字模數(shù)組中第p+l+2個(gè)字節(jié)的第j位并移到第8位上
dat3 = (*(p + 3 + l))&dat6;
dat3 = dat3 >> j;
dat3 <<= 3; //取出字模數(shù)組中第p+l+3個(gè)字節(jié)的第j位并移到第8位上
write_160160(1, dat0 | dat1); //寫(xiě)入的數(shù)據(jù)是16進(jìn)制包含2個(gè)字節(jié)數(shù)據(jù) 將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 縱向取模 從上往下一次八個(gè)點(diǎn),從左往右 每個(gè)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個(gè)字節(jié) 因?yàn)槭强v向取模 所以橫向 共3*8=24個(gè)像素點(diǎn) i的上限為字符寬度/8 eg:24/8=3
{ //i的值控制著字符寬度若顯示48*24則for(i=0;i<6;i++)
n = i * 12 * type; //縱向 type==2時(shí)為漢字 因?yàn)槭?4*24尺寸的漢字所以縱向每次需要24個(gè)bit
//n的值控制著字符高度像素若顯示24*48則n=i*24*type (type==2時(shí)顯示漢字)
for (j = 0; j < 8; j++) //j的8次循環(huán)負(fù)責(zé)將取模字節(jié)中的數(shù)據(jù)還原成8bit像素?cái)?shù)據(jù)
{
m = i * 8 + j; //控制LCD RAM的地址
write_160160(0, 0x89); //地址自動(dòng)加一
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++) //此循環(huán)顯示漢字的時(shí)候執(zhí)行4*6=24個(gè)字節(jié)(for循環(huán)中用dat0-dat6計(jì)算字模中的6個(gè)字節(jié))
{
l = k * 6 + n; //l和n聯(lián)合控制漢字高度因?yàn)槭?4*24所以每次執(zhí)行4*6=24個(gè)循環(huán) 其中(4表示k的數(shù)據(jù)范圍 6表示k的公倍數(shù))
dat6 = 0x01 << j; //通過(guò)上一層j的for循環(huán)來(lái)取出沒(méi)個(gè)字節(jié)中的8bit數(shù)據(jù)
dat0 = (*(p + l))&dat6;
dat0 = dat0 >> j;
dat0 <<= 7; //取出字模數(shù)組中第p+l個(gè)字節(jié)的第j位并移到第8位上
dat1 = (*(p + l + 1))&dat6;
dat1 = dat1 >> j;
dat1 <<= 3; //取出字模數(shù)組中第p+l+1個(gè)字節(jié)的第j位并移到第4位上
dat2 = *(p + 2 + l)&dat6;
dat2 = dat2 >> j;
dat2 <<= 7; //取出字模數(shù)組中第p+2個(gè)字節(jié)的第j位并移到第8位上
dat3 = (*(p + 3 + l))&dat6;
dat3 = dat3 >> j;
dat3 <<= 3; //取出字模數(shù)組中第p+l+3個(gè)字節(jié)的第j位并移到第4位上
dat4 = (*(p + 4 + l))&dat6;
dat4 = dat4 >> j;
dat4 <<= 7; //取出字模數(shù)組中第p+l+4個(gè)字節(jié)的第j位并移到第8位上
dat5 = (*(p + 5 + l))&dat6;
dat5 = dat5 >> j;
dat5 <<= 3; //取出字模數(shù)組中第p+l+5個(gè)字節(jié)的第j位并移到第4位上
write_160160(1, dat0 | dat1); //寫(xiě)入的數(shù)據(jù)是16進(jìn)制包含2個(gè)字節(jié)數(shù)據(jù) 將dat0放到高4位 dat1放到第4位
write_160160(1, dat2 | dat3);
write_160160(1, dat4 | dat5);
}
write_160160(0, 0x88); //
}
}
write_160160(0, 0x89);
}
//--圖形寫(xiě)入函數(shù)-------------------
// 圖形格式要求:水平方向?qū)挾纫? 和8 的倍數(shù)出現(xiàn)
// 8 的倍數(shù)是數(shù)據(jù)以字節(jié)形式出現(xiàn)
// 3 的倍數(shù)是因?yàn)镈DRAM 列地址以列塊形式計(jì)算的,即3 點(diǎn)像素?cái)?shù)據(jù)為一個(gè)列塊
void ShowBMP(uchar x,uchar y,uchar width,uchar high,uchar bmp[])
{
// 坐標(biāo)X 為像素列塊0-79 列塊,3 像素點(diǎn)數(shù)據(jù)/列塊
// 坐標(biāo)Y 為像素點(diǎn)行數(shù)0-159
// 圖形寬度width 為水平方向點(diǎn)列數(shù),要求該值為3 和8 的倍數(shù)
// 圖形高度high 為垂直方向點(diǎn)行數(shù),取值為0-159
// 圖形數(shù)組bmp[]為所要寫(xiě)入的圖形數(shù)據(jù),以1bpp(8dots/byte)、水平排列格式表示
uint p;
uchar i,j,k,m,Ddata;
write_160160(0,0xf4); write_160160(0,0x25+x); // 設(shè)置操作窗口左邊界
write_160160(0,0xf5); write_160160(0,y); // 設(shè)置操作窗口上邊界
write_160160(0,0xf6); write_160160(0,0x25+x+width/3-1); // 設(shè)置操作窗口右邊界
write_160160(0,0xf7); write_160160(0,high-1+y); // 設(shè)置操作窗口下邊界
write_160160(0,0xf8); // 設(shè)置窗口操作使能
x=x+0x25;
write_160160(0,x&0x0f); write_160160(0,0x10|(x>>4)); // 設(shè)置起始列地址
write_160160(0,0x60+(y&0x0f)); write_160160(0,0x70+(y>>4)); // 設(shè)置起始行地址
p=0; // 數(shù)組指針初始化
for(i=0;i<high;i++) // 循環(huán)行數(shù)數(shù)據(jù)量
{
for ( j=0;j<width/8;j++) // 循環(huán)字節(jié)數(shù)/行
{
k=bmp[p++]; // 取圖形數(shù)據(jù)
for (m=0;m<4;m++) // 1 字節(jié)轉(zhuǎn)換成4 字節(jié)數(shù)據(jù)寫(xiě)入
{
switch (k&0xc0) // 根據(jù)數(shù)據(jù)位值設(shè)置顯示數(shù)據(jù)
{
case 0x00 : Ddata=0x00;break;
case 0x40 : Ddata=0x0f;break;
case 0x80 : Ddata=0xf0;break;
case 0xc0 : Ddata=0xff;break;
}
write_160160(1,Ddata); // 寫(xiě)入數(shù)據(jù)
k=k<<2;
}
}
switch (width%3)
{
case 0 : break;
case 1 : write_160160(1,0x00);break; //補(bǔ)充余數(shù)據(jù)為0
case 2 : write_160160(1,0x00); write_160160(1,0x00);break;// 補(bǔ)充余數(shù)據(jù)為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");
}
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1