lcd driver
June 9th, 2011
lcd driver:
#include<string.h>
#include<reg51.h>
#define LCD_clear() LCD_command(0x1) /* Clear display LCD */
#define LCD_origin() LCD_command(0x2) /* Set to origin LCD */
#define LCD_row1() LCD_command(0x80) /* Begin at Line 1 */
#define LCD_row2() LCD_command(0xC0)
sbit rs = P3^6;
sbit en = P3^7;
void lcd_en ()
{
en = 1; en = 1; en = 1;
en = 0; en = 0;
}
void LCD_delay(unsigned char ms)
{
unsigned char n;
unsigned int i;
for (n=0; n {
for (i=0; i<1535; i++); /* For 1 ms */
}
}
void LCD_command(unsigned char command)
{
rs=0; rs = 0;
P0 = command;
lcd_en ();
LCD_delay(1);
}
void LCD_init()
{
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x0c);
LCD_command(0x01);
LCD_delay(256);
}
void LCD_putc(unsigned char ascii)
{
rs=1;
P0 = ascii;
lcd_en ();
LCD_delay(2);
LCD_command(0x0C);
}
void LCD_puts(unsigned char *lcd_string)
{
while (*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
Related posts: