lcd, C and pic - Page 1
Forum section: electronics / beginners

author: Zedy
author_rank: Contributor
timestamp: August 22, 2010, 04:06:47 pm
content: Hi, I am working right now on my lcd project, and I have some problem with lcd initialization:After this peace of code, LCD just don't work, but if I change LCD_EN to portB pin (in softwere and hardwere) all works fine. Any help would be appreciated.(pic microcontroller: PIC16F677, LCD module 8x2)Code:#include <htc.h>#define _XTAL_FREQ 4000000#define lcd_port PORTC#define LCD_EN RC4#define LCD_RS RC5__CONFIG(INTIO & WDTDIS & PWRTDIS & MCLREN & UNPROTECT & BORDIS & IESODIS & FCMDIS);void init(void){// port directions: 1=input, 0=outputTRISA = 0b00000000;TRISB = 0b00000000;TRISC = 0b00000000;}void main(void){init();lcd_port = 0x00;__delay_ms(50);lcd_port = 0x03;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);lcd_port = 0x02; //Function setLCD_EN = 1;LCD_EN = 0;lcd_port = 0x08;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);lcd_port = 0x02; //Function setLCD_EN = 1;LCD_EN = 0;lcd_port = 0x08;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);lcd_port = 0x00; //Display on/offLCD_EN = 1;LCD_EN = 0;lcd_port = 0x08;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);lcd_port = 0x00; //Display ClearLCD_EN = 1;LCD_EN = 0;lcd_port = 0x01;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);lcd_port = 0x00;//Entry Mode setLCD_EN = 1;LCD_EN = 0;lcd_port = 0x06;LCD_EN = 1;LCD_EN = 0;__delay_ms(10);while(1){}}What is going on?

author: Unknown
author_rank: Unknown
timestamp: August 22, 2010, 04:39:09 pm
content: You should use code tags (button with hash/pound/number sign) to make the C code more readable. I'm not a PIC person, but is there anything else on PORTC that might conflict, like programming pins, reset pin or crystal pins? Check the datasheet for your PIC.

author: Simon
author_rank: Unknown
timestamp: August 22, 2010, 05:07:25 pm
content: have you setup your registers correctly

author: Zedy
author_rank: Contributor
timestamp: August 22, 2010, 05:42:41 pm
content: Quote from: alm on August 22, 2010, 04:39:09 pmThere is nothing else, just pic and LCD module, the only thing about PORTC, some of the pins are part of compartors and analog pins, but I use them only like output pins.Quote from: Simon on August 22, 2010, 05:07:25 pmI think so, but I also have trayed to disable other functions of the pins in softwere. Nothing changes, it just don't work if lcd enable pin is connected to the same port.

author: migsantiago
author_rank: Frequent Contributor
timestamp: August 22, 2010, 07:26:04 pm
content: Hello ZedyYou should tell the HiTech compiler which pic you're using...Code:#include <htc.h>// Required to interface with delay routines#include <pic12f683.h> //modify this with your picAnd be careful when using lcd_port, because you're actually modifying the 8 bits of the port at the same time... including RC4 and RC5, which should not be changed.I'd recommend using that LCD on a 4bit mode and whenever you want to send a 4 bit command or data, be sure not to modify the other RCx pins.In order to do that you'll have to use AND, OR or XOR masks.Ohh and there is a pre-built LCD library with Hitech, just search for it in the installation paths.

author: Zedy
author_rank: Contributor
timestamp: August 22, 2010, 08:58:58 pm
content: Quote from: migsantiago on August 22, 2010, 07:26:04 pmI have 9.70 HiTech compiler version.Quote from: migsantiago on August 22, 2010, 07:26:04 pmThanks! I have found LCD library, and with little code modification it works very nice!

author: migsantiago
author_rank: Frequent Contributor
timestamp: August 22, 2010, 10:19:32 pm
content: No, it doesn't matter what version you're using, it's always recommended to include the header file for the specific PIC you are using...Code:#include <pic12f683.h> //modify this with your picCongratulations on your first LCD project!

author: Simon
author_rank: Unknown
timestamp: August 23, 2010, 06:47:15 am
content: yea I'm hoping to do something with LCD's soon just got to get one project up and running

author: Zedy
author_rank: Contributor
timestamp: August 23, 2010, 04:55:13 pm
content: Quote from: migsantiago on August 22, 2010, 10:19:32 pmThanks!I have included header for my pic, so now all seems to be right.Quote from: Simon on August 23, 2010, 06:47:15 amIt was really painful process for me, I spant almost month just trying understand how lcd module works

author: FreeThinker
author_rank: Frequent Contributor
timestamp: September 09, 2010, 06:18:10 pm
content: Hi, Have a read of thishttp://www.epemag.wimborne.co.uk/resources.htmThe LCD pdf's are a Good read. Hope they help

author: Zedy
author_rank: Contributor
timestamp: September 09, 2010, 08:06:26 pm
content: Quote from: FreeThinker on September 09, 2010, 06:18:10 pmThe links to LCD pdf's are broken.

author: djsb
author_rank: Super Contributor
timestamp: September 09, 2010, 10:19:43 pm
content: http://www.wizard.org/auction_support/lcd1.pdfhttp://www.wizard.org/auction_support/lcd2.pdfHTHDavid.