使用SC95F8617驱动16位总线LCD显示屏,刷屏显示红、绿、蓝三色。
一、电路图
使用SC95F8617的P3口+74LVC16245+74HC573扩展成16位总线的方式。电路如下:
二、程序
2.1、main.c
#include "config.h"
void main(void)
{
uint i=0;
Init_led();
Init_lcd();
LCD_Fill(0,0,LCD_X,LCD_Y,RED);
while(1)
{
LED0=0;
LED1=1;
LED2=0;
LED3=1;
//LCD_BK=0;
LCD_Fill(0,0,LCD_X,LCD_Y,GREEN);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
LCD_Fill(0,0,LCD_X,LCD_Y,BLUE);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
LCD_Fill(0,0,LCD_X,LCD_Y,RED);
LED0=1;
LED1=0;
LED2=1;
LED3=0;
//LCD_BK=1;
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
for(i=0;i<50000;i++);for(i=0;i<50000;i++);
}
}
2.2、lcd.c
#include "config.h"
void delay(uint ds)
{
uint dsi,dsj;
for(dsj=0;dsj<ds;dsj++)
{
for(dsi=0;dsi<200;dsi++);
}
}
static void lcd_Reset(void)
{
LCD_RST=1;
delay(1);
LCD_RST=0;
delay(500);
LCD_RST=1;
delay(500);
}
void lcd_sendat(uint16_t dat)
{
uchar i;
LCD_DIR=1; //A->B
LCD_EN=0; //2A->2B
P3=dat; //D7..D0;
LCD_LE=1;
for(i=0;i<10;i++);
LCD_LE=0;
P3=dat>>8; //D7..D0;
}
void LCD_WR_CMD(uint16_t LCD_Reg)
{
LCD_CS=0; //cs=0
LCD_RS=0; //rs=0
LCD_RD=1; //rd=1
LCD_WR=0; //wr=0
lcd_sendat(LCD_Reg);
//GPIO_Write(GPIOE, LCD_Reg);
LCD_WR=1; //wr=1
LCD_CS=1; //cs=1
LCD_RS=1; //rs=1
}
void LCD_WR_DATA(uint16_t LCD_Data)
{
LCD_RS=1; //rs=1
LCD_CS=0; //cs=0
LCD_RD=1; //rd=1
LCD_WR=0; //wr=0
lcd_sendat(LCD_Data);
LCD_WR=1; //wr=1
LCD_CS=1; //cs=1
}
void LCD_WriteReg(uint16_t reg,uint16_t val)
{
LCD_WR_CMD(reg);
LCD_WR_DATA(val);
}
void Init_lcd(void)
{
P4CON |= 0xff;
P3CON |= 0xff;
P5CON |= 0x20; //0010 0000
LCD_BK=1;
lcd_Reset();
LCD_WriteReg(0x0000,0x0001);
delay(10);
LCD_WriteReg(0x00A4,0x0001);
delay(10);
LCD_WriteReg(0x0070,0x9B00);
delay(10);
LCD_WriteReg(0x0007,0x0031);
delay(10);
//power supply setting
LCD_WriteReg(0x0018,0x0001);
delay(5);
LCD_WriteReg(0x0010,0x16B0);
delay(5);
LCD_WriteReg(0x0011,0x0200);
delay(5);
LCD_WriteReg(0x0012,0x1118);
delay(5);
LCD_WriteReg(0x0013,0x880F);
delay(5);
LCD_WriteReg(0x0014,0x0000);
delay(5);
LCD_WriteReg(0x0012,0x1138);
delay(5);
LCD_WriteReg(0x0090,0x0004);
LCD_WriteReg(0x0091,0x0000);
LCD_WriteReg(0x0092,0x0007);
LCD_WriteReg(0x0098,0x0002);
//display contral
LCD_WriteReg(0x0001,0x0100);
LCD_WriteReg(0x0002,0x0400);
LCD_WriteReg(0x0003,0x1030);
LCD_WriteReg(0x0008,0x0708);
LCD_WriteReg(0x0070,0x1B00);
LCD_WriteReg(0x0071,0x0001);
//gamma contral
LCD_WriteReg(0x0030,0x0305);
LCD_WriteReg(0x0031,0x0005);
LCD_WriteReg(0x0032,0x0000);
LCD_WriteReg(0x0033,0x0003);
LCD_WriteReg(0x0034,0x0900);
LCD_WriteReg(0x0035,0x0607);
LCD_WriteReg(0x0036,0x0307);
LCD_WriteReg(0x0037,0x0305);
LCD_WriteReg(0x0038,0x1305);
LCD_WriteReg(0x0039,0x1C00);
LCD_WriteReg(0x003A,0x1500);
//panel interface
LCD_WriteReg(0x0020,0x0000);
LCD_WriteReg(0x0021,0x0000);
//address set
LCD_WriteReg(0x0050,0x0000);
LCD_WriteReg(0x0051,LCD_X);
LCD_WriteReg(0x0052,0x0000);
LCD_WriteReg(0x0053,LCD_Y);//176*220
//display on
delay(5);
LCD_WriteReg(0x0007,0x0001);
delay(10);
LCD_WriteReg(0x0007,0x0021);
delay(10);
LCD_WriteReg(0x0007,0x0233);
}
void LCD_SetPos(uint16_t x,uint16_t y)
{
LCD_WriteReg(0x0020, x & 0xFF);
LCD_WriteReg(0x0021, y & 0x1FF);
LCD_WR_CMD(0x0022);//?GRAM
}
void LCD_Fill(uint16_t x,uint16_t y,uint16_t x_len,uint16_t y_len,uint16_t Color)
{
uint16_t i,j;
for(i = y;i < y+y_len;i ++)
{
j = x;
LCD_SetPos(j,i);
for(;j < x+x_len;j ++)
{
LCD_WR_DATA(Color);
}
}
}
2.3、lcd.h
#ifndef _LCD_H_
#define _LCD_H_
#include "mytype.h"
sbit LCD_BK = P4^0;
sbit LCD_RST = P4^1;
sbit LCD_RD = P4^2;
sbit LCD_WR = P4^3;
sbit LCD_RS = P4^4;
sbit LCD_CS = P4^5;
sbit LCD_EN = P4^6;
sbit LCD_DIR = P4^7;
sbit LCD_LE = P5^5;
#define LCD_X 176
#define LCD_Y 220
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define BACKCOLOR 0xFFFF
#define WORDCOLOR 0x0000
void Init_lcd(void);
void LCD_Fill(uint16_t x,uint16_t y,uint16_t x_len,uint16_t y_len,uint16_t Color);
#endif
三、运行结果
|
|