各位大神,请问我这个程序那里出现语法错误啦,我看不...
时间:10-02
整理:3721RD
点击:
#include"reg52.h"
#include"stdio.h"
#include"intrins.h"
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit LCD_EN = P1^0; /* 读写使能信号 */
sbit LCD_RW = P2^0; /* 读写选择信号 */
sbit LCD_RS = P2^1; /* 数据、指令选择信号 */
#define DATA_PORT P0 /* 数据端口 */
#define CLEAR_DISPLAY 0x01; //显示清屏
#define SET_OPERATING_MODE 0X38; //工作方式设置
#define SET_DISPLAY 0x08; //显示命令
#define SET_DISPLAY_D 0x04; //开显示
#define SET_DISPLAY_C 0x02; //开光标
#define SET_DISPLAY_B 0x01; //开闪烁
#define SET_INPUT_MODE 0x06; //读写数据后,AC自动加1,画面不动
#define SET_DDRAM_ADDRESS1 0x80; //第一行显示
#define SET_DDRAM_ADDRESS2 0xc0; //第二行显示
?
uint8 code DisplayBuf0[] =
{
" WU YUAN YUAN "
};
uint8 code DisplayBuf1[] =
{
" WO AI NI "
};
uint8 code DisplayBuf2[] =
{
" WO HAO AI NI "
};
uint8 code DisplayBuf3[] =
{
" NI AI WO MA "
};
void DelayUs( uint16 Us )
{
while(--Us);
}
void DelayMs( uint16 Ms )
{
uint8 i;
while (Ms--)
{
for ( i = 0; i < 114; i++ );
}
}
void LCD1602_CheckBusy()
{
uint8 BusyFlag;
BusyFlag = 1;
while (BusyFlag)
{
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 1;
BusyFlag = DATA_PORT & 0x80 ;
DelayUs(1);
}
LCD_EN = 0;
}
void LCD1602_WriteCommand(uint8 cmd)
{
LCD1602_CheckBusy();
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
DATA_PORT = cmd;
DelayUs(1);
LCD_EN = 0;
}
void LCD1602_WriteData(uint8 WrData)
{
LCD1602_CheckBusy( );
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
DATA_PORT = WrData;
DelayUs(1);
LCD_EN = 0;
}
void LCD1602_Init()
{
LCD1602_WriteCommand(SET_OPERATING_MODE);
LCD1602_WriteCommand(SET_DISPLAY | SET_DISPLAY_D);
LCD1602_WriteCommand(SET_INPUT_MODE);
LCD1602_WriteCommand(CLEAR_DISPLAY);
}
void LCD1602_SetDisplayPosition(uint8 Xpos,uint8 Ypos)
{
if(Ypos==0x01)
{
LCD1602_WriteCommand( Xpos | SET_DDRAM_ADDRESS1);
}
if(Ypos==0x02)
{
LCD1602_WriteCommand( Xpos | SET_DDRAM_ADDRESS2);
}
}
void LCD1602_WriteString(uint8 *str)
{
while(*str!=0x00)
{
LCD1602_WriteData( *str );
str++;
}
}
void main()
{
DelayMs( 20 ); /* 上电延时 */
LCD1602_Init(); /* 初始化LCD */
while(1)
{
LCD1602_SetDisplayPosition( 0, 1 ); /* 第一行显示 */
LCD1602_WriteString( DisplayBuf0 );
LCD1602_SetDisplayPosition( 0, 2 ); /* 第二行显示 */
LCD1602_WriteString( DisplayBuf1 );
DelayMs(2000); /* 延时大约2秒 */
LCD1602_WriteCommand( CLEAR_DISPLAY );
DelayMs(500);
LCD1602_SetDisplayPosition( 0, 1 );
LCD1602_WriteString( DisplayBuf2 );
LCD1602_SetDisplayPosition( 0, 2 );
LCD1602_WriteString( DisplayBuf3 );
DelayMs(2000);
LCD1602_WriteCommand( CLEAR_DISPLAY );
DelayMs(500);
}
}
#include"stdio.h"
#include"intrins.h"
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit LCD_EN = P1^0; /* 读写使能信号 */
sbit LCD_RW = P2^0; /* 读写选择信号 */
sbit LCD_RS = P2^1; /* 数据、指令选择信号 */
#define DATA_PORT P0 /* 数据端口 */
#define CLEAR_DISPLAY 0x01; //显示清屏
#define SET_OPERATING_MODE 0X38; //工作方式设置
#define SET_DISPLAY 0x08; //显示命令
#define SET_DISPLAY_D 0x04; //开显示
#define SET_DISPLAY_C 0x02; //开光标
#define SET_DISPLAY_B 0x01; //开闪烁
#define SET_INPUT_MODE 0x06; //读写数据后,AC自动加1,画面不动
#define SET_DDRAM_ADDRESS1 0x80; //第一行显示
#define SET_DDRAM_ADDRESS2 0xc0; //第二行显示
?
uint8 code DisplayBuf0[] =
{
" WU YUAN YUAN "
};
uint8 code DisplayBuf1[] =
{
" WO AI NI "
};
uint8 code DisplayBuf2[] =
{
" WO HAO AI NI "
};
uint8 code DisplayBuf3[] =
{
" NI AI WO MA "
};
void DelayUs( uint16 Us )
{
while(--Us);
}
void DelayMs( uint16 Ms )
{
uint8 i;
while (Ms--)
{
for ( i = 0; i < 114; i++ );
}
}
void LCD1602_CheckBusy()
{
uint8 BusyFlag;
BusyFlag = 1;
while (BusyFlag)
{
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 1;
BusyFlag = DATA_PORT & 0x80 ;
DelayUs(1);
}
LCD_EN = 0;
}
void LCD1602_WriteCommand(uint8 cmd)
{
LCD1602_CheckBusy();
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
DATA_PORT = cmd;
DelayUs(1);
LCD_EN = 0;
}
void LCD1602_WriteData(uint8 WrData)
{
LCD1602_CheckBusy( );
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
DATA_PORT = WrData;
DelayUs(1);
LCD_EN = 0;
}
void LCD1602_Init()
{
LCD1602_WriteCommand(SET_OPERATING_MODE);
LCD1602_WriteCommand(SET_DISPLAY | SET_DISPLAY_D);
LCD1602_WriteCommand(SET_INPUT_MODE);
LCD1602_WriteCommand(CLEAR_DISPLAY);
}
void LCD1602_SetDisplayPosition(uint8 Xpos,uint8 Ypos)
{
if(Ypos==0x01)
{
LCD1602_WriteCommand( Xpos | SET_DDRAM_ADDRESS1);
}
if(Ypos==0x02)
{
LCD1602_WriteCommand( Xpos | SET_DDRAM_ADDRESS2);
}
}
void LCD1602_WriteString(uint8 *str)
{
while(*str!=0x00)
{
LCD1602_WriteData( *str );
str++;
}
}
void main()
{
DelayMs( 20 ); /* 上电延时 */
LCD1602_Init(); /* 初始化LCD */
while(1)
{
LCD1602_SetDisplayPosition( 0, 1 ); /* 第一行显示 */
LCD1602_WriteString( DisplayBuf0 );
LCD1602_SetDisplayPosition( 0, 2 ); /* 第二行显示 */
LCD1602_WriteString( DisplayBuf1 );
DelayMs(2000); /* 延时大约2秒 */
LCD1602_WriteCommand( CLEAR_DISPLAY );
DelayMs(500);
LCD1602_SetDisplayPosition( 0, 1 );
LCD1602_WriteString( DisplayBuf2 );
LCD1602_SetDisplayPosition( 0, 2 );
LCD1602_WriteString( DisplayBuf3 );
DelayMs(2000);
LCD1602_WriteCommand( CLEAR_DISPLAY );
DelayMs(500);
}
}