/*
\\\|///
\\ - - //
( @ @ )
+---------------------oOOo-(_)-oOOo-------------------------+
| |
| TFT018.c |
| by Xiaoran Liu |
| 2008.3.16 |
| |
| ZERO research group |
| www.the0.net |
| |
| Oooo |
+----------------------oooO--( )--------------------------+
( ) ) /
\ ( (_/
\_)
*/
// 引入相关芯片的头文件
#include <LPC214X.h>
//#include "LPC2103Z.h"
#include "TFT018.h"
#include "MyType.h"
volatile U8 Font=0;
/*----------------------------------------------------------*\
| Backlight Initialize |
\*----------------------------------------------------------*/
void BacklightOn(void) {
PINSEL1 &= 0xFFFFF3FF;
PINSEL1 |= 0x00000400; // 设置PWM5连接到P0.21管脚
PWMPR = 0x00; // 不分频,计数频率为Fpclk
PWMMR0 = 50; // 设置PWM周期,PWMMR0=50
PWMMR5 = 6; // 设置PWM占空比,PWMMR2=49
PWMLER = 0x20; // PWMMR0、PWMMR5锁存,更新PWM占空比
PWMPCR = 0x2000; // 允许PWM5输出,单边PWM
PWMTCR = 0x09; // 启动定时器,PWM使能
}
/*----------------------------------------------------------*\
| Delay |
\*----------------------------------------------------------*/
void Delay1Ms(unsigned int tmr) {
while( tmr ) {
unsigned int i;
for(i=0;i<10;i++);
tmr--;
}
}
/*----------------------------------------------------------*\
| BUS simulate |
\*----------------------------------------------------------*/
/* ------ LOW LEVEL OPERATE ------ */
void LCD_Bus_Initial( void ) {
//PINSEL2 = 0x00000004;
//SCS=0x03; //设置快速FGPIO
//FIO0MASK = ~(LCD_BUS_RST | LCD_BUS_CS | LCD_BUS_RD); // 允许快速I/O
IO0DIR = LCD_BUS_RST | LCD_BUS_CS | LCD_BUS_RD;
//FIO1MASK = ~(LCD_BUS_RS | LCD_BUS_RW | LCD_BUS_DAT); // 允许快速I/O
IO1DIR = LCD_BUS_RS | LCD_BUS_RW;
IO0CLR = LCD_BUS_RST;
Delay1Ms( 20 );
IO0SET = LCD_BUS_RST | LCD_BUS_CS | LCD_BUS_RD;
IO1SET = LCD_BUS_RS | LCD_BUS_RW;
}
void LCD_Bus_Write_Byte( unsigned char Data ) {
unsigned int d = (((unsigned int)Data)<<16) & LCD_BUS_DAT;
IO1CLR = LCD_BUS_DAT; // data on bus
IO1SET = d;
//IO1PIN = ((unsigned int)Data)<<16;
IO1CLR = LCD_BUS_RW; // RW to LOW
//Delay1Ms( 1 );
IO1SET = LCD_BUS_RW; // RW to HIGH
}
void LCD_Bus_Write_Data( unsigned short Data ) {
LCD_Bus_Write_Byte( Data>>8 );
LCD_Bus_Write_Byte( Data );
}
unsigned int LCD_Bus_Read_Byte( void ) {
unsigned int BusData;
IO0CLR = LCD_BUS_RD; // RD to LOW
BusData = IO1PIN;
Delay1Ms( 1 );
IO0SET = LCD_BUS_RD; // RD to HIGH
return (BusData>>16)&0xFF;
}
void LCD_Reg_Set(unsigned int Cmd,unsigned int Data) {
IO1DIR |= LCD_BUS_DAT;
IO0CLR = LCD_BUS_CS;
IO0SET = LCD_BUS_RD;
IO1CLR = LCD_BUS_RS;
LCD_Bus_Write_Byte( Cmd );
IO1SET = LCD_BUS_RS;
LCD_Bus_Write_Byte( Data );
IO0SET = LCD_BUS_CS;
IO1DIR &= ~LCD_BUS_DAT;
}
/*----------------------------------------------------------*\
| LCD Initialize |
\*----------------------------------------------------------*/
void LCD_Init( void ) {
LCD_Bus_Initial();
//IOCLR = LCD_BUS_CS;
//LCD_Reg_Set(0x01,0x00);
//LCD_Reg_Set(0x02,0x06);
//LCD_Reg_Set(0x02,0x46);
LCD_Reg_Set(0x02,0x86);
LCD_Reg_Set(0x03,0x00);
LCD_Reg_Set(0x05,0x08);
LCD_Reg_Set(0x07,0x7F);
LCD_Reg_Set(0x08,0x17);
// SRAM control
LCD_Reg_Set(0x09,0x00);
LCD_Reg_Set(0x10,0x00);
LCD_Reg_Set(0x11,0x7F);
LCD_Reg_Set(0x12,0x9F);
LCD_Reg_Set(0x14,0x00);
LCD_Reg_Set(0x16,0x9F);
LCD_Reg_Set(0x17,0x01);
LCD_Reg_Set(0x18,0x00);
LCD_Reg_Set(0x19,0x00);
// Gamma voltage adjustalbe level
LCD_Reg_Set(0x21,0x88);
LCD_Reg_Set(0x22,0x33);
LCD_Reg_Set(0x23,0xCC);
LCD_Reg_Set(0x24,0xCC);
LCD_Reg_Set(0x25,0xBB);
LCD_Reg_Set(0x26,0xBB);
LCD_Reg_Set(0x27,0x77);
LCD_Reg_Set(0x28,0x77);
LCD_Reg_Set(0x29,0x77);
LCD_Reg_Set(0x06,0xC7);
}
void LCD_SetArea( U8 x0, U8 y0, U8 x1, U8 y1 ) {
// SRAM control
LCD_Reg_Set(0x09,y0);
LCD_Reg_Set(0x10,x0);
LCD_Reg_Set(0x11,y1);
LCD_Reg_Set(0x12,x1);
LCD_Reg_Set(0x18,y0);
LCD_Reg_Set(0x19,x0);
}
void LCD_Rectangle( unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned int Data ) {
int x,y;
LCD_SetArea(x0,y0,x1,y1);
IO1DIR |= LCD_BUS_DAT;
IO0CLR = LCD_BUS_CS;
IO0SET = LCD_BUS_RD;
IO1SET = LCD_BUS_RS;
for(x=0;x<=x1-x0;x++)
for(y=0;y<=y1-y0;y++) {
LCD_Bus_Write_Byte( Data>>8 );
LCD_Bus_Write_Byte( Data );
}
IO0SET = LCD_BUS_CS;
IO1DIR &= ~LCD_BUS_DAT;
}
void LCD_Clear_Screen( unsigned int Data ) {
LCD_Rectangle(0,0,159,127, Data );
}
void LCD_SetPixel(unsigned short x, unsigned short y, unsigned short color) {
LCD_SetArea(x,y,x,y);
IO1DIR |= LCD_BUS_DAT;
IO0CLR = LCD_BUS_CS;
IO0SET = LCD_BUS_RD;
LCD_Bus_Write_Byte( color>>8 );
LCD_Bus_Write_Byte( color );
IO0SET = LCD_BUS_CS;
IO1DIR &= ~LCD_BUS_DAT;
}
#include "8X16.h"
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
register unsigned int i,j;
LCD_SetArea(x,y,x+8-1,y+16-1);
IO1DIR |= LCD_BUS_DAT;
IO0CLR = LCD_BUS_CS;
IO0SET = LCD_BUS_RD;
IO1SET = LCD_BUS_RS;
for(i=0; i<16;i++) {
unsigned char m=Font8x16[c*16+i];
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
LCD_Bus_Write_Byte(f>>8);
LCD_Bus_Write_Byte(f);
}
else {
LCD_Bus_Write_Byte(b>>8);
LCD_Bus_Write_Byte(b);
}
m<<=1;
}
}
IO0SET = LCD_BUS_CS;
IO1DIR &= ~LCD_BUS_DAT;
}
#include "8X8h.h"
void LCD_PutChar8x8(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
register unsigned int i,j;
LCD_SetArea(x,y,x+8-1,y+8-1);
IO1DIR |= LCD_BUS_DAT;
IO0CLR = LCD_BUS_CS;
IO0SET = LCD_BUS_RD;
IO1SET = LCD_BUS_RS;
for(i=0; i<8;i++) {
unsigned char m=Font8x8[c][i];
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
LCD_Bus_Write_Byte(f>>8);
LCD_Bus_Write_Byte(f);
}
else {
LCD_Bus_Write_Byte(b>>8);
LCD_Bus_Write_Byte(b);
}
m<<=1;
}
}
IO0SET = LCD_BUS_CS;
IO1DIR &= ~LCD_BUS_DAT;
}
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
if( Font )
LCD_PutChar8x8( x, y, c, f, b );
else
LCD_PutChar8x16( x, y, c, f, b );
}
void LCD_PutString(unsigned short x, unsigned short y, char *s, unsigned int f, unsigned int b) {
register unsigned char l=0;
while(*s) {
LCD_PutChar(x+l*8,y,*s,f,b);
s++;l++;
}
}
IIC.rar_LPC2148 IIC
版权申诉
65 浏览量
2022-09-21
05:54:10
上传
评论
收藏 116KB RAR 举报
weixin_42651887
- 粉丝: 75
- 资源: 1万+
最新资源
- XILINXFPGA源码Xilinxspratan3xcs100E(VGAPS2)
- XILINXFPGA源码XilinxSPARTAN-3E入门开发板实例
- XILINXFPGA源码XilinxSdramVerilog和VHDL版本文档
- 物联网智能家居方案-基于Nucleo-STM32L073&机智云(大赛作品,文档齐全,可直接运行)(文档加Matlab源码)
- XILINXFPGA源码XilinxISE9.xFPGACPLD设计源码
- 成都市地图含高新区(高新南区,高新西区),天府新区,东部新区虚拟行政区划
- XILINXFPGA源码XilinxEDK设计试验
- XILINXFPGA源码XilinxEDKMicroBlaze内置USB固件程序
- 基于 django 的视频点播后台管理系统源代码+数据库
- 基于Java的网上医院预约挂号系统的设计与实现(部署视频)-kaic.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈