Electronics > Beginners

lcd, C and pic

(1/3) > >>

Zedy:
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=output
TRISA = 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 set
LCD_EN = 1;
LCD_EN = 0;
                lcd_port = 0x08;
LCD_EN = 1;
LCD_EN = 0;

__delay_ms(10);

        lcd_port = 0x02;   //Function set
LCD_EN = 1;
LCD_EN = 0;
                lcd_port = 0x08;
LCD_EN = 1;
LCD_EN = 0;

__delay_ms(10);

lcd_port = 0x00;   //Display on/off
LCD_EN = 1;
LCD_EN = 0;
                lcd_port = 0x08;
LCD_EN = 1;
LCD_EN = 0;

__delay_ms(10);

lcd_port = 0x00;   //Display Clear
LCD_EN = 1;
LCD_EN = 0;
                lcd_port = 0x01;
LCD_EN = 1;
LCD_EN = 0;

__delay_ms(10);

lcd_port = 0x00; //Entry Mode set
LCD_EN = 1;
LCD_EN = 0;
lcd_port = 0x06;  
LCD_EN = 1;
LCD_EN = 0;

__delay_ms(10);

     while(1)
            {
             }
}

--- End code ---


What is going on?   ???  :)

alm:
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.

Simon:
have you setup your registers correctly

Zedy:

--- Quote from: alm on August 22, 2010, 04:39:09 pm ---is there anything else on PORTC that might conflict, like programming pins, reset pin or crystal pins? Check the datasheet for your PIC.

--- End quote ---

There 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 pm ---have you setup your registers correctly

--- End quote ---

I 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.

migsantiago:
Hello Zedy

You 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 pic
--- End code ---

And 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.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod