📄 lcd.c
字号:
#include <stdio.h>
#include "config.h"
#define RST 0x00000400 /* P0.10*/
#define BUSY 0x00000800 /* P0.11 */
#define WWR 0x00001000 /* P0.12 */
#define RRD 0x00002000 /* P0.13 */
#define RS 0x00200000 /* P0.21*/
#define CS1 0x00400000 /* P0.22 */
#define LCD_IOCON 0x00603400 /* 定义LCD接口的I/O设置字 */
#define LCD_cmdReg (*((volatile unsigned short *) 0x83000002))
#define LCD_cmdData (*((volatile unsigned short *) 0x83000000))
#define LCD_DATA (*((volatile unsigned short *) 0x83000000))
/************************************************/
extern void delay (int i);
extern void LCD_CmdWrite(unsigned char,unsigned char);
extern unsigned char LCD_CmdRead(unsigned char);
extern void LCD_DataWrite(unsigned char);
extern void LCD_ChkBusy(void);
extern void LCD_Reset(void);
extern void LCD_Initial(void);
extern void LCD_Clearzf(void);
//extern void LCD_clear(void);
extern void LCD_all(void);
extern void LCD_row(void);
extern void LCD_cul(void);
extern void LCD_dot(void);
extern void LCD_box(void);
extern void wrhz(void) ;
extern void wrhzfd(void);
//===================================================================//
// LCD Command Write Subroutine //
//===================================================================//
void LCD_CmdWrite(unsigned char cmdReg,unsigned char cmdData)
{
//LCD_ChkBusy();
IO0CLR =BUSY;
delay(50);
LCD_cmdReg = cmdReg;
IO0CLR=CS1 ; //RA8803 Chip Enable.
IO0SET=RRD; //= 1;
IO0CLR=RS; // RS = 0;
IO0CLR=WWR; // WR = 0;
//delay(10);
IO0SET=WWR ; // WR = 1;
IO0SET=RS; // RS = 1;
IO0SET=CS1; //RA8803 Chip Disable.
//.................................................................
//LCD_ChkBusy();
delay(50);
LCD_cmdReg = cmdData;
IO0CLR=CS1 ; //RA8803 Chip Enable.
IO0SET=RRD;//
IO0CLR=RS; // RS = 0;
IO0CLR=WWR; // WR = 0;
//delay(10);
IO0SET=WWR ; // WR = 1;
IO0SET=RS; // RS = 1;
IO0SET=CS1; //RA8803 Chip Disable.
//delay(1);
}
void delay(int i)
{
int k ;
for ( k=0 ; k < i ; k++ );
}
//====================================================================//
// //
//====================================================================//
void LCD_Initial(void)
{
LCD_CmdWrite(0x00,0xCD); // LCD Control Register(LCR)
LCD_CmdWrite(0x01,0xf3); // Misc.Register(MIR)
LCD_CmdWrite(0x02,0x10); // Advance Power Setup Register(APSR)
LCD_CmdWrite(0x03,0x80); // Advance Display Setup Regiser(ADSR)
LCD_CmdWrite(0x10,0x68); // Cursor Control Register(CCR)
LCD_CmdWrite(0x11,0x20); // Distance of Word or Lines Register(DWLR)
LCD_CmdWrite(0x12,0x91); // Memory Access Mode Register(AWRR)
LCD_CmdWrite(0x20,0x27); // Active Window Right Register(AWRR)
LCD_CmdWrite(0x30,0xEF); // Active Window Bottom Register(AWBR)
LCD_CmdWrite(0x40,0x00); // Active Window Left Register(AWLR)
LCD_CmdWrite(0x50,0x00); // Active Window Top Register(AWTR)
LCD_CmdWrite(0x21,0x27); // Display Window Right Register(DWRR)
LCD_CmdWrite(0x31,0xEF); // Display Window Bottom Register(DWBR)
LCD_CmdWrite(0x41,0x00); // Display Window Left Register(DWLR)
LCD_CmdWrite(0x51,0x00); // Display Window Top Register(DWTR)
LCD_CmdWrite(0x60,0x00); // Cursor Position X Register(CPXR)
LCD_CmdWrite(0x61,0x00); // Begin Segment Position Register(BGSG)
LCD_CmdWrite(0x70,0x00); // Cursor Position Y Register(CPYR)
LCD_CmdWrite(0x71,0x00); // Shift action range,Begin Commom Register(BGCM)
LCD_CmdWrite(0x72,0xEF); // Shift action range,End Commom Register(EDCM)
LCD_CmdWrite(0x80,0x33); // Blink Time Register(BTR)
LCD_CmdWrite(0x81,0x00); // Frame Rate Polarity Change at Common_FA Register(FDCA)
LCD_CmdWrite(0x91,0x00); // Frame Rate Polarity Change at Common_FB Register(FDCB)
LCD_CmdWrite(0x90,0x04); // Shift Clock Control Register(SCCR)
LCD_CmdWrite(0xA0,0x11); // Interrupt Setup & Status Register(FRCB)
LCD_CmdWrite(0xA1,0x00); // Key Scan Control Register(KSCR)
LCD_CmdWrite(0xA2,0x00); // Key Scan Data Register(KSDR)
LCD_CmdWrite(0xA3,0x00); // Key Scan Data Expand Register(KSER)
LCD_CmdWrite(0xB0,0x27); // Interrupt Column Setup Register(INTX)
LCD_CmdWrite(0xB1,0xEF); // Interrupt Row Setup Register(INTY)
LCD_CmdWrite(0xC0,0xD0); // Touch Panel Control Register(TPCR)
LCD_CmdWrite(0xC1,0x0A); // ADC Status Register(ADCS)
LCD_CmdWrite(0xC8,0x80); // Touch Panel Segment High Byte Data Register(TPXR)
LCD_CmdWrite(0xC9,0x80); // Touch Panel Common High Byte Data Register(TPYR)
LCD_CmdWrite(0xCA,0x00); // Touch Panel Segment/Common Low Byte Data Register(TPZR)
LCD_CmdWrite(0xD0,0x0C); // LCD Contrast Control Register (LCCR)
LCD_CmdWrite(0xE0,0x00); // Pattern Data Register(PDR)
LCD_CmdWrite(0xF0,0xA0); // Font Control Register(FCR)
LCD_CmdWrite(0xF1,0x0F); // Font Size Control Register
}
/***************************************************************/
//****************************清屏
void LCD_Clearzf(void)
{
unsigned int i,j;
LCD_CmdWrite(0x60,0x00);
LCD_CmdWrite(0x70,0x00);
i=0;
j=0;
while(j <8)
{
while(i<15)
{
LCD_DataWrite(0xb0);
LCD_DataWrite(0xa0);
i++;
}
i=0;
j++;
}
}
//******************************
void LCD_DataWrite(unsigned char WrData)
{
//LCD_ChkBusy();
IO0CLR =BUSY;
///INT=0;
delay(2);
LCD_DATA = WrData;
IO0CLR =CS1; //RA8803 Chip Enable.
IO0SET=RRD; //
IO0SET=RS; // RS = 1;
IO0CLR =WWR; // WR = 0;
IO0CLR =WWR; // WR = 0;
IO0CLR =WWR; // WR = 0;
//delay(1);
IO0SET=WWR ; // WR = 1;
IO0SET=RS; // RS = 1;
IO0SET=CS1; //RA8803 Chip Disable.
}
unsigned char LCD_CmdRead(unsigned char cmdReg)
{
unsigned char REG_Read;
//LCD_ChkBusy();
delay(4);
LCD_cmdReg = cmdReg;
IO0CLR =CS1; //RA8803 Chip Enable.
IO0SET=RRD; //
IO0CLR =RS; // RS = 0;
IO0CLR =WWR; // WR = 0;
//delay(10);
IO0SET=WWR ;// WR = 1;
IO0SET=RS; // RS = 1;
IO0SET=CS1; //RA8803 Chip Disable.
//.................................................................
//LCD_ChkBusy();
delay(4);
LCD_DATA = 0xff;
IO0CLR =CS1; //RA8803 Chip Enable.
IO0SET=WWR ; // WR = 1;
IO0CLR =RS; // RS = 0;
IO0CLR =RRD ; // RD = 0;
//delay(100);
delay(4);
REG_Read = LCD_DATA;
IO0SET=RRD; // RD = 1;
IO0SET=RS; // RS = 1;
IO0SET=CS1; //RA8803 Chip Disable.
return REG_Read;
}
void LCD_ChkBusy(void)
{
do
{
}while(BUSY == 1);
}
//--- RA8803 Reset ---------------------------------------------------
void LCD_Reset(void)
{
//IO0SET=READY ; // LCD_RSWWRRRD/CS1/CS2 normal - skeep high.
IO0CLR =CS1; // RA8803 Chip Enable.
delay(1000);
IO0CLR =RST; // LCD RESET-pin active low.
delay(11000); // Reset 250ms
IO0SET=RST; // LCD RESET-pin Noraml high.
delay(1000);
}
//**************************写汉字
void wrhz(void)
{
unsigned int i;//,j
LCD_CmdWrite(0x00,0xCD);
LCD_CmdWrite(0x60,0x00);
LCD_CmdWrite(0x70,0x00);
for(i=0;i<15;i++)
{
LCD_DataWrite(0xB1); //北
LCD_DataWrite(0xB1);
LCD_DataWrite(0xBE); //京
LCD_DataWrite(0xA9);
LCD_DataWrite(0xC7); //青
LCD_DataWrite(0xE0);
LCD_DataWrite(0xD4); //云
LCD_DataWrite(0xC6);
LCD_DataWrite(0xB4); //创
LCD_DataWrite(0xB4);
LCD_DataWrite(0xD0); //新
LCD_DataWrite(0xC2);
LCD_DataWrite(0xBF); //科
LCD_DataWrite(0xC6);
LCD_DataWrite(0xBC); //技
LCD_DataWrite(0xBC);
LCD_DataWrite(0xB7); //发
LCD_DataWrite(0xA2);
LCD_DataWrite(0xD5); //展
LCD_DataWrite(0xB9);
LCD_DataWrite(0xD3); //有
LCD_DataWrite(0xD0);
LCD_DataWrite(0xCF); //限
LCD_DataWrite(0xDE);
LCD_DataWrite(0xD4); //责
LCD_DataWrite(0xF0);
LCD_DataWrite(0xC8); //任
LCD_DataWrite(0xCE);
LCD_DataWrite(0xB9); //公
LCD_DataWrite(0xAB);
LCD_DataWrite(0xCB); //司
LCD_DataWrite(0xBE);
LCD_DataWrite(0xD2); //液
LCD_DataWrite(0xBA);
LCD_DataWrite(0xBE); //晶
LCD_DataWrite(0xA7);
LCD_DataWrite(0xC4); //模
LCD_DataWrite(0xA3);
LCD_DataWrite(0xBF); //块
LCD_DataWrite(0xE9);
}
i++;
}
//**************************写汉字放大
/****************************
void wrhzfd(void )
{
//unsigned int i,j;
LCD_CmdWrite(0x00,0xCD);
LCD_CmdWrite(0x60,0x00);
LCD_CmdWrite(0x70,0x00);
LCD_CmdWrite(0xF1,0xFF);
LCD_DataWrite(0xB1); //北
LCD_DataWrite(0xB1);
}
***********************/
//***************************写图片
/************************
void wramap1(void)
{
unsigned char Data;
int i=0,j=0;
LCD_CmdWrite(0x60,0x00);
LCD_CmdWrite(0x70,0x00);
LCD_CmdWrite(0x00,0xC5);
LCD_CmdWrite(0x12,0x91);
while(j < 240)
{
for(i = 0; i < 40; i++)
{
Data = map_table1[j][i];
LCD_DataWrite(Data);
}
j++;
LCD_CmdWrite(0x60,0x00);
LCD_CmdWrite(0x70,j+00);
}
}
*******************************/
//****************************
unsigned char Read_TP_ststus(void)
{
LCD_CmdWrite(0xC0,0x08); /* 平常偵測觸控螢幕狀態只要將SW3-ON 即可*/
LCD_CmdWrite(0xC1,0x35); /* ADC 初始值設定*/
delay(1000); /* delay()只是防止觸控時的雜訊抑制*/
return LCD_CmdRead(0xC1) & 0x40; /* 0xC1 位址之bit6 若為”1”,表示有觸控發生*/
}
int main (void)
{
PINSEL0 = 0x00000000; // 设置管脚连接GPIO
PINSEL1= 0x00000000; // 设置管脚连接GPIO
IO0DIR = LCD_IOCON; // 设置l控制口
//unsigned char y_temp,x_temp;
LCD_Reset();
LCD_Initial();
//LCD_clear();
wrhz();
delay(1100);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
/********************
wrhzfd();
delay(1100);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
wramap1();
delay(11000);
delay(1100);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
delay(11000);
***************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -