标题: lcd.c(3): error C141: syntax error near 'sbit' [打印本页]

作者: acgacg    时间: 2023-11-19 17:08
标题: lcd.c(3): error C141: syntax error near 'sbit'
#include <REGX52.H>
#include "delay.h"
sbit LCD_RW = P2^5;
sbit LCD_RS = P2^6;
sbit LCD_EN = P2^7;
#define LCD_DATAPORT P0
void data_process()
{
LCD_EN=1;
delay(1);
LCD_EN=0;
delay(1);
}
void writecommand(unsigned char command)
{
LCD_RS=0;
LCD_RW=0;
LCD_DATAPORT=command;
data_process();
}
void writedata(unsigned char datas)
{
LCD_RS=1;
LCD_RW=0;
LCD_DATAPORT=datas;
data_process();
}

void LCD_Init(void)
{
        LCD_writecommand(0x38);
        LCD_writecommand(0x0C);
        LCD_writecommand(0x06);
        LCD_writecommand(0x01);
}
void set_cursor(unsigned char line,unsigned char column)
{
if(line==1);
        writecommand(0x80|column-1);
else
        writecommand(0x80|column-1+0x40);
}
void writes_char(unsigned char line,unsigned char column,unsigned char str)
{
set_cursor(line,column);
writedata(str);
}
void writes_string(unsigned char line,unsigned char column,unsigned char *string)
{
set_cursor(line,column);
for(int i=0;i<string[i]!=0;++i)
        writedata(string[i]);
}
void main()
{
LCD_Init();
writes_string(1,1,"fuck you");
while(1)
{

}
}


屏幕截图 2023-11-19 170651.png (286.22 KB, 下载次数: 19)

屏幕截图 2023-11-19 170651.png

作者: Hephaestus    时间: 2023-11-19 19:43
应该是delay.h不干净,把错误遗留这里了。
作者: sgq657785    时间: 2023-11-19 20:01
第六行移动到第三行试试
作者: zhuls    时间: 2023-11-19 20:51
因为代码不文明,被KEIL强制隔离了
作者: zhuls    时间: 2023-11-19 21:07
#include <REGX52.H>
#include "delay.h"//路径对吗?
sbit LCD_RW = P2^5;
sbit LCD_RS = P2^6;
sbit LCD_EN = P2^7;
#define LCD_DATAPORT P0
void data_process()
{
LCD_EN=1; //EN 低跳变?
delay(1);
LCD_EN=0;
delay(1);
}

void writecommand(unsigned char command)
{
LCD_RS=0;
LCD_RW=0;
LCD_DATAPORT=command;
data_process();
}
void writedata(unsigned char datas)
{
LCD_RS=1;
LCD_RW=0;
LCD_DATAPORT=datas;
data_process();
}

void LCD_Init(void)
{
        LCD_writecommand(0x38);//LCD_writecommand原型在哪 里?
        LCD_writecommand(0x0C);
        LCD_writecommand(0x06);
        LCD_writecommand(0x01);
}
void set_cursor(unsigned char line,unsigned char column)
{
if(line==1);  //这行是干什么的?
        writecommand(0x80|column-1);//逻辑顺序对吗?
else
        writecommand(0x80|column-1+0x40);//逻辑顺序对吗?
}
void writes_char(unsigned char line,unsigned char column,unsigned char str)
{
set_cursor(line,column);
writedata(str);
}
void writes_string(unsigned char line,unsigned char column,unsigned char *string)
{
set_cursor(line,column);
for(int i=0;i<string!=0;++i)
        writedata(string);
}
void main()
{
LCD_Init();
writes_string(1,1,"fuck you");
while(1)
{

}
}

作者: Hephaestus    时间: 2023-11-19 21:16
zhuls 发表于 2023-11-19 21:07
#include
#include "delay.h"//路径对吗?
sbit LCD_RW = P2^5;

路径不对怎么可能出现楼主位的错误,不仅行数不对,而且错误也不对。

错误的问题出在第3行,而第3行显然是正确的,那就是第2行的遗留问题,编译器没检测到问题,但是到了正确的第3行就出问题了。显然是头文件太脏了,把正确的文件污染成错误的。
作者: zhuls    时间: 2023-11-19 21:27
Hephaestus 发表于 2023-11-19 21:16
路径不对怎么可能出现楼主位的错误,不仅行数不对,而且错误也不对。

错误的问题出在第3行,而第3行显 ...

不一定哦~~
我曾经遇到过这样的错误:
单个文件都是对的,是在extern 引用时,因为类型不对,(变量声明时u8,引用时u16)结果提示什么什么缺少“;”、XXX未定义之类的。反正就是5花8门的错误后,后来把extern的类型配对后就没有错了。
作者: Hephaestus    时间: 2023-11-19 21:37
zhuls 发表于 2023-11-19 21:27
不一定哦~~
我曾经遇到过这样的错误:
单个文件都是对的,是在extern 引用时,因为类型不对,(变量声 ...

算了吧,驴唇不对马嘴。
作者: huihou    时间: 2023-11-20 20:38
delay.h看看是不是声明少了个;





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1