lcd1602同款操作方式,液晶显示屏显示基础知识,BLA,BLK两个针脚被隐藏了
BLA接VCC调节亮度,BLK接GND
BLA背光源正极
BLK背光源负极
h文件
c文件
#ifndef __LCD_H__
#define __LCD_H__
#include<reg51.h>
//VSS GND,VDD VCC,VEE接地对比度 10k电阻接地消除鬼影
sbit LCD_RS = P3^0;
sbit LCD_RW = P3^1;
sbit LCD_E = P3^2;
#define LCD_DATA P0
void lcd_busy();
void lcd_cmd(unsigned char cmd);
void lcd_write(unsigned char dat);
void lcd_dis(unsigned char *s);
unsigned char lcd_read();
unsigned char lcd_dispos(unsigned char row,unsigned char col);
#endif
#include<reg51.h>
#include<intrins.h>
#include "lcd.h"
unsigned char sta;
unsigned char pos;
void main(void){
lcd_cmd(0x01);//清屏
lcd_cmd(0x06);//指针自增
lcd_cmd(0x0C);//显示开,光标关
lcd_cmd(0x38);//8位接口,两行显示
lcd_cmd(0x80);//写地址
lcd_write('O');
lcd_write('K');
lcd_write('!');
while(1){
}
}
void lcd_busy(){
LCD_DATA = 0xFF;
LCD_RS = 0;//读状态(命令)
LCD_RW = 1;//读
do{
LCD_E = 1;//使能
sta = LCD_DATA;//会被其他途径赋值
LCD_E = 0;
}while((sta & 0x80) == 0x80);//判断命令最高位是1,表示忙
}
void lcd_write(unsigned char dat){
lcd_busy();
LCD_RS = 1;//数据
LCD_RW = 0;//写
LCD_DATA = dat;//准备
LCD_E = 1;//使能读写,写入
LCD_E = 0;//使不能
}
void lcd_cmd(unsigned char cmd){
lcd_busy();
LCD_RS = 0;//命令
LCD_RW = 0;//写
LCD_DATA = cmd;//准备
LCD_E = 1;//使能读写,写入
LCD_E = 0;//使不能
}
void lcd_dis(unsigned char *s){
while(*s){
lcd_write(*s++);
}
}
unsigned char lcd_dispos(unsigned char row,unsigned char col){
if(row == 0) {
pos = 0x80+col;
}else {
pos = 0xC0+col;
}
lcd_cmd(pos);
}
unsigned char lcd_read(){
lcd_busy();
LCD_DATA = 0xFF;
LCD_RS = 1;//数据
LCD_RW = 1;//读
LCD_E = 1;//使能
sta = LCD_DATA;//会被其他途径赋值
LCD_E = 0;
return sta;
}
|