try using proteus. It simulates MCU + LCD quite nicely Here is a pic16f84a + 2x16 LCDa sample code in hi-tech cCode: [Select]/*LCD interfacing using 4-bit mode*/#include <pic.h>#include "delay.c"//configuration fuse__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);static bit LCD_RS @ ((unsigned)&PORTA*8+0); // Register selectstatic bit LCD_EN @ ((unsigned)&PORTA*8+1); // Enable#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))void lcd_write(unsigned char c){ PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}/* * Clear and home the LCD */void lcd_clear(void){ LCD_RS = 0; lcd_write(0x1); DelayMs(2);}/* write a string of chars to the LCD */void lcd_puts(const char * s){ LCD_RS = 1; // write characters while(*s) lcd_write(*s++);}/* write one character to the LCD */void lcd_putch(char c){ LCD_RS = 1; // write characters PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}/* * Go to the specified position */void lcd_goto(unsigned char pos){ LCD_RS = 0; lcd_write(0x80+pos);} /* initialise the LCD - put into 4 bit mode */void lcd_init(void){ LCD_RS = 0; // write control bytes DelayMs(15); // power on delay PORTB = 0x03; // attention! LCD_STROBE; DelayMs(5); LCD_STROBE; DelayUs(100); LCD_STROBE; DelayMs(5); PORTB = 0x02; // set 4 bit mode LCD_STROBE; DelayUs(40); lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font (0010 1000) lcd_write(0x08); // display off (0000 1000) lcd_write(0x0F); // display on, blink curson on lcd_write(0x06); // entry mode}void main(){ TRISA &= ~0x03; //RA2 & RA3 are output PORTA &= ~0x03; TRISB &= ~0x0F; //RB<3:0> are output PORTB &= ~0x0F; //RB<3:0> are low lcd_init(); //initialize LCD, set to 4-bit mode lcd_clear(); //clear LCD lcd_puts("abcde"); //display text in first line lcd_goto(0x40); //display text in second line lcd_puts("pogi si paranz"); while(1);}
/*LCD interfacing using 4-bit mode*/#include <pic.h>#include "delay.c"//configuration fuse__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);static bit LCD_RS @ ((unsigned)&PORTA*8+0); // Register selectstatic bit LCD_EN @ ((unsigned)&PORTA*8+1); // Enable#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))void lcd_write(unsigned char c){ PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}/* * Clear and home the LCD */void lcd_clear(void){ LCD_RS = 0; lcd_write(0x1); DelayMs(2);}/* write a string of chars to the LCD */void lcd_puts(const char * s){ LCD_RS = 1; // write characters while(*s) lcd_write(*s++);}/* write one character to the LCD */void lcd_putch(char c){ LCD_RS = 1; // write characters PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}/* * Go to the specified position */void lcd_goto(unsigned char pos){ LCD_RS = 0; lcd_write(0x80+pos);} /* initialise the LCD - put into 4 bit mode */void lcd_init(void){ LCD_RS = 0; // write control bytes DelayMs(15); // power on delay PORTB = 0x03; // attention! LCD_STROBE; DelayMs(5); LCD_STROBE; DelayUs(100); LCD_STROBE; DelayMs(5); PORTB = 0x02; // set 4 bit mode LCD_STROBE; DelayUs(40); lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font (0010 1000) lcd_write(0x08); // display off (0000 1000) lcd_write(0x0F); // display on, blink curson on lcd_write(0x06); // entry mode}void main(){ TRISA &= ~0x03; //RA2 & RA3 are output PORTA &= ~0x03; TRISB &= ~0x0F; //RB<3:0> are output PORTB &= ~0x0F; //RB<3:0> are low lcd_init(); //initialize LCD, set to 4-bit mode lcd_clear(); //clear LCD lcd_puts("abcde"); //display text in first line lcd_goto(0x40); //display text in second line lcd_puts("pogi si paranz"); while(1);}
kailangan mag-convert ng digits kung floating point binary yung pinapadala. pero kung per digit na ipapadala, kunin lang yung value sa port tapos kung ano mang alignment sa LCD ang gusto tapos i-command na.pwedeng gumawa ng character lookup table nung LCD or function na magco-convert ng ASCII to LCD characters kung masasagad yung Flash or EEPROM memory.
Hi mga master, kailangan ko gumamit ng lcd display pero wala akong idea pano. May massuggest ba kayong materials na pwede aralin para makagamit ako ng lcd (meron ako 4x20 lcd)? Links or kahit turuan niyo ko, ayos lang po. Thank you!