Thư Viện Lcd
Thư Viện Lcd
h"
#include "string.h"
#include "stdio.h"
union reg {
struct bit {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
}_BIT;
unsigned char _BYTE;
};
union reg* P2_DIR=(union reg*)0x2a; //khai bao dia chi o nho
union reg* P2_OUT=(union reg*)0x29;
union reg* P2_SEL=(union reg*)0x2e;
union reg* P2_IN=(union reg*)0x28;
lcd_delay_us(20);
LCD_EN = 1;
lcd_delay_us(20);
LCD_EN = 0;
lcd_delay_us(20);
LCD_EN = 1;
lcd_delay_us(20);
LCD_EN = 0;
}
void lcd_init(void)
{
LCD_RS_DIR = 1;
LCD_EN_DIR = 1;
LCD_DATA_4_DIR = 1;
LCD_DATA_5_DIR = 1;
LCD_DATA_6_DIR = 1;
LCD_DATA_7_DIR = 1;
LCD_RS = 0;
LCD_EN = 0;
lcd_delay_ms(200);
lcd_put_byte(0,0x30);
lcd_delay_ms(50);
lcd_put_byte(0,0x30);
lcd_delay_ms(50);
lcd_put_byte(0,0x32);
lcd_delay_ms(200);
if(row!=0)
address=0x40;
else
address=0;
address += col;
lcd_put_byte(0,0x80|address);
lcd_delay_ms(2); // wait for LCD
}
void lcd_putc(char c)
{
switch(c){
case '\f':
lcd_put_byte(0, 0x01);
lcd_delay_ms(2); // wait for LCD
break;
case '\n':
lcd_gotoxy(0, 0x01);
break;
default:
lcd_put_byte(1, c);
lcd_delay_ms(2); // wait for LCD
break;
}
}
void lcd_puts(const char* s)
{
while(*s){
lcd_putc(*s++);
__delay_cycles(50000);
}
}
void lcd_3n(unsigned char x)
{ lcd_putc((x/100)+48);
lcd_putc(((x/10)%10)+48);
lcd_putc((x%10)+48); }