LCD1602突然只能显示数字,不能显示字母,显示字母突然出错。跪求大神解释原因:#include "C8051F120.h"
#include"stdio.h"
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS = P2^0; //复位端
sbit LCD_RW = P2^1; //写数据端
sbit LCD_EP = P2^2; //使能端
void delay_1ms(uint z) //延时z*1ms
{
uint x,y;
for(x=z; x>0; x--)
for(y=1696; y>0; y--);
}
/****************侧忙函数,读状态************************/
void lcd_bz()// 测试LCD忙碌状态
{
LCD_RS = 0;
LCD_RW = 1;
LCD_EP = 1; //EP代表的是DB7,输入使能信号,当其变为1代表不忙
delay_1ms(2);
while((P1 & 0x80));
LCD_EP = 0;
}
/****************写命令函数************************/
lcd_wcmd(uchar cmd)
{
lcd_bz(); //当不忙时
LCD_RS = 0;
LCD_RW = 0;
LCD_EP = 0;
delay_1ms(1);
P1 = cmd; //将8位指令通过P0口传给1602
delay_1ms(1);
LCD_EP = 1;
delay_1ms(1);
LCD_EP = 0;
}
/****************写数据函数************************/
char putchar(uchar dat) //没有将返回值送回,故存在一个警告
{
lcd_bz(); //当不忙时
LCD_RS = 1;
LCD_RW = 0;
LCD_EP = 0;
delay_1ms(1);
P1 = dat; //将8位指令通过P0口传给1602
delay_1ms(1);
LCD_EP = 1;
delay_1ms(1);
LCD_EP = 0;
return(0) ;
}
/****************写地址函数************************/
void gotoxy (uchar y ,uint x )//置光标于y行,X列
{
switch(y)
{
case 0 : x=x+0x80;break;
case 1 : x=x+0x40+0x80; break; //1602,第二行的位置
default : break;
}
lcd_wcmd(x);
}
/****************初始化LCD1602函数************************/
lcd_init()
{
lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
delay_1ms(1);
lcd_wcmd(0x0c); //显示开,关光标
delay_1ms(1);
lcd_wcmd(0x06); //移动光标
delay_1ms(1);
lcd_wcmd(0x01); //清除LCD的显示内容
delay_1ms(80);
}
void Port_IO_Init()
{
SFRPAGE = CONFIG_PAGE;
XBR2 = 0x40;
}
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for ini
tialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
OSCICN &= ~0x80;
}
void Init_Device(void)
{
Port_IO_Init();
Oscillator_Init();
Reset_Sources_Init();
lcd_init();
}
void main()
{
float c=1.23569;
Init_Device();
delay_1ms(2);
gotoxy(0 ,1 ); //第一个字符决定行,第二个字符决定位置
delay_1ms(10) ;
printf("abcddef"); //printf 跟 putchar 函数配合使用,输出字符,为最简单的字符输出
gotoxy(1,2 ); //第一个字符决定行,第二个字符决定位置
printf("wen=%6.4f",c) ;//输出的结果为wen=1.2357
while(1);
}
一周热门 更多>