微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > TFT液晶屏C51控制

TFT液晶屏C51控制

时间:11-18 来源:互联网 点击:
最近事情比较忙,但是最近好像习惯了在自己博客上发些资料,可以以后自己参考下,也可以供别人参考。上次玩了2.8寸的TFT液晶,这几天有点时间了,用51控制了下2.4寸的TFT液晶,驱动是一样的。写了下程序,放网上。

/*功能描述:TFT(ILI9325)液晶测试程序 */
/*作者:ClimberWin */
/*编写时间:2010.3.8 */
/*功能:TFT液晶显示图片和打印字符 */
/*STC89C58RD 接外部晶振11.0592 MHZ */
/**************************************************/

#include
#include"ILI9325.H"
main()
{
uchar i;
LCD_INIT(); //TFT初始化
LCD_picture_diplay();
LCD_write_english_string(20,20,"TFT C51 Test

OK",GREEN,BLACK);
LCD_write_english_string(20,40,"ClimberWin

2010.3.8",GREEN,BLACK);

for(i=0;i<10;i++)
{
LCD_caitiao_diplay(100,RED);
LCD_caitiao_diplay(120,GREEN);
LCD_caitiao_diplay(140,BLUE);
LCD_caitiao_diplay(160,YELLOW);
LCD_caitiao_diplay(180,WHITE);
LCD_caitiao_diplay(200,MAGENTA);
LCD_caitiao_diplay(220,CYAN);

LCD_caitiao_diplay(100,CYAN);
LCD_caitiao_diplay(120,RED);
LCD_caitiao_diplay(140,GREEN);
LCD_caitiao_diplay(160,BLUE);
LCD_caitiao_diplay(180,YELLOW);
LCD_caitiao_diplay(200,WHITE);
LCD_caitiao_diplay(220,MAGENTA);
}
while(1);

}

///////////////////////////////////////////////头文件定义//////////////////////////////////////////////////

#ifndef_ILI9325_H_
#define_ILI9325_H_

#include
#include"picture.h"
#include"english_16x8.h"

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

#defineBLACK0x0000 //黑
#defineBLUE0x001F //蓝
#defineRED 0xF800 //红
#defineGREEN 0x07E0 //绿
#define CYAN0x07FF //青
#define MAGENTA 0xF81F //洋红
#define YELLOW0xFFE0 //黄
#define WHITE0xFFFF //白

#define LCD_DATA_PORT P0 //定义数据口 D8-D15
sbit LCD_RS = P2^0; //数据/命令切换
sbit LCD_RST = P2^7; //复位
sbit LCD_WR = P2^1; //写控制
sbit LCD_RD =P2^2; //读控制
sbit LCD_CS=P2^5;
void delayms(uint count);
void LCD_Write_REG(uint lcd_reg); //8位数据接口发送16位寄存器地址
void LCD_Write_DATA(uint lcd_data);//8位数据接口发送16位数据
void LCD_Write_REG_DATA( uint lcd_reg,lcd_data); //设置寄存器和数据
void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2);//设置坐标
void LCD_INIT(void);//液晶初始化
void LCD_picture_diplay(void);//显示图片
void LCD_write_english(unsigned char data1,unsigned int color,unsigned int xcolor);//写字符
void LCD_write_english_string(unsigned int x,unsigned int y,unsigned char *s,unsigned int color,unsigned int xcolor);//英文字符串显示
void Lcd_SetBox(unsigned int xStart,unsigned int yStart,unsigned int xLong,unsigned int yLong);
void LCD_SetCursor(unsigned int Xpos, unsigned int Ypos);
void LCD_Clear(unsigned int Color);
void LCD_caitiao_diplay(uchar x,uint color);//画彩条 20点宽 320点长

void delayms(uint count)
{
unsigned int i,j;
for(i=0;ifor(j=0;j<120;j++);
}

void LCD_Write_REG( uint lcd_reg) //8位数据接口发送16位寄存器地址
{
LCD_RS=0;
LCD_CS =0;
LCD_DATA_PORT=lcd_reg>>8;
LCD_WR=0;
LCD_WR=1;
LCD_DATA_PORT=lcd_reg&0XFF;
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}

void LCD_Write_DATA(uint lcd_data)//8位数据接口发送16位数据
{
LCD_RS=1;
LCD_CS =0;
LCD_DATA_PORT=lcd_data>>8;
LCD_WR=0;
LCD_WR=1;
LCD_DATA_PORT=lcd_data&0XFF;
LCD_WR=0;
LCD_WR=1;
LCD_CS =1;
}

void LCD_Write_REG_DATA( uint lcd_reg,lcd_data)
{
LCD_Write_REG(lcd_reg);
LCD_Write_DATA(lcd_data);
}

void LCD_Add_Set(uint x1,uint y1,uint x2,uint y2)
{
LCD_Write_REG_DATA(0x0020,x1); //设置X坐标位置
LCD_Write_REG_DATA(0x0021,y1); //设置Y坐标位置
LCD_Write_REG_DATA(0x0050,x1); //开始X
LCD_Write_REG_DATA(0x0052,y1);//开始Y
LCD_Write_REG_DATA(0x0051,x2); //结束X
LCD_Write_REG_DATA(0x0053,y2); //结束Y
LCD_Write_REG(0x0022);
}

///////////液晶初始化程序////////////////////
void LCD_INIT(void)
{

LCD_RST=1;
delayms(5);
LCD_RST=0;
delayms(10);
LCD_RST=1;
delayms(20);
//************* Start Initial Sequence **********//
LCD_Write_REG(0x00E5); LCD_Write_DATA(0x78F0); // set SRAM internal timing

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top