This document contains code for routines to interface with a serial LCD display using a PIC microcontroller. It includes functions for initialization, delay, string output, hexadecimal and decimal number output, and character output to the LCD.
This document contains code for routines to interface with a serial LCD display using a PIC microcontroller. It includes functions for initialization, delay, string output, hexadecimal and decimal number output, and character output to the LCD.
// // This is a collection of routines to interface with a PIC-n-LCD // or similar serial LCD capable of 9600 baud, inverted, no parity. // // 16F84 PIC-n-LCD // // RA0 (term 17) ---------------> Serin In (term 3) // // void delay_ms(long t); // delays for t ms // void delay_10us(int t); // delays for t * 10 us // void lcd_init(void); // inits PIC-n-LCD, sends 0x0c with a delay // void out_RAM_str(int *s); // output null terminated str // void lcd_hex_byte(int val); // output val in two digit hex // void lcd_dec_byte(int val, int digits); // output val in dec to significant figures specified // by digits. For example, if val is 014, specifying // digits as 3, will cause "014". Specifying digits as 2 // will cause "14" and specifying digits as 1 will cause // "4" // int num_to_char(int val); // converts val in range of // 0 - 15 to hex character // void lcd_char(int c); // outputs character c, 9600 baud, inverted // void lcd_new_line(void); // outputs 0x0d, 0x0a
// copyright, Peter H. Anderson, Mecklenburg CO, VA , MD, Mar, '99
void lcd_new_line(void) // outputs 0x0d, 0x0a { lcd_char(0x0d); delay_ms(10); // give the PIC-n-LCD time to perform the lcd_char(0x0a); // new line function delay_ms(10); }
void lcd_hex_byte(int val) // displays val in hex format { int ch; ch = num_to_char((val>>4) & 0x0f); lcd_char(ch); ch = num_to_char(val&0x0f); lcd_char(ch); }
void lcd_dec_byte(int val, int digits) // displays byte in decimal as either 1, 2 or 3 digits { int d; int ch; if (digits == 3) { d=val/100; ch=num_to_char(d); lcd_char(ch); } if (digits >1) // take the two lowest digits { val=val%100; d=val/10; ch=num_to_char(d); lcd_char(ch); } if (digits == 1) // take the least significant digit { val = val%100; }