代码如下:
#include <C8051F410.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
#include <INTRINS.H>
#define uchar unsigned char
#define uint unsigned int
unsigned char xdata Netdata[14]={0x77,0x77,0x77,0x2e,0x78,0x68,0x6c,0x2e
,0x63,0x6f,0x6d,0x2e,0x63,0x6e};
unsigned char xdata NCDdata[14]={0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20
,0x74,0x6f,0x20,0x4e,0x43,0x44};
sbit LCM_EN=P1^0;
sbit LCM_RW=P1^1;
sbit LCM_RS=P1^2;
#define DataPort P0
void delay(int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<1000;k++);
}
void WaitForEnable(void)
{
DataPort=0xff;
LCM_RS=0;
LCM_RW=1;
_nop_();
LCM_EN=1;
_nop_();
_nop_();
while(DataPort&0x80);
LCM_EN=0;
}
void WriteCommandLCM(uchar CMD,uchar Attribc)
{
if(Attribc)WaitForEnable();
LCM_RS=0;LCM_RW=0;
_nop_();
DataPort=CMD;
_nop_();
LCM_EN=1;
_nop_();
_nop_();
LCM_EN=0;
}
void WriteDataLCM(uchar dataW)
{
WaitForEnable();
LCM_RS=1;LCM_RW=0;
_nop_();
DataPort=dataW;
_nop_();
LCM_EN=1;
_nop_();
_nop_();
LCM_EN=0;
}
void InitLcd()
{
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
void SYSCLK_Init(void)
{
OSCICN = 0x87;
}
void PORT_Init(void)
{
P0MDOUT = 0xFF;
P1MDOUT = 0xFF;
XBR1 = 0x40;
}
void main()
{
unsigned int i;
PCA0MD &= ~0x40;
SYSCLK_Init();
PORT_Init();
InitLcd();
//write_com(0x80);
//write_data('H');
while(1) //最后程序停留在while语句中
{
for(i=0;i<14;i++)
{
WriteDataLCM(Netdata[i]);
delay(20);
}
WriteCommandLCM(0x80+0x51,1);
for(i=0;i<14;i++)
{
WriteDataLCM(NCDdata[i]);
delay(20);
}
for(i=0;i<14;i++) //整屏左移
{
WriteCommandLCM(0x18,1); //整屏左移一个字节
delay(400);
}
InitLcd();
/*unsigned int n;
for(n=0;n<14;n++)
{
write_data(NCDdata[n]);
}
delay(5);
LCD_Init();*/
}
}
一周热门 更多>