选择51单片机(AT89C51),再选一个显示设备(AMPIRE12864),动态滚动显示自己的姓名中文(王瑞媛)和学号(202006084242)的keil代码#include <reg51.h> #define LCDLCDDisp_Off 0x3e #define LCDLCDDisp_On 0x3f #define Page_Add 0xb8 #define LCDCol_Add 0x40 #define Start_Line 0xC0 #define data_ora P1 sbit LCDMcs=P2^4 ; sbit LCDScs=P2^3 ; sbit LCDDi=P2^2 ; sbit LCDRW=P2^1 ; sbit LCDEnable=P2^0 ;
时间: 2024-03-22 13:42:48 浏览: 64
好的,这是您的代码:
```c
#include <reg51.h>
#include <string.h>
#define LCDLCDDisp_Off 0x3e
#define LCDLCDDisp_On 0x3f
#define Page_Add 0xb8
#define LCDCol_Add 0x40
#define Start_Line 0xC0
#define data_ora P1
sbit LCDMcs = P2^4;
sbit LCDScs = P2^3;
sbit LCDDi = P2^2;
sbit LCDRW = P2^1;
sbit LCDEnable = P2^0;
void delayms(int ms) {
int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 120; j++) {
;
}
}
}
void WriteCommand(unsigned char Command) {
LCDDi = 0;
data_ora = Command;
LCDEnable = 1;
LCDEnable = 0;
}
void WriteData(unsigned char Data) {
LCDDi = 1;
data_ora = Data;
LCDEnable = 1;
LCDEnable = 0;
}
void InitLCD(void) {
WriteCommand(LCDLCDDisp_Off);
delayms(5);
WriteCommand(LCDLCDDisp_On);
delayms(5);
WriteCommand(Page_Add);
WriteCommand(LCDCol_Add);
WriteCommand(Start_Line);
}
void DispChs(unsigned char x, unsigned char y, unsigned char *p) {
unsigned char i;
x = LCDCol_Add + x*16;
y = Page_Add + y;
WriteCommand(y);
WriteCommand(x);
for (i = 0; i < 16 && *p; i++, p++) {
WriteData(*p);
}
}
void main() {
unsigned char name[] = "王瑞媛";
unsigned char number[] = "202006084242";
unsigned char i;
InitLCD();
while (1) {
DispChs(0, 0, name);
DispChs(0, 1, number);
for (i = 0; i < 16; i++) {
WriteCommand(Start_Line + i);
delayms(500);
}
}
}
```
注意,这段代码假设您已经将 AMPIRE12864 连接到了 P1 端口上。如果您的硬件连接不同,请自行修改相应的代码。
此代码会在屏幕上不断滚动显示您的姓名和学号,每行显示 16 个字符,并且每隔 500ms 滚动一行。
阅读全文