完全找不到头绪啊!!
#include<reg51.h>
#define LCD1602_DATAPINS P0;
sbit LCD_RS=P2^6;
sbit LCD_RW=P2^5;
sbit LCD_E=P2^7;
unsigned char code DATA[]="I Want You" ;
void Delay1ms(unsigned int c)
{
unsigned char a,b;
for(;c>0;c--);
for(a=38;a>0;a--);
for(b=130;b>0;b--);
}
void lcdcom(unsigned char com)
{
LCD_E=0;
LCD_RS=0;
LCD_RW=0;
LCD1602_DATAPINS=com;
Delay1ms(10);
LCD_E=1;
Delay1ms(10);
LCD_E=0;
}
void lcddat(unsigned char dat)
{
LCD_E=0;
LCD_RS=1;
LCD_RW=0;
LCD1602_DATAPINS=dat;
Delay1ms(10);
LCD_E=1;
Delay1ms(10);
LCD_E=0;
}
void lc
tinit()
{
lcdcom(0x38);
lcdcom(0x0c);
lcdcom(0x06);
lcdcom(0x01);
}
void main()
{
lcdinit();
while(1)
{ unsigned char i;
lcdcom(0x80);
for(i=0;i<9;i++)
{
lcddat(DATA[i]);
}
}
}
Build target 'Target 1'
compiling lcd.c...
LCD.C(20): warning C275: expression with possibly no effect
LCD.C(20): error C141: syntax error near '='
LCD.C(51): error C141: syntax error near '='
Target not created
# include <reg51.h>
# include <intrins.h>
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef bit BOOL;
sbit rs=P0^7;
sbit rw=P0^6;
sbit ep=P0^5;
BYTE code dis1 []={" yanlindianzi"};
BYTE code dis2 []={" 15001162199"};
void delay (int m)
{
unsigned char i,j;
for (i=0;i<m;i++)
for (j=0;j<253;j++);
}
BOOL lcd_bz()
{
BOOL result;
rs=0; // 读忙信号
rw=1;
ep=1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (BOOL)(P2&0x80);
ep=0;
result ;
}
void lcd_wcmd (BYTE cmd)
{
while (lcd_bz());
rs=0;
rw=0;
ep=0;
_nop_();
_nop_();
P2=cmd ;
_nop_();
_nop_();
_nop_();
_nop_();
ep=1;
_nop_();
_nop_();
_nop_();
_nop_();
ep=0;
}
void lcd_pos (BYTE pos)
{
lcd_wcmd (pos|0x80);
}
void lcd_wdat (BYTE dat)
{
while (lcd_bz());
rs=1;
rw=0;
ep=0;
_nop_();
_nop_();
P2=dat ;
_nop_();
_nop_();
_nop_();
_nop_();
ep=1;
_nop_();
_nop_();
_nop_();
_nop_();
ep=0;
}
void lcd_init ()
{
lcd_wcmd (0x38);
delay (1);
lcd_wcmd (0x0c);
delay (1);
lcd_wcmd (0x06);
delay (1);
lcd_wcmd (0x01);
delay (1);
}
main ()
{
BYTE i;
lcd_init ();
delay (10);
lcd_pos (0);
i=0;
while (dis1 [i]!=' ')
{
lcd_wdat (dis1 [i]);
i++;
}
lcd_pos (0x41);
i=0;
while (dis2 [i]!=' ')
{
lcd_wdat (dis2 [i]);
i++;
}
while (1);
}
感谢,现已改正错误!
真的唉,我都没看到初始化那里打错了......谢谢你这么耐心地回答我的问题,改正后程序已经没问题了!
一周热门 更多>