Lcd Con Solo 3 Pines
Click here to load reader
Transcript of Lcd Con Solo 3 Pines
LCD con sólo 3 pinesLunes, 30 de Noviembre de 2009 12:03
Esta útil librería permite gestionar un LCD 2x16 compatible HD44780 con sólo 3 pines de tumicro, utilizando un registro de desplazamiento.
Es una modificación a la conocida Flex_LCD realizada por los amigos Akenafab yDuende_Azul.
Los pines utilizados son:
LCD_E: señal de control Enable del LCD
LCD_CK: señal de reloj del registro de desplazamiento
LCD_DAT: salida del bit menos signficativo hacia el registro de desplazamiento
1 / 2
LCD con sólo 3 pinesLunes, 30 de Noviembre de 2009 12:03
Este es el código de la librería:// flex_lcd_3_pins.c//Modificación de Flex_lcd por Duende_Azul y Akenafab//Trabaja con 3 pines y 74VHC164//8-Bit Serial-In, Parallel-Out Shift Register//La LCD se usa en modo 4bits//Revisar diagrama de conexion Adjunto//Se ha utilizado a una velocidad de @40MHz sin ningun problema//No esta habilitada la lecturadel LCD//RW debe ir a gnd//Definir pines antes de llamar libreria////#define LCD_E PIN_A0//#define LCD_CK PIN_A1 //#define LCD_DAT PIN_A2//========================================int RS_bit;#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines#define lcd_line_two 0x40 // LCD RAM address for the 2nd lineint8 const LCD_INIT_STRING[4] ={ 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots 0xc, // Display on 1, // Clear display 6 // Increment cursor };//-------------------------------------void lcd_send_nibble(int8 nibble, int rs_bit){int x;if(RS_bit==1) nibble=nibble|0x10;for(x=0;x<5;x++){ output_bit(LCD_DAT,shift_right(&nibble,1,0)); delay_cycles(1); output_low(LCD_CK); delay_us(1); output_high(LCD_CK);} output_high(LCD_E); delay_us(2); output_low(LCD_E);}//-----------------------------------//----------------------------------------// Send a byte to the LCD.void lcd_send_byte(int8 address, int8 n){//output_low(LCD_RS);RS_bit=0;delay_us(100);if(address) //output_high(LCD_RS); RS_bit=1;else //output_low(LCD_RS); RS_bit=0; delay_cycles(1);output_low(LCD_E);lcd_send_nibble(n >> 4,RS_bit);lcd_send_nibble(n & 0xf,RS_bit);}//----------------------------void lcd_init(void){int8 i;//output_low(LCD_RS);RS_bit=0;output_low(LCD_E);delay_ms(20);for(i=0 ;i < 3; i++) { lcd_send_nibble(0x03,RS_bit); delay_ms(5); }lcd_send_nibble(0x02,RS_bit);for(i=0; i < sizeof(LCD_INIT_STRING); i++) { lcd_send_byte(0, LCD_INIT_STRING[i]); delay_ms(5); }}//----------------------------void lcd_gotoxy(int8 x, int8 y){int8 address;if(y != 1) address = lcd_line_two;else address=0;address += x-1;lcd_send_byte(0, 0x80 | address);}//-----------------------------void lcd_putc(char c){ switch(c) { case 'f': //limpia pantalla lcd_send_byte(0,1); delay_ms(8); break; case 'n': //cambio de linea lcd_gotoxy(1,2); break; case 'b': //retrocede 1 caracter lcd_send_byte(0,0x10); break; default: lcd_send_byte(1,c); break; }}//------------------------------void lcd_setcursor_vb(short visible, short blink) { lcd_send_byte(0, 0xC|(visible<<1)|blink); } Y este un código ejemplo que la utiliza:#include <16F88.h>#FUSESINTRC_IO,NOWDT,PUT,MCLR,NOBROWNOUT,NOLVP,NOPROTECT,NODEBUG,CCPB0,NOFCMEN,NOIESO#use delay(Internal=8M)//------------ Pines del LCD ---------------------//#define LCD_E PIN_A0#define LCD_CK PIN_A1 #define LCD_DAT PIN_A2//--------------------------------------------------//#include "flex_lcd_3pins.c" // Cargamos libreriadel lcdvoid main(){delay_ms(100); output_a(0); output_b(0); lcd_init(); // inicializamos el LCD lcd_setcursor_vb(1,1); //cursor visible,papadeowhile(1){ printf(lcd_putc,"f-LCD 3pin Mode-n* !.|.|..|.|.! *"); delay_ms(1000); printf(lcd_putc,"f* Duende_Azul *n * Akenafab *"); delay_ms(1000); }//end while }//end mainPuedes descargar aquí un arhivo ZIP que contiene:- código fuente- librería- esquemático- simulación en Proteus.Que la disfrutes.
2 / 2