Download AN731

Transcript
AN731
/**************************************************************
** void lcd_send_byte( byte address, byte n )
**
** Writes the byte n to the address in address.
**
**************************************************************/
void lcd_send_byte( byte address, byte n )
{
set_tris_b(LCD_WRITE);// set TRIS bits for output
lcd.reg_sel = 0;
delay_us(50);
lcd.reg_sel = address;// select register to write
delay_cycles(1);
lcd.rd_w = 0;// set for writes
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);// write data byte in nibbles
lcd_send_nibble(n & 0xf);
TRISB=0xfd;
}
/**************************************************************
** void lcd_init(void)
**
** Initializes the LCD display.
**
**************************************************************/
void lcd_init()
{
byte i;
set_tris_b(LCD_WRITE);// set tris bits
lcd.reg_sel = 0;// select configuration
lcd.enable = 0;
delay_ms(15);
lcd_send_byte(0,0x28);// Write config info
lcd_send_byte(0,0x0C);
lcd_send_byte(0,0x01);
TRISB=0xfd;
}
/**************************************************************
** void lcd_gotoxy(byte x,byte y)
**
** Changes the cursor position to x,y.
**
**************************************************************/
void lcd_gotoxy( byte x, byte y)
{
byte address;
if(y!=1)
// Check for line 1 or 2
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);// Write cursor position
}
/**************************************************************
** void lcd_putc(char c)
**
** Writes the byte c to the current cursor position. Routine**
** detects form feeds, returns, and backspaces.
**
**************************************************************/
void lcd_putc( char c)
{
switch(c)
{
case ‘\f’:
// form feed
DS00731A-page 34
Preliminary
 2000 Microchip Technology Inc.