|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-7-6 10:49:17
|
显示全部楼层
#include <C8051F410.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
#include <INTRINS.H>
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0 //LCD1602数据端口
sbit LCM_RS=P1^2; //LCD1602命令端口
sbit LCM_RW=P1^1; //LCD1602命令端口
sbit LCM_EN=P1^0; //LCD1602命令端口
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};
void OSCILLATOR_Init (void);
void Port_Init (void);
void InitLcd(); //初始化lcd1602
void WriteDataLCM(uchar dataW);
void WriteCommandLCM(uchar CMD,uchar Attribc);
//*********************************************************
void OSCILLATOR_Init (void) //配置系统时钟24500000Hz
{
OSCICN = 0x87;
}
//********************************************************
void Port_Init (void)
{
P0MDOUT = 0xFF;
P1MDOUT = 0x17;
XBR1 = 0x40;
}
/********************************/
void Delay1ms(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 main()
{
// uchar devid;
unsigned int i;
InitLcd(); //液晶初始化ADXL345
OSCILLATOR_Init ();
Port_Init ();
PCA0MD &= ~0x40; // WDTE = 0 (watchdog timer enable bit)
EA=1;
while(1) //循环
{
for(i=0;i<14;i++)
{
WriteDataLCM(Netdata[i]);
Delay1ms(20);
}
WriteCommandLCM(0x80+0x51,1);
for(i=0;i<14;i++)
{
WriteDataLCM(NCDdata[i]);
Delay1ms(20);
}
for(i=0;i<14;i++) //整屏左移
{
WriteDataLCM(0x18); //整屏左移一个字节
Delay1ms(400);
}
InitLcd();
}
}
这个为什么显示都成了问题? |
|