#include "reg52.h"
#include "intrins.h"
#define uint8_t unsigned char
#define uint16_t unsigned int
sbit GT_CS = P2^5;
sbit LCM_CS = P2^4;
sbit LCM_RST = P2^3;
sbit LCM_WR = P2^6;
sbit LCM_A0 = P2^1;
sbit LCM_A1 = P2^2;
#define LCM_BUS P0
#define LCM_ADDR_BUFFER 0x00
#define LCM_ADDR_ROWSET 0x01
#define LCM_ADDR_COLSET 0x02
#define LCM_ADDR_PAGESET 0x03
#define LCM_WIDTH 320
#define LCM_HEIGHT 240
#define COLOR_WHITE 0xFF
#define COLOR_RED 0xE0
#define COLOR_GREEN 0x1C
#define COLOR_BLUE 0x03 //0x03
void LCM_Write(uint8_t addr, uint8_t dat);
void delay_cnt(uint8_t count);
void delay_cnt(uint8_t count){
for (; count>0; count--);
}
void LCM_Write(uint8_t addr, uint8_t dat){
//选中LCM
LCM_CS = 0;
//设定地址线状态
switch (addr){
case LCM_ADDR_BUFFER:
LCM_A0 = 0;
LCM_A1 = 0;
break;
case LCM_ADDR_ROWSET:
LCM_A0 = 1;
LCM_A1 = 0;
break;
case LCM_ADDR_COLSET:
LCM_A0 = 0;
LCM_A1 = 1;
break;
case LCM_ADDR_PAGESET:
LCM_A0 = 1;
LCM_A1 = 1;
break;
}
//将数据送至LCM总线
LCM_BUS = dat;
//写入数据
LCM_WR = 0;
//delay_cnt(2);
LCM_WR = 1;
//取消选中LCM
LCM_CS = 1;
}
/*
void LCM_RCDelay(uint8_t cnt){
//delay_cnt(0);
_nop_();
}
*/
#define LCM_RCDelay(x)
//_nop_();
void main(void)
{
uint16_t row, col;
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
delay_cnt(255);
P2 = 0xff;
//低电平复位,至少持续?ms
LCM_RST = 0;
delay_cnt(255);
LCM_RST = 1;
delay_cnt(255);
LCM_Write(LCM_ADDR_PAGESET, 0);
LCM_RCDelay(0);
// do{
//清屏
//行地址为8位,直接写入
LCM_Write(LCM_ADDR_ROWSET, 0);
LCM_RCDelay(0);
//列地址为16位,每次写8位,低位先写,高位后写
LCM_Write(LCM_ADDR_COLSET, 0);
LCM_RCDelay(0);
LCM_Write(LCM_ADDR_COLSET, 0);
LCM_RCDelay(0);
for (row=0; row<LCM_HEIGHT; row++){
for (col=0; col<320; col++){
LCM_Write(LCM_ADDR_BUFFER, 0);
} //for (col=0; col<LCM_WIDTH; col++)
} //for (row=0; row<LCM_HEIGHT; row++)
//行地址为8位,直接写入
LCM_RCDelay(0);
LCM_Write(LCM_ADDR_ROWSET, 0);
LCM_RCDelay(0);
//列地址为16位,每次写8位,低位先写,高位后写
LCM_Write(LCM_ADDR_COLSET, 0);
LCM_RCDelay(0);
LCM_Write(LCM_ADDR_COLSET, 0);
LCM_RCDelay(0);
for (row=0; row<241; row++){
for (col=0; col<LCM_WIDTH; col++){
LCM_Write(LCM_ADDR_BUFFER, COLOR_RED);
} //for (col=0; col<LCM_WIDTH; col++)
} //for (row=0; row<LCM_HEIGHT; row++)
while(1);
}
//行地址为8位,直接写入
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_ROWSET, 0);
// LCM_RCDelay(0);
//
// //列地址为16位,每次写8位,低位先写,高位后写
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
//
// for (row=0; row<241; row++){
// for (col=0; col<330; col++){
// LCM_Write(LCM_ADDR_BUFFER, COLOR_GREEN);
// } //for (col=0; col<LCM_WIDTH; col++)
// }
// }
//for (row=0; row<LCM_HEIGHT; row++)
//行地址为8位,直接写入
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_ROWSET, 0);
// LCM_RCDelay(0);
//
// //列地址为16位,每次写8位,低位先写,高位后写
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
//
// for (row=0; row<241; row++){
// for (col=0; col<LCM_WIDTH; col++){
// LCM_Write(LCM_ADDR_BUFFER, COLOR_BLUE);
// } //for (col=0; col<LCM_WIDTH; col++)
// }
// while(1);
//}
//for (row=0; row<LCM_HEIGHT; row++)
//
// //行地址为8位,直接写入
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_ROWSET, 0);
// LCM_RCDelay(0);
//
// //列地址为16位,每次写8位,低位先写,高位后写
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
// LCM_Write(LCM_ADDR_COLSET, 0);
// LCM_RCDelay(0);
//
// LCM_Write(LCM_ADDR_BUFFER, COLOR_BLUE);
// {P1=0xfa;}
//
// }
// while(1);
//}