ILI9341的单片机仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
给各位做了参考.ILI9341 8位模式,16位色
ILI9341单片机源程序如下:
- //#include <REGX52.H>
- #include <REGX55.H>
- #include <intrins.h>
- #include "map.h"
- //#define RED 0XF800 //红色
- //#define GREEN 0X07E0 //绿色
- //#define BLUE 0X001F //蓝色
- //#define WHITE 0XF785 //白色
- #define DATA_H P2
- #define DATA_L P1
- sbit LCD_CS = P3^1;
- sbit LCD_RS = P3^2;
- sbit LCD_WR = P3^3;
- sbit LCD_RD = P3^4;
- sbit LCD_RESET = P3^0;
- void Delay1ms() //@12.000MHz
- {
- unsigned char i, j;
- i = 12;
- j = 169;
- do
- {
- while (--j);
- } while (--i);
- }
- void delay_ms(unsigned int ms)
- {
- while(ms--)
- {
- Delay1ms();
- }
- }
- void LCD_WR_DATA(unsigned char val)
- {
- LCD_RS=1; //RS=1;
- LCD_CS=0; //CS=0;
- DATA_L=val;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- void LCD_WR_REG(unsigned char reg)
- {
- LCD_RS=0; //RS=0;
- LCD_CS=0; //CS=0;
- DATA_L=reg;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- void LCD_Init()
- {
- LCD_RESET=0;
- delay_ms(10);
- LCD_RESET=1;
- delay_ms(120);
- LCD_WR_REG(0xCF);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0xC1);
- LCD_WR_DATA(0X30);
- LCD_WR_REG(0xED);
- LCD_WR_DATA(0x64);
- LCD_WR_DATA(0x03);
- LCD_WR_DATA(0X12);
- LCD_WR_DATA(0X81);
- LCD_WR_REG(0xE8);
- LCD_WR_DATA(0x85);
- LCD_WR_DATA(0x10);
- LCD_WR_DATA(0x7A);
- LCD_WR_REG(0xCB);
- LCD_WR_DATA(0x39);
- LCD_WR_DATA(0x2C);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x34);
- LCD_WR_DATA(0x02);
- LCD_WR_REG(0xF7);
- LCD_WR_DATA(0x20);
- LCD_WR_REG(0xEA);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x00);
- LCD_WR_REG(0xC0); //Power control //电源控制
- LCD_WR_DATA(0x1B); //VRH[5:0]
- LCD_WR_REG(0xC1); //Power control
- LCD_WR_DATA(0x01); //SAP[2:0];BT[3:0]
- LCD_WR_REG(0xC5); //VCM control
- LCD_WR_DATA(0x30); //3F
- LCD_WR_DATA(0x30); //3C
- LCD_WR_REG(0xC7); //VCM control2
- LCD_WR_DATA(0XB7);
- LCD_WR_REG(0x36); // Memory Access Control (存储器访问控制)
- LCD_WR_DATA(0x48);
- LCD_WR_REG(0x3A); //像素格式设置
- LCD_WR_DATA(0x55);
- LCD_WR_REG(0xB1);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x1A);
- LCD_WR_REG(0xB6); // Display Function Control
- LCD_WR_DATA(0x0A);
- LCD_WR_DATA(0xA2);
- LCD_WR_REG(0xF2); // 3Gamma Function Disable
- LCD_WR_DATA(0x00);
- LCD_WR_REG(0x26); //Gamma curve selected
- LCD_WR_DATA(0x01);
- LCD_WR_REG(0xE0); //Set Gamma
- LCD_WR_DATA(0x0F);
- LCD_WR_DATA(0x2A);
- LCD_WR_DATA(0x28);
- LCD_WR_DATA(0x08);
- LCD_WR_DATA(0x0E);
- LCD_WR_DATA(0x08);
- LCD_WR_DATA(0x54);
- LCD_WR_DATA(0XA9);
- LCD_WR_DATA(0x43);
- LCD_WR_DATA(0x0A);
- LCD_WR_DATA(0x0F);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x00);
- LCD_WR_REG(0XE1); //Set Gamma
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x15);
- LCD_WR_DATA(0x17);
- LCD_WR_DATA(0x07);
- LCD_WR_DATA(0x11);
- LCD_WR_DATA(0x06);
- LCD_WR_DATA(0x2B);
- LCD_WR_DATA(0x56);
- LCD_WR_DATA(0x3C);
- LCD_WR_DATA(0x05);
- LCD_WR_DATA(0x10);
- LCD_WR_DATA(0x0F);
- LCD_WR_DATA(0x3F);
- LCD_WR_DATA(0x3F);
- LCD_WR_DATA(0x0F);
- LCD_WR_REG(0x2B);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x01);
- LCD_WR_DATA(0x3f);
- LCD_WR_REG(0x2A); //列地址设定
- LCD_WR_DATA(0x00); //第一个参数
- LCD_WR_DATA(0x00); //第二参数
- LCD_WR_DATA(0x00); //第三参数
- LCD_WR_DATA(0xef); //第四参数
- LCD_WR_REG(0x11); //Exit Sleep
- delay_ms(120);
- LCD_WR_REG(0x29); //display on
- }
- void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy)
- {//分别四个参数来设置起使X,起使Y,结整X,结束Y
- LCD_WR_REG(0x2A); //列地址
- LCD_WR_DATA(stx>>8);
- LCD_WR_DATA(stx&0xff);
- LCD_WR_DATA(endx>>8);
- LCD_WR_DATA(endx&0xff);
- LCD_WR_REG(0x2B); //页地址
- LCD_WR_DATA(sty>>8);
- LCD_WR_DATA(sty&0xff);
- LCD_WR_DATA(endy>>8);
- LCD_WR_DATA(endy&0xff);
- }
- void LcdWirteColorData(unsigned int color)
- {
- // LCD_RS=1; //RS=1;
- // LCD_CS=0; //CS=0;
- // DATA_H=color>>8;
- // DATA_L=color;
- // LCD_WR=0; //WR=0;
- // LCD_WR=1; //WR=1;
- // LCD_CS=1; //CS=1;
-
- LCD_RS=1; //RS=1;
- LCD_CS=0; //CS=0;
- DATA_L=color>>8;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- DATA_L=color;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- //void LCD_Clear(unsigned int color)
- //{
- // unsigned int i,j;
- // LCD_SetArea(0,0,180,240); //设置行列起使与结束
- // LCD_WR_REG(0x2C); //写存储器
- // for(i=0;i<320;i++)
- // {
- // for(j=0;j<360;j++)
- // {
- // LcdWirteColorData(color);
- // }
- // }
- //}
- void main()
- { unsigned int i;
- unsigned int *image;
- image=(unsigned int*)gImage_map;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
ii1394for89c52.rar
(296.15 KB, 下载次数: 429)
|