51单片机1602显示不出来,那里出问题了?
#include<reg52.h>#defineLCD1602_DBP0sbitLCD1602_RS=P1^0;sbitLCD1602_RW=P1^1;sbitLCD16...
#include <reg52.h>#define LCD1602_DB P0sbit LCD1602_RS = P1^0;sbit LCD1602_RW = P1^1;sbit LCD1602_E = P1^5;void InitLcd1602();void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);void main(){ unsigned char str[] = "guoFei"; InitLcd1602(); // x×ø±ê y×ø±ê ×Ö·û´®Ö¸ÕëÂë Ö¸Õë±äÁ¿ LcdShowStr(2, 0, str); LcdShowStr(0, 1, "1234"); EA=1; ET0=1; TR0=1; while(1); }void LcdWaitReady() //µÈ´ý ÅжÏÊÇ·ñæ{ unsigned char sta; LCD1602_DB = 0xFF; LCD1602_RS = 0; LCD1602_RW = 1; do { LCD1602_E = 1; sta = LCD1602_DB; LCD1602_E = 0; }while(sta & 0x80);}void LcdWriteCmd(unsigned char cmd) //дָÁî{ LcdWaitReady(); LCD1602_RS = 0; LCD1602_RW = 0; LCD1602_DB = cmd; LCD1602_E = 1; LCD1602_E = 0;}void LcdWriteDat(unsigned char dat) //дÊý¾Ý{ LcdWaitReady(); LCD1602_RS = 1; LCD1602_RW = 0; LCD1602_DB = dat; LCD1602_E = 1; LCD1602_E = 0;}void LcdSetCursor(unsigned char x, unsigned char y){ unsigned char addr; if(y == 0) addr = 0x00 + x; else addr = 0x40 + x; LcdWriteCmd(addr | 0x80);}void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str){ LcdSetCursor(x, y); while(*str != '\0') { LcdWriteDat(*str++); }}void InitLcd1602(){ ///³õʼ»¯ LcdWriteCmd(0x38); //ÉèÖÃ16¡Á2ÏÔʾ £¬ 5¡Á7µãÕó £¬8λÊý¾Ý½Ó¿Ú LcdWriteCmd(0x0C); LcdWriteCmd(0x06); LcdWriteCmd(0x01); //Çå0}
展开
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32是一种由意法半导体(STMicroelectronics)公司设计和生产的单片机系列,广泛用于嵌入式系统、物联网(IoT)设备、汽车电子、工业自动化等领域。STM32具有以下优点:1. 低功耗:STM32单片机通常具有较低的功耗,...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询