找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 598|回复: 8
收起左侧

lcd.c(3): error C141: syntax error near 'sbit'

[复制链接]
ID:1100383 发表于 2023-11-19 17:08 | 显示全部楼层 |阅读模式
#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
回复

使用道具 举报

ID:883242 发表于 2023-11-19 19:43 | 显示全部楼层
应该是delay.h不干净,把错误遗留这里了。
回复

使用道具 举报

ID:227393 发表于 2023-11-19 20:01 来自手机 | 显示全部楼层
第六行移动到第三行试试
回复

使用道具 举报

ID:69038 发表于 2023-11-19 20:51 | 显示全部楼层
因为代码不文明,被KEIL强制隔离了
回复

使用道具 举报

ID:69038 发表于 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)
{

}
}
回复

使用道具 举报

ID:883242 发表于 2023-11-19 21:16 | 显示全部楼层
zhuls 发表于 2023-11-19 21:07
#include
#include "delay.h"//路径对吗?
sbit LCD_RW = P2^5;

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

错误的问题出在第3行,而第3行显然是正确的,那就是第2行的遗留问题,编译器没检测到问题,但是到了正确的第3行就出问题了。显然是头文件太脏了,把正确的文件污染成错误的。
回复

使用道具 举报

ID:69038 发表于 2023-11-19 21:27 | 显示全部楼层
Hephaestus 发表于 2023-11-19 21:16
路径不对怎么可能出现楼主位的错误,不仅行数不对,而且错误也不对。

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

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

使用道具 举报

ID:883242 发表于 2023-11-19 21:37 | 显示全部楼层
zhuls 发表于 2023-11-19 21:27
不一定哦~~
我曾经遇到过这样的错误:
单个文件都是对的,是在extern 引用时,因为类型不对,(变量声 ...

算了吧,驴唇不对马嘴。
回复

使用道具 举报

ID:1100542 发表于 2023-11-20 20:38 | 显示全部楼层
delay.h看看是不是声明少了个;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表