新手上路
- 积分
- 48
- 金钱
- 48
- 注册时间
- 2012-8-24
- 在线时间
- 0 小时
|
5金钱
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
#define LCM_WR RB1
#define LCM_RD RB2
#define LCM_CE RB0
#define LCM_CD RA3
#define LCM_RST RA2
#define FS1 RA1 //write seize
#define LCM_DATA PORTD
#define LCM_COMMD PORTD
#define nop() asm("nop")
__CONFIG(0x3B31);
void init_IO();
void init_LCM();
void delay_um(uint um);
void delay_ms(uint ms);
void LCD_RESET();
uchar chk_busy();
void Write_Data(uchar da);
void Write_Command(uchar cd);
void WriteDataCommand(uchar Data,uchar Command);
void WriteData2Command(uchar Data1,uchar Data2,uchar Command);
void Check_Status_LCM();
void Write_LCM(const unsigned char *pt);
void LCMClearScreen();
const unsigned char TAB1B[ ] = {" WWW.12334455.COM"};
void main()
{
init_IO();
LCD_RESET();
init_LCM();
LCMClearScreen();
while(1)
{
Write_LCM(TAB1B);
delay_ms(1000);
}
}
void Write_LCM(const unsigned char *pt)
{
WriteData2Command(0x00,0x00,0x24);
Write_Command(0xB0);
while(*pt) //检测是否达到了字符串最后
{
Write_Data(*pt++); //发送数据给lcd
delay_ms(30);
}
}
void delay_us(uint um)
{
int i;
for(i=0;i<um;i++)
;
}
void delay_ms(uint ms)
{
uint i;
uchar j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--)
;
}
void init_IO()
{
TRISD=0x00;
PORTD=0xff;
TRISA=0x00;
PORTA=0xff;
TRISB=0x00;
PORTB=0xff;
FS1=1;
}
void init_LCM()
{
WriteData2Command(0x00,0x00,0x21);
WriteData2Command(0x03,0x00,0x22);
WriteData2Command(0x00,0x00,0x24);
WriteData2Command(0x24,0x00,0x40);
WriteData2Command(0x1e,0x00,0x41);
WriteData2Command(0x00,0x00,0x42);
WriteData2Command(0x1e,0x00,0x43);
Write_Command(0xa0);
Write_Command(0x80);
Write_Command(0x9f);
}
void WriteDataCommand(uchar Data,uchar Command)
{
Write_Data(Data);
delay_ms(20);
Write_Command(Command);
delay_ms(20);
}
void WriteData2Command(uchar Data1,uchar Data2,uchar Command)
{
Write_Data(Data1);
delay_ms(20);
Write_Data(Data2);
delay_ms(20);
Write_Command(Command);
delay_ms(20);
}
void Write_Data(uchar da)
{
Check_Status_LCM();
LCM_DATA=da;
LCM_CD=0;
LCM_CE=0;
LCM_RD=1;
LCM_WR=0;
nop();
nop();
LCM_WR=1;
LCM_CE=1;
LCM_CD=1;
}
void Write_Command(uchar cd)
{
Check_Status_LCM();
LCM_COMMD=cd;
LCM_CD=1;
LCM_CE=0;
LCM_RD=1;
LCM_WR=0;
nop();
nop();
nop();
LCM_WR=1;
LCM_CE=1;
LCM_CD=0;
}
//清屏
void LCMClearScreen()
{
uint i;
WriteData2Command(0x00,0x00,0x24);
Write_Command(0xB0);
for(i=0;i<8192;i++)//8k
{
Write_Data(0x00);//写数据
}
Write_Command(0xB2);
}
void LCD_RESET()
{
LCM_RST=0;
delay_ms(2);
LCM_RST=1;
delay_ms(10);
}
uchar chk_busy()
{
uchar temp ;
TRISD=0xff;
PORTD=0x00;
LCM_CD=1; //1
LCM_CE=0;
LCM_RD=0;
temp=PORTD;
nop();
LCM_RD=1;
LCM_CE=1;
LCM_CD=0;
TRISD=0x00;
PORTD=0x00;
return temp ;
}
void Check_Status_LCM()
{
uint xa;
uint xi;
for(xi = 0; xi < 200; xi++)
{
xa =chk_busy();
if((xa & 0x03) == 0x03)
break;
}
}
|
|