?? lcd.c
字號(hào):
#include <reg52.h>
#include <lcd.h>
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
void DelayUs(unsigned char cnt) reentrant
{
while(cnt!=0)
{cnt--;}
}
void DelayMs(unsigned char cnt) reentrant //延時(shí)1ms,使用12M晶振
{
unsigned char i;
do {
i = 4;
do {
DelayUs(250);
} while(--i);
} while(--cnt);
}
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c) reentrant
{
P1 = (P1 & 0xF0) | (c >> 4);
LCD_STROBE;
P1 = (P1 & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}
/*
* Clear and home the LCD
*/
void
lcd_clear(void) reentrant
{
LCD_RS = 0;
lcd_write(0x1);
DelayMs(2);
}
/* write a string of chars to the LCD */
void
lcd_puts(const char * s) reentrant
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
/* write one character to the LCD */
void
lcd_putch(char c) reentrant
{
LCD_RS = 1; // write characters
P1 = (P1 & 0xF0) | (c >> 4);
LCD_STROBE;
P1 = (P1 & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}
/*
* Go to the specified position
*/
void
lcd_goto(unsigned char pos) reentrant
{
LCD_RS = 0;
lcd_write(0x80+pos);
}
/* initialise the LCD - put into 4 bit mode */
void
lcd_init(void) reentrant
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
P1 = 0x3; // attention!
LCD_STROBE;
DelayMs(5);
LCD_STROBE;
DelayUs(100);
LCD_STROBE;
DelayMs(5);
P1 = 0x2; // set 4 bit mode
LCD_STROBE;
DelayUs(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x0c); // display on, blink curson off
lcd_write(0x06); // entry mode
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -