现象是综合测试实验的主画面出不来,但是点进去后其他模块能正常显示!
请教原子哥,以下是改动的ILI93XX.c文件,蓝 {MOD}重点改动的,其他小地方需要变的也跟着变了!我这边默认是L2R U2D模式,背光PWM没有,所以把两个函数删成void放在后面了
#include "lcd.h"
#include "stdlib.h"
#include "font.h"
#include "usart.h"
#include "delay.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//全动电子3.97寸LCD模块驱动程序,芯片OTM8009A
//显示分辨率800*480
//改动正点原子lcd.c的源代码,删除了扫描方向函数和背光亮度控制函数
//////////////////////////////////////////////////////////////////////////////////
//LCD的画笔颜 {MOD}和背景 {MOD}
u16 POINT_COLOR=0x0000; //画笔颜 {MOD}
u16 BACK_COLOR=0xFFFF; //背景 {MOD}
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;
//写寄存器函数
//regval:寄存器值
void LCD_WR_REG(u16 regval)
{
LCD->LCD_REG=regval;//写入要写的寄存器序号
}
//写LCD数据
//data:要写入的值
void LCD_WR_DATA(u16 data)
{
LCD->LCD_RAM=data;
}
//读LCD数据
//返回值:读到的值
u16 LCD_RD_DATA(void)
{
vu16 ram; //防止被优化
ram=LCD->LCD_RAM;
return ram;
}
//写寄存器
//LCD_Reg:寄存器地址
//LCD_RegValue:要写入的数据
void LCD_WriteReg(u16 LCD_Reg,u16 LCD_RegValue)
{
LCD->LCD_REG = LCD_Reg; //写入要写的寄存器序号
LCD->LCD_RAM = LCD_RegValue;//写入数据
}
//读寄存器
//LCD_Reg:寄存器地址
//返回值:读到的数据
u16 LCD_ReadReg(u16 LCD_Reg)
{
LCD_WR_REG(LCD_Reg); //写入要读的寄存器序号
delay_us(5);
return LCD_RD_DATA(); //返回读到的值
}
//开始写GRAM
void LCD_WriteRAM_Prepare(void)
{
LCD->LCD_REG=lcddev.wramcmd;
}
//LCD写GRAM
//RGB_Code:颜 {MOD}值
void LCD_WriteRAM(u16 RGB_Code)
{
LCD->LCD_RAM = RGB_Code;//写十六位GRAM
}
//LCD开启显示
void LCD_DisplayOff(void)
{
LCD_WR_REG(0x2800); //开启显示
}
//LCD关闭显示
void LCD_DisplayOn(void)
{
LCD_WR_REG(0x2900); //开启显示
}
//初始化lcd
void LCD_Init(void)
{
RCC->AHBENR|=1<<8; //使能FSMC时钟
RCC->APB2ENR|=1<<3; //使能PORTB时钟
RCC->APB2ENR|=1<<5; //使能PORTD时钟
RCC->APB2ENR|=1<<6; //使能PORTE时钟
RCC->APB2ENR|=1<<8; //使能PORTG时钟
GPIOB->CRL&=0XFFFFFFF0; //PB0 推挽输出 背光
GPIOB->CRL|=0X00000003;
//PORTD复用推挽输出
GPIOD->CRH&=0X00FFF000;
GPIOD->CRH|=0XBB000BBB;
GPIOD->CRL&=0XFF00FF00;
GPIOD->CRL|=0X00BB00BB;
//PORTE复用推挽输出
GPIOE->CRH&=0X00000000;
GPIOE->CRH|=0XBBBBBBBB;
GPIOE->CRL&=0X0FFFFFFF;
GPIOE->CRL|=0XB0000000;
//PORTG12复用推挽输出
GPIOG->CRH&=0XFFF0FFFF;
GPIOG->CRH|=0X000B0000;
GPIOG->CRL&=0XFFFFFFF0;//PG0->RS
GPIOG->CRL|=0X0000000B;
//寄存器清零
//bank1有NE1~4,每一个有一个BCR+TCR,所以总共八个寄存器。
//这里我们使用NE4 ,也就对应BTCR[6],[7]。
FSMC_Bank1->BTCR[6]=0X00000000;
FSMC_Bank1->BTCR[7]=0X00000000;
FSMC_Bank1E->BWTR[6]=0X00000000;
//操作BCR寄存器 使用异步模式
FSMC_Bank1->BTCR[6]|=1<<12; //存储器写使能
FSMC_Bank1->BTCR[6]|=1<<14; //读写使用不同的时序
FSMC_Bank1->BTCR[6]|=1<<4; //存储器数据宽度为16bit
//操作BTR寄存器
//读时序控制寄存器
FSMC_Bank1->BTCR[7]|=0<<28; //模式A
FSMC_Bank1->BTCR[7]|=1<<0; //地址建立时间(ADDSET)为2个HCLK 1/36M=27ns(实际>200ns)
//因为液晶驱动IC的读数据的时候,速度不能太快,尤其对1289这个IC。
FSMC_Bank1->BTCR[7]|=0XF<<8; //数据保存时间为16个HCLK
//写时序控制寄存器
FSMC_Bank1E->BWTR[6]|=0<<28; //模式A
FSMC_Bank1E->BWTR[6]|=0<<0; //地址建立时间(ADDSET)为1个HCLK
//4个HCLK(HCLK=72M)因为液晶驱动IC的写信号脉宽,最少也得50ns。72M/4=24M=55ns
FSMC_Bank1E->BWTR[6]|=3<<8; //数据保存时间为4个HCLK
//使能BANK1,区域4
FSMC_Bank1->BTCR[6]|=1<<0; //使能BANK1,区域4
delay_ms(50); // delay 50 ms
LCD_WR_REG(0xff00); LCD_WR_DATA(0x80); //enable access command2
LCD_WR_REG(0xff01); LCD_WR_DATA(0x09); //enable access command2
LCD_WR_REG(0xff02); LCD_WR_DATA(0x01); //enable access command2
LCD_WR_REG(0xff80); LCD_WR_DATA(0x80); //enable access command2
LCD_WR_REG(0xff81); LCD_WR_DATA(0x09); //enable access command2
LCD_WR_REG(0xff03); LCD_WR_DATA(0x01); //
LCD_WR_REG(0xc5b1); LCD_WR_DATA(0xA9); //power control
LCD_WR_REG(0xc591); LCD_WR_DATA(0x0F); //power control
LCD_WR_REG(0xc0B4); LCD_WR_DATA(0x50);
//panel driving mode : column inversion
////// gamma
LCD_WR_REG(0xE100); LCD_WR_DATA(0x00);
LCD_WR_REG(0xE101); LCD_WR_DATA(0x09);
LCD_WR_REG(0xE102); LCD_WR_DATA(0x0F);
LCD_WR_REG(0xE103); LCD_WR_DATA(0x0E);
LCD_WR_REG(0xE104); LCD_WR_DATA(0x07);
LCD_WR_REG(0xE105); LCD_WR_DATA(0x10);
LCD_WR_REG(0xE106); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xE107); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xE108); LCD_WR_DATA(0x04);
LCD_WR_REG(0xE109); LCD_WR_DATA(0x07);
LCD_WR_REG(0xE10A); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xE10B); LCD_WR_DATA(0x08);
LCD_WR_REG(0xE10C); LCD_WR_DATA(0x0F);
LCD_WR_REG(0xE10D); LCD_WR_DATA(0x10);
LCD_WR_REG(0xE10E); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xE10F); LCD_WR_DATA(0x01);
LCD_WR_REG(0xE200); LCD_WR_DATA(0x00);
LCD_WR_REG(0xE201); LCD_WR_DATA(0x09);
LCD_WR_REG(0xE202); LCD_WR_DATA(0x0F);
LCD_WR_REG(0xE203); LCD_WR_DATA(0x0E);
LCD_WR_REG(0xE204); LCD_WR_DATA(0x07);
LCD_WR_REG(0xE205); LCD_WR_DATA(0x10);
LCD_WR_REG(0xE206); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xE207); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xE208); LCD_WR_DATA(0x04);
LCD_WR_REG(0xE209); LCD_WR_DATA(0x07);
LCD_WR_REG(0xE20A); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xE20B); LCD_WR_DATA(0x08);
LCD_WR_REG(0xE20C); LCD_WR_DATA(0x0F);
LCD_WR_REG(0xE20D); LCD_WR_DATA(0x10);
LCD_WR_REG(0xE20E); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xE20F); LCD_WR_DATA(0x01);
LCD_WR_REG(0xD900); LCD_WR_DATA(0x4E); //vcom setting
LCD_WR_REG(0xc181); LCD_WR_DATA(0x66); //osc=65HZ
LCD_WR_REG(0xc1a1); LCD_WR_DATA(0x08);
LCD_WR_REG(0xc592); LCD_WR_DATA(0x01); //power control
LCD_WR_REG(0xc595); LCD_WR_DATA(0x34); //power control
LCD_WR_REG(0xd800); LCD_WR_DATA(0x79); //GVDD / NGVDD setting
LCD_WR_REG(0xd801); LCD_WR_DATA(0x79); //GVDD / NGVDD setting
LCD_WR_REG(0xc594); LCD_WR_DATA(0x33); //power control
LCD_WR_REG(0xc0a3); LCD_WR_DATA(0x1B); //panel timing setting
LCD_WR_REG(0xc582); LCD_WR_DATA(0x83); //power control
LCD_WR_REG(0xc481); LCD_WR_DATA(0x83); //source driver setting
LCD_WR_REG(0xc1a1); LCD_WR_DATA(0x0E);
LCD_WR_REG(0xb3a6); LCD_WR_DATA(0x20);
LCD_WR_REG(0xb3a7); LCD_WR_DATA(0x01);
LCD_WR_REG(0xce80); LCD_WR_DATA(0x85); // GOA VST
LCD_WR_REG(0xce81); LCD_WR_DATA(0x01); // GOA VST
LCD_WR_REG(0xce82); LCD_WR_DATA(0x00); // GOA VST
LCD_WR_REG(0xce83); LCD_WR_DATA(0x84); // GOA VST
LCD_WR_REG(0xce84); LCD_WR_DATA(0x01); // GOA VST
LCD_WR_REG(0xce85); LCD_WR_DATA(0x00); // GOA VST
LCD_WR_REG(0xcea0); LCD_WR_DATA(0x18); // GOA CLK
LCD_WR_REG(0xcea1); LCD_WR_DATA(0x04); // GOA CLK
LCD_WR_REG(0xcea2); LCD_WR_DATA(0x03); // GOA CLK
LCD_WR_REG(0xcea3); LCD_WR_DATA(0x39); // GOA CLK
LCD_WR_REG(0xcea4); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcea5); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcea6); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcea7); LCD_WR_DATA(0x18); // GOA CLK
LCD_WR_REG(0xcea8); LCD_WR_DATA(0x03); // GOA CLK
LCD_WR_REG(0xcea9); LCD_WR_DATA(0x03); // GOA CLK
LCD_WR_REG(0xceaa); LCD_WR_DATA(0x3a); // GOA CLK
LCD_WR_REG(0xceab); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xceac); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcead); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xceb0); LCD_WR_DATA(0x18); // GOA CLK
LCD_WR_REG(0xceb1); LCD_WR_DATA(0x02); // GOA CLK
LCD_WR_REG(0xceb2); LCD_WR_DATA(0x03); // GOA CLK
LCD_WR_REG(0xceb3); LCD_WR_DATA(0x3b); // GOA CLK
LCD_WR_REG(0xceb4); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xceb5); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xceb6); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xceb7); LCD_WR_DATA(0x18); // GOA CLK
LCD_WR_REG(0xceb8); LCD_WR_DATA(0x01); // GOA CLK
LCD_WR_REG(0xceb9); LCD_WR_DATA(0x03); // GOA CLK
LCD_WR_REG(0xceba); LCD_WR_DATA(0x3c); // GOA CLK
LCD_WR_REG(0xcebb); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcebc); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcebd); LCD_WR_DATA(0x00); // GOA CLK
LCD_WR_REG(0xcfc0); LCD_WR_DATA(0x01); // GOA ECLK
LCD_WR_REG(0xcfc1); LCD_WR_DATA(0x01); // GOA ECLK
LCD_WR_REG(0xcfc2); LCD_WR_DATA(0x20); // GOA ECLK
LCD_WR_REG(0xcfc3); LCD_WR_DATA(0x20); // GOA ECLK
LCD_WR_REG(0xcfc4); LCD_WR_DATA(0x00); // GOA ECLK
LCD_WR_REG(0xcfc5); LCD_WR_DATA(0x00); // GOA ECLK
LCD_WR_REG(0xcfc6); LCD_WR_DATA(0x01); // GOA other options
LCD_WR_REG(0xcfc7); LCD_WR_DATA(0x00);
// GOA signal toggle option setting
LCD_WR_REG(0xcfc8); LCD_WR_DATA(0x00); //GOA signal toggle option setting
LCD_WR_REG(0xcfc9); LCD_WR_DATA(0x00);
//GOA signal toggle option setting
LCD_WR_REG(0xcfd0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb80); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb81); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb82); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb83); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb84); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb85); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb86); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb87); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb88); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb89); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb90); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb91); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb92); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb93); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb94); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb95); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb96); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb97); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb98); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb99); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb9a); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb9b); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb9c); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb9d); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcb9e); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcba9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbaa); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbab); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbac); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbad); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbae); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbb9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbc0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbc1); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbc2); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbc3); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbc4); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbc5); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbc6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbc7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbc8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbc9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbca); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbcb); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbcc); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbcd); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbce); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbd6); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbd7); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbd8); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbd9); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbda); LCD_WR_DATA(0x04);
LCD_WR_REG(0xcbdb); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbdc); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbdd); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbde); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbe9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcbf0); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf1); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf2); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf3); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf4); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf5); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf6); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf7); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf8); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcbf9); LCD_WR_DATA(0xFF);
LCD_WR_REG(0xcc80); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc81); LCD_WR_DATA(0x26);
LCD_WR_REG(0xcc82); LCD_WR_DATA(0x09);
LCD_WR_REG(0xcc83); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xcc84); LCD_WR_DATA(0x01);
LCD_WR_REG(0xcc85); LCD_WR_DATA(0x25);
LCD_WR_REG(0xcc86); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc87); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc88); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc89); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc90); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc91); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc92); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc93); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc94); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc95); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc96); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc97); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc98); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc99); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc9a); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcc9b); LCD_WR_DATA(0x26);
LCD_WR_REG(0xcc9c); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xcc9d); LCD_WR_DATA(0x0C);
LCD_WR_REG(0xcc9e); LCD_WR_DATA(0x02);
LCD_WR_REG(0xcca0); LCD_WR_DATA(0x25);
LCD_WR_REG(0xcca1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcca9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccaa); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccab); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccac); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccad); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccae); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccb0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccb1); LCD_WR_DATA(0x25);
LCD_WR_REG(0xccb2); LCD_WR_DATA(0x0C);
LCD_WR_REG(0xccb3); LCD_WR_DATA(0x0A);
LCD_WR_REG(0xccb4); LCD_WR_DATA(0x02);
LCD_WR_REG(0xccb5); LCD_WR_DATA(0x26);
LCD_WR_REG(0xccb6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccb7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccb8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccb9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc0); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccc9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccca); LCD_WR_DATA(0x00);
LCD_WR_REG(0xcccb); LCD_WR_DATA(0x25);
LCD_WR_REG(0xcccc); LCD_WR_DATA(0x0B);
LCD_WR_REG(0xcccd); LCD_WR_DATA(0x09);
LCD_WR_REG(0xccce); LCD_WR_DATA(0x01);
LCD_WR_REG(0xccd0); LCD_WR_DATA(0x26);
LCD_WR_REG(0xccd1); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd2); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd3); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd4); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd5); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd6); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd7); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd8); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccd9); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccda); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccdb); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccdc); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccdd); LCD_WR_DATA(0x00);
LCD_WR_REG(0xccde); LCD_WR_DATA(0x00);
LCD_WR_REG(0x3A00); LCD_WR_DATA(0x55);
LCD_WR_REG(0x1100);
delay_ms(100);
LCD_WR_REG(0x2900);
delay_ms(50);
LCD_WR_REG(0x2C00);
LCD_WR_REG(0x2A00); LCD_WR_DATA(0x00);
LCD_WR_REG(0x2A01); LCD_WR_DATA(0x00);
LCD_WR_REG(0x2A02); LCD_WR_DATA(0x01);
LCD_WR_REG(0x2A03); LCD_WR_DATA(0xe0);
LCD_WR_REG(0x2B00); LCD_WR_DATA(0x00);
LCD_WR_REG(0x2B01); LCD_WR_DATA(0x00);
LCD_WR_REG(0x2B02); LCD_WR_DATA(0x03);
LCD_WR_REG(0x2B03); LCD_WR_DATA(0x20);
lcddev.wramcmd=0x2c00;
lcddev.dir=0;//竖屏
lcddev.width=480;
lcddev.height=800;
LCD_WriteReg(0x3600,0x00);
LCD_Clear(WHITE);
LCD_LED=1; //点亮背光
}
//当mdk -O1时间优化时需要设置
//延时i
void opt_delay(u8 i)
{
while(i--);
}
//读取个某点的颜 {MOD}值
//x,y:坐标
//返回值:此点的颜 {MOD}
u16 LCD_ReadPoint(u16 x,u16 y)
{
u16 r=0,g=0,b=0;
if(x>=lcddev.width||y>=lcddev.height)return 0; //超过了范围,直接返回
LCD_SetCursor(x,y);
LCD_WR_REG(0x2E00);//9341/6804/3510/1963 发送读GRAM指令LCD_WR_REG(0X2E00); //5510 发送读GRAM指令
opt_delay(2);
r=LCD_RD_DATA();
g=r&0XFF; //对于9341/5310/5510,第一次读取的是RG的值,R在前,G在后,各占8位
g<<=8;
return r; //这几种IC直接返回颜 {MOD}值
}
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{
LCD_WR_REG(0x2A00);
LCD_WR_DATA(Xpos>>8);
LCD_WR_REG(0x2A01);
LCD_WR_DATA(Xpos&0xFF);
LCD_WR_REG(0x2A02);
LCD_WR_DATA(Xpos>>8);
LCD_WR_REG(0x2A03);
LCD_WR_DATA(Xpos&0xFF);
LCD_WR_REG(0x2B00);
LCD_WR_DATA(Ypos>>8);
LCD_WR_REG(0x2B01);
LCD_WR_DATA(Ypos&0xFF);
LCD_WR_REG(0x2B02);
LCD_WR_DATA(Ypos>>8);
LCD_WR_REG(0x2B03);
LCD_WR_DATA(Ypos&0xFF);
LCD->LCD_REG=lcddev.wramcmd;
}
//画点
//x,y:坐标
//POINT_COLOR:此点的颜 {MOD}
void LCD_DrawPoint(u16 x,u16 y)
{
LCD_SetCursor(x,y); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
LCD->LCD_RAM=POINT_COLOR;
}
//快速画点
//x,y:坐标
//color:颜 {MOD}
void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color)
{
LCD_WR_REG(0x2A00);
LCD_WR_DATA(x>>8);
LCD_WR_REG(0x2A01);
LCD_WR_DATA(x&0xFF);
LCD_WR_REG(0x2A02);
LCD_WR_DATA(x>>8);
LCD_WR_REG(0x2A03);
LCD_WR_DATA(x&0xFF);
LCD_WR_REG(0x2B00);
LCD_WR_DATA(y>>8);
LCD_WR_REG(0x2B01);
LCD_WR_DATA(y&0xFF);
LCD_WR_REG(0x2B02);
LCD_WR_DATA(y>>8);
LCD_WR_REG(0x2B03);
LCD_WR_DATA(y&0xFF);
LCD->LCD_REG=lcddev.wramcmd;
LCD->LCD_RAM=color;
}
//设置窗口,并自动设置画点坐标到窗口左上角(sx,sy).
//sx,sy:窗口起始坐标(左上角)
//width,height:窗口宽度和高度,必须大于0!!
//窗体大小:width*height.
void LCD_Set_Window(u16 sx,u16 sy,u16 ex,u16 ey)
{
LCD_WR_REG(0x2A00);
LCD_WR_DATA(sx>>8);
LCD_WR_REG(0x2A01);
LCD_WR_DATA(sx&0xFF);
LCD_WR_REG(0x2A02);
LCD_WR_DATA(ex>>8);
LCD_WR_REG(0x2A03);
LCD_WR_DATA(ex&0xFF);
LCD_WR_REG(0x2B00);
LCD_WR_DATA(sy>>8);
LCD_WR_REG(0x2B01);
LCD_WR_DATA(sy&0xFF);
LCD_WR_REG(0x2B02);
LCD_WR_DATA(ey>>8);
LCD_WR_REG(0x2B03);
LCD_WR_DATA(ey&0xFF);
LCD_WriteRAM_Prepare(); //开始写入GRAM
}
//清屏函数
//color:要清屏的填充 {MOD}
void LCD_Clear(u16 color)
{
u32 index=0;
LCD_Set_Window(0,0,479,799);
for(index=0;index<480*800;index++)
{
LCD->LCD_RAM=color;
}
}
//在指定区域内填充单个颜 {MOD}
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为
ex-sx+1)*(ey-sy+1)
//color:要填充的颜 {MOD}
void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color)
{
u32 i;
u16 width=ex-sx+1; //得到填充的宽度
u16 height=ey-sy+1; //高度
u32 totalpoint=height*width;
LCD_Set_Window(sx,sy,ex-1,ey-1);//设置显示窗口
for(i=0;i<totalpoint;i++)
{
LCD->LCD_RAM=color; //写入数据
}
LCD_Set_Window(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口设置为全屏
}
void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color)
{
u16 height,width;
u16 i,j;
width=ex-sx+1; //得到填充的宽度
height=ey-sy+1; //高度
for(i=0;i<height;i++)
{
LCD_SetCursor(sx,sy+i); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(j=0;j<width;j++)LCD->LCD_RAM=color[i*width+j];//写入数据
}
}
//画线
//x1,y1:起点坐标
//x2,y2:终点坐标
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
{
u16 t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; //设置单步方向
else if(delta_x==0)incx=0;//垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;//水平线
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++ )//画线输出
{
LCD_DrawPoint(uRow,uCol);//画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
//画矩形
//(x1,y1),(x2,y2):矩形的对角坐标
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
{
LCD_DrawLine(x1,y1,x2,y1);
LCD_DrawLine(x1,y1,x1,y2);
LCD_DrawLine(x1,y2,x2,y2);
LCD_DrawLine(x2,y1,x2,y2);
}
//在指定位置画一个指定大小的圆
//(x,y):中心点
//r :半径
void LCD_Draw_Circle(u16 x0,u16 y0,u8 r)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1); //判断下个点位置的标志
while(a<=b)
{
LCD_DrawPoint(x0+a,y0-b); //5
LCD_DrawPoint(x0+b,y0-a); //0
LCD_DrawPoint(x0+b,y0+a); //4
LCD_DrawPoint(x0+a,y0+b); //6
LCD_DrawPoint(x0-a,y0+b); //1
LCD_DrawPoint(x0-b,y0+a);
LCD_DrawPoint(x0-a,y0-b); //2
LCD_DrawPoint(x0-b,y0-a); //7
a++;
//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
}
}
//在指定位置显示一个字符
//x,y:起始坐标
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16/24
//mode:叠加方式(1)还是非叠加方式(0)
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode)
{
u8 temp,t1,t;
u16 y0=y;
u8 csize=(size/8+((size%8)?1:0))*(size/2); //得到字体一个字符对应点阵集所占的字节数
num=num-' ';//得到偏移后的值(ASCII字库是从空格开始取模,所以-' '就是对应字符的字库)
for(t=0;t<csize;t++)
{
if(size==12)temp=asc2_1206[num][t]; //调用1206字体
else if(size==16)temp=asc2_1608[num][t]; //调用1608字体
else if(size==24)temp=asc2_2412[num][t]; //调用2412字体
else return; //没有的字库
for(t1=0;t1<8;t1++)
{
if(temp&0x80)LCD_Fast_DrawPoint(x,y,POINT_COLOR);
else if(mode==0)LCD_Fast_DrawPoint(x,y,BACK_COLOR);
temp<<=1;
y++;
if(y>=lcddev.height)return; //超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=lcddev.width)return; //超区域了
break;
}
}
}
}
//m^n函数
//返回值:m^n次方.
u32 LCD_Pow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
//显示数字,高位为0,则不显示
//x,y :起点坐标
//len :数字的位数
//size:字体大小
//color:颜 {MOD}
//num:数值(0~4294967295);
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
LCD_ShowChar(x+(size/2)*t,y,' ',size,0);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,0);
}
}
//显示数字,高位为0,还是显示
//x,y:起点坐标
//num:数值(0~999999999);
//len:长度(即要显示的位数)
//size:字体大小
//mode:
//[7]:0,不填充;1,填充0.
//[6:1]:保留
//[0]:0,非叠加显示;1,叠加显示.
void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
if(mode&0X80)LCD_ShowChar(x+(size/2)*t,y,'0',size,mode&0X01);
else LCD_ShowChar(x+(size/2)*t,y,' ',size,mode&0X01);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,mode&0X01);
}
}
//显示字符串
//x,y:起点坐标
//width,height:区域大小
//size:字体大小
//*p:字符串起始地址
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)
{
u8 x0=x;
width+=x;
height+=y;
while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
{
if(x>=width){x=x0;y+=size;}
if(y>=height)break;//退出
LCD_ShowChar(x,y,*p,size,0);
x+=size/2;
p++;
}
}
void LCD_Scan_Dir(u8 dir)
{
}
void LCD_SSD_BackLightSet(u8 pwm)
{
}
一周热门 更多>