写出STC12C5A60S2单片机做一个在1602LED显示屏显示姓名学号的Kile5编程
时间: 2023-03-09 17:08:16 浏览: 268
答: 可以使用 STC12C5A60S2 单片机和 1602LED 显示屏来实现显示姓名学号的 Kile5 编程,可以使用以下程序: #include <reg51.h> #include <STC12C5A60S2.h> #define uint unsigned int #define uchar unsigned char sbit LCD_RS=P2^4; sbit LCD_RW=P2^5; sbit LCD_EN=P2^6; sbit LCD_D7=P2^7; sbit LCD_D6=P2^3; sbit LCD_D5=P2^2; sbit LCD_D4=P2^1; char code Table1[]="姓名:XXX"; char code Table2[]="学号:XXXXX"; delay_ms(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void LCD_Write_Command(uchar Command) { LCD_RS=0; LCD_RW=0; LCD_D7=Command&0x80; LCD_D6=Command&0x40; LCD_D5=Command&0x20; LCD_D4=Command&0x10; LCD_EN=1; delay_ms(2); LCD_EN=0; LCD_D7=Command<<4; LCD_D6=Command<<4; LCD_D5=Command<<4; LCD_D4=Command<<4; LCD_EN=1; delay_ms(2); LCD_EN=0; } void LCD_Write_Data(uchar Data) { LCD_RS=1; LCD_RW=0; LCD_D7=Data&0x80; LCD_D6=Data&0x40; LCD_D5=Data&0x20; LCD_D4=Data&0x10; LCD_EN=1; delay_ms(2); LCD_EN=0; LCD_D7=Data<<4; LCD_D6=Data<<4; LCD_D5=Data<<4; LCD_D4=Data<<4; LCD_EN=1; delay_ms(2); LCD_EN=0; } void LCD_Init(void) { LCD_Write_Command(0x38); delay_ms(5); LCD_Write_Command(0x08); delay_ms(5); LCD_Write_Command(0x01); delay_ms(5); LCD_Write_Command(0x06); delay_ms(5); LCD_Write_Command(0x0C); delay_ms(5); LCD_Write_Command(0x80); delay_ms(5); } void LCD_Write_String(uchar X,uchar Y,uchar *s) { uchar i=0; LCD_Write_Command(0x80|Y+X); while(s[i]!='\0') { LCD_Write_Data(s[i]); i++; } } void main(void) { LCD_Init(); LCD_Write_String(0,0,Table1); LCD_Write_String(1,0,Table2); }
阅读全文