?? 1602b_lcd.c
字號:
/**********************************************************
TC1602B LCD DISPLAY WITH 4 BITS MODE
建立時間:2004年12月10號
修改日期:2005年1月12號
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第二行顯示寄存器地址:0XC0-0XCF
**********************************************************/
#include <At89x51.h>
#include "1602B_LCD.h"
//--------------------------------------------------------
#define LCD_DATA_PORT P3
sbit LCD_EN=P3^4;
sbit LCD_RS=P3^5;
//--------------------------------------------------------
typedef unsigned char uchar;
code char Numtable[]="0123456789ABCDEF ";
//--------------------------------------------------------
void delay_nms(char i){for(;i>0;i--);}
//--------------------------------------------------------
void LCD_WR4bits(unsigned char c){
//c<<=4;
//unsigned char i=0x01,j=0x80,k=0;
//for(;i<0x10;i<<=1,j>>=1){
// if(c&i)k|=j;
//}
LCD_EN=1;
//LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT&=0xf0;
LCD_DATA_PORT|=c;
//LCD_DATA_PORT|=k;
LCD_EN=0;
}
//--------------------------------------------------------
void LCD_init(void){
/* delay_nms(50);
LCD_RS=0; //command
LCD_WR4bits(0x03); //set 8 bits
delay_nms(10);
LCD_WR4bits(0x03); //set 8 bits
delay_nms(10);
LCD_WR4bits(0x03); //set 8 bits
delay_nms(10);
LCD_WR4bits(0x02); //set 4 bits
LCD_WR4bits(0x08);
delay_nms(2);
LCD_WR4bits(0x00); //顯示開
LCD_WR4bits(0x0c);
delay_nms(2);
LCD_WR4bits(0x00); //光標設定
LCD_WR4bits(0x06);
delay_nms(2);
LCD_RS=1; //data
delay_nms(10);
*/
delay_nms(250);
LCD_RS=0; //command
LCD_WR4bits(0x02); //set 4 bits
delay_nms(50);
LCD_WR4bits(0x08); //2 Lines,disp off
delay_nms(50);
LCD_WR4bits(0x00); //顯示開
LCD_WR4bits(0x0c); //cursor off,blink off
delay_nms(50);
LCD_WR4bits(0x00); //clean all
LCD_WR4bits(0x01);
delay_nms(5);
LCD_WR4bits(0x00); //inc mode,shift off
LCD_WR4bits(0x06);
LCD_RS=1; //data
}
/*--------------------------------------------------------
LCD_set_xy : 設置LCD顯示的起始位置
輸入參數:x、y : 顯示字符串的位置,X:0-15,Y:0-1
--------------------------------------------------------*/
void LCD_set_xy( uchar x, uchar y ){
x=(y==0)?0x80+x:0xc0+x;
LCD_RS=0;
LCD_WR4bits(x>>4);
LCD_WR4bits(x);
LCD_RS=1;
}
//----------------------------------------------------
void LCD_char(uchar c){
LCD_WR4bits(c>>4);
LCD_WR4bits(c);
delay_nms(2);
}
/*----------------------------------------------------
LCD_write_string : 英文字符串顯示函數
輸入參數:*s :英文字符串指針;
X、Y : 顯示字符串的位置
----------------------------------------------------*/
void LCD_write_string(uchar X,uchar Y,uchar *s){
LCD_set_xy( X, Y );
while(*s)LCD_char(*s++);
}
//----------------------------------------------------
void LCD_digtal(uchar c){
LCD_WR4bits(Numtable[c]>>4);
LCD_WR4bits(Numtable[c]);
delay_nms(2);
}
//----------------------------------------------------
void LCD_clear(void){
LCD_RS=0;
delay_nms(2);
LCD_WR4bits(0x00);
LCD_WR4bits(0x01);
delay_nms(2);
LCD_RS=1;
delay_nms(10);
}
//----------------------------------------------------
void LCD_home(void){
LCD_RS=0;
delay_nms(2);
LCD_WR4bits(0x00);
LCD_WR4bits(0x02);
delay_nms(2);
LCD_RS=1;
delay_nms(10);
}
//----------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -