翻译C语言 #include "include.h" #define DataPort P0 sbit RS=P3^3; sbit RW=P3^2; sbit EN=P3^5; void lcdDelay(unsigned int m) //延时程序,微妙级 { while(m--) { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } } void lcdBuzy() { DataPort=0xff; RW=1; RS=0; EN=1; while(DataPort&0x80); EN=0; } void lcdTransferData(char data1,bit DI) //传送数据或者命令,当DI=0,传送命令,当DI=1,传送数据. { lcdBuzy(); RW=0; RS=DI; DataPort=data1; EN=1; EN=0; } void lcdDingwei(unsigned char line,unsigned char row) //定位在哪行哪列显示 { unsigned int i; switch(line) { case 1: i=0x80+row;break; case 2: i=0x90+row;break; case 3: i=0x88+row;break; case 4: i=0x98+row;break; default: i=0x80;break; } lcdTransferData(i,0); lcdDelay(1); } void lcdMsg(unsigned char *addr,unsigned char line,unsigned char row) //传送一个字符串 { lcdDingwei(line,row); while(*addr>0) { lcdTransferData(*addr,1); addr++; } } //void lcdDisplayonechar(unsigned int data2) //传送一个字符 //{ // lcdTransferData(data2,1);//写要显示的数据 //} void lcdInitinal(void) //LCD字库初始化程序 { lcdTransferData(0x30,0); //8BIT设置,RE=0: basic instruction set lcdTransferData(0x08,0); //Display on Control lcdTransferData(0x10,0); //Cursor Display Control光标设置 lcdTransferData(0x0C,0); //Display Control,D=1,显示开 lcdTransferData(0x01,0); //Display Clear }
时间: 2024-04-26 10:23:25 浏览: 8
这段代码是一个控制LCD显示屏的程序,使用C语言编写。其中包含了LCD显示屏的初始化程序、延时程序、传送数据或命令的函数、定位显示位置的函数、传送字符串的函数等。具体的函数实现细节请看注释。
其中,`#include "include.h"` 是包含头文件的指令,`#define DataPort P0` 定义了一个宏,将P0端口命名为DataPort。`sbit RS=P3^3;`、`sbit RW=P3^2;`、`sbit EN=P3^5;` 定义了三个位变量,分别代表LCD的RS、RW、EN三个引脚。
相关问题
#include<reg52.h> #define DataPort P0; sbit LATCH2=P2^2; sbit LATCH1=P2^3; unsigned char code zima[]={0x76,0x73,0x38,0x38,0x7f}; unsigned char code wm[]={0xfe,0xfd,0xfb,0xf7,0xef}; void delay(unsigned int t); void main() { unsigned char i=0; while(1){ DataPort=wm[i]; LATCH2=1; LATCH2=0; DataPort=zima[i]; LATCH1=1; LATCH1=0; delay(20); i++; if(i==5) i=0; } } void Delay(unsigned int t) { while(--t); } 哪里错了
这段代码中有几个问题:
1. 在 `#define DataPort P0;` 这一行中,应该将分号(;)去掉,否则会导致后续使用 `DataPort` 宏时出现语法错误。
2. `void Delay(unsigned int t)` 函数名称大小写不一致,应该统一为 `delay`。
3. `delay` 函数中的 `while(--t);` 应该改为 `while(--t) ;`,添加一个空格以避免编译器误解为语句结束。
4. 在 `void main()` 函数中,应该添加 `Delay(20);` 语句,以调用 `delay` 函数。
下面是修改过的代码:
```C
#include<reg52.h>
#define DataPort P0
sbit LATCH2 = P2^2;
sbit LATCH1 = P2^3;
unsigned char code zima[] = {0x76,0x73,0x38,0x38,0x7f};
unsigned char code wm[] = {0xfe,0xfd,0xfb,0xf7,0xef};
void delay(unsigned int t);
void main() {
unsigned char i = 0;
while(1) {
DataPort = wm[i];
LATCH2 = 1;
LATCH2 = 0;
DataPort = zima[i];
LATCH1 = 1;
LATCH1 = 0;
Delay(20);
i++;
if (i == 5) i = 0;
}
}
void delay(unsigned int t) {
while(--t) ;
}
```
希望这可以帮助您解决问题。
将本段C语言代码转换为流程图#include<reg52.h> #define DataPort P0 sbit SM_COM=P2^0; sbit SM_SEG=P2^1; sbit LCD1602=P1^2; unsigned char code SEG_DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; unsigned char code SEG_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; void Delay(unsigned int t); main() { unsigned char i=0; LCD1602=0; while(1) { DataPort=0; SM_SEG=1; SM_SEG=0; DataPort=SEG_WeiMa[i]; SM_COM=1; SM_COM=0; DataPort=SEG_DuanMa[i]; SM_SEG=1; SM_SEG=0; Delay(200); i++; if(8==i) i=0; } } void Delay(unsigned int t) { while(--t); }
以下为该C语言代码的流程图:
![flowchart](https://img-blog.csdn.net/20180529142050108?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xhbmR5X3Npbmdo/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)