烧写程序给板子上电之后,1602只显示这一行白块,应该不是对比度的问题?因为调可调电阻只是亮度变了下,程序在proteus上仿真是能实现运行的,大佬们帮忙看看,本人小白不太懂。。
单片机源程序如下:
- #include <reg52.h>
- unsigned long int fre;
- unsigned char time;
- unsigned int count;
- unsigned int count1;
- sbit LCD_RS=P1^0; //片选信号
- sbit LCD_RW=P1^1; //读写信号
- sbit LCD_E=P1^2; //使能信号
- #define LCD_DB P0 //数据信号
- unsigned char character[10]={0};//在屏幕上显示的字符串
- unsigned char character_1[]={"fre= Hz"};
- unsigned char FLAG = 0; //是否分频选择标志
- void LCD_init(void);//初始化函数
- void LCD_write_command(unsigned char command);//写指令函数
- void LCD_write_data(unsigned char dat);//写数据函数
- void LCD_disp_char(unsigned char x,unsigned char y,unsigned char dat);//在某个屏幕位置上显示一个字符,X(0-15),y(1-2)
- void delay_n40us(unsigned int n);//延时函数
- void timer_init(); //中断初始化函数
- //-----------------------------延时函数---------------------------
- void delay_n40us(unsigned int n) //延时函数
- {
- unsigned int i;
- unsigned char j;
- for(i=n;i>0;i--)
- for(j=0;j<2;j++);
- }
- void delay_1s()
- {
- unsigned int i,j;
- for(i = 0;i<100;i++)
- for(j = 0;j<1000;j++);
- }
- //---------------------lcd1602液晶显示函数--------------------
- void LCD_init(void) //液晶初始化函数
- {
- LCD_write_command(0x38);//设置8位格式,2行,5x7
- LCD_write_command(0x38);//设置8位格式,2行,5x7
- LCD_write_command(0x38);//设置8位格式,2行,5x7
- LCD_write_command(0x38);//设置8位格式,2行,5x7
- LCD_write_command(0x0c);//整体显示,关光标,不闪烁
- LCD_write_command(0x06);//设定输入方式,增量不移位
- LCD_write_command(0x01);//清除屏幕显示
- LCD_write_command(0x80);//数据指针起点
- delay_n40us(100);//清屏延时
- }
- void LCD_write_command(unsigned char dat) //写命令函数
- {
- LCD_DB=dat;
- LCD_RS=0;//指令
- LCD_RW=0;//写入
- LCD_E=1; //使能
- LCD_E=0;
- delay_n40us(1);//写命令延时
- }
- void LCD_write_data(unsigned char dat) //写数据函数
- {
- LCD_DB=dat;
- LCD_RS=1;//数据
- LCD_RW=0;//写入
- LCD_E=1;//使能
- LCD_E=0;
- delay_n40us(1); //写数据延时
- }
- void LCD_disp_char(unsigned char x,unsigned char y,unsigned char dat)//显示一个字符
- {
- unsigned char address;
- if(y==1)
- address=0x80+x; //显示在第一排的时候的x的地址
- else
- address=0xc0+x; //显示在第二排的时候的x的地址
- LCD_write_command(address); //输入地址
- LCD_write_data(dat); //输入数据
- }
- void LCD_disp_num(unsigned char x,unsigned char y,unsigned char dat)//显示一个数字
- {
- unsigned char address;
- if(y==1)
- address=0x80+x; //显示在第一排的时候的x的地址
- else
- address=0xc0+x; //显示在第二排的时候的x的地址
- LCD_write_command(address); //输入地址
- LCD_write_data(dat+48); //输入数据
- }
- void dis_num(void)
- {
- unsigned char i=0,j=0,k=0;
- LCD_write_command(0x01);//清除屏幕显示
- character[0] = fre/10000000;
- character[1] = fre/1000000%10;
- character[2] = fre/100000%10;
- character[3] = fre/10000%10;
- character[4] = fre/1000%10;
- character[5] = fre/100%10;
- character[6] = fre/10%10;
- character[7] = fre%10;
- character[8] = 'H';
- character[9] = 'z';
- for(i = 0;i<4;i++) //显示“fre=”
- {
- LCD_disp_char(i+0,1,character_1[i]);
- }
- for(i = 0;i<10;i++) //判断第一个不为0的数
- {
- if(character[i]!=0)
- break;
- }
- k = 8-i;
- for(j = 0;j<k;j++) //显示所有的数字
- {
- LCD_disp_num(4+j,1,character[i++]);
- }
- for(i = 5;i<7;i++) //显示“Hz”
- {
- LCD_disp_char(j+4,1,character_1[i]);
- j++;
- }
- }
复制代码
|