Author Topic: lcd, C and pic  (Read 6308 times)

0 Members and 1 Guest are viewing this topic.

Offline Zedy

  • Contributor
  • Posts: 26
lcd, C and pic
« on: August 22, 2010, 04:06:47 pm »
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: [Select]
#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)
            {
             }
}


What is going on?   ???  :)
« Last Edit: August 22, 2010, 05:16:55 pm by Zedy »
 

alm

  • Guest
Re: lcd, C and pic
« Reply #1 on: August 22, 2010, 04:39:09 pm »
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.
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 14763
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: lcd, C and pic
« Reply #2 on: August 22, 2010, 05:07:25 pm »
have you setup your registers correctly
 

Offline Zedy

  • Contributor
  • Posts: 26
Re: lcd, C and pic
« Reply #3 on: August 22, 2010, 05:42:41 pm »
is there anything else on PORTC that might conflict, like programming pins, reset pin or crystal pins? Check the datasheet for your PIC.

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.

have you setup your registers correctly

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.
« Last Edit: August 22, 2010, 05:44:26 pm by Zedy »
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: lcd, C and pic
« Reply #4 on: August 22, 2010, 07:26:04 pm »
Hello Zedy

You should tell the HiTech compiler which pic you're using...

Code: [Select]
#include <htc.h> // Required to interface with delay routines
#include <pic12f683.h> //modify this with your pic

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.
 

Offline Zedy

  • Contributor
  • Posts: 26
Re: lcd, C and pic
« Reply #5 on: August 22, 2010, 08:58:58 pm »
Hello Zedy

You should tell the HiTech compiler which pic you're using...


I have 9.70 HiTech compiler version.


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.

Thanks! I have found LCD library, and with little code modification it works very nice!
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: lcd, C and pic
« Reply #6 on: August 22, 2010, 10:19:32 pm »
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: [Select]
#include <pic12f683.h> //modify this with your pic
Congratulations on your first LCD project!  ;D
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 14763
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: lcd, C and pic
« Reply #7 on: August 23, 2010, 06:47:15 am »
yea I'm hoping to do something with LCD's soon just got to get one project up and running
 

Offline Zedy

  • Contributor
  • Posts: 26
Re: lcd, C and pic
« Reply #8 on: August 23, 2010, 04:55:13 pm »
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: [Select]
#include <pic12f683.h> //modify this with your pic
Congratulations on your first LCD project!  ;D

Thanks!  :)  I have included header for my pic, so now all seems to be right.  :)

yea I'm hoping to do something with LCD's soon just got to get one project up and running

It was really painful process for me, I spant almost month just trying understand how lcd module works  ;D
« Last Edit: August 23, 2010, 05:00:03 pm by Zedy »
 

Offline FreeThinker

  • Frequent Contributor
  • **
  • Posts: 791
  • Country: england
  • Truth through Thought
Re: lcd, C and pic
« Reply #9 on: September 09, 2010, 06:18:10 pm »
Hi, Have a read of this
http://www.epemag.wimborne.co.uk/resources.htm
The LCD pdf's are a Good read. Hope they help
Machines were mice and Men were lions once upon a time, but now that it's the opposite it's twice upon a time.
MOONDOG
 

Offline Zedy

  • Contributor
  • Posts: 26
Re: lcd, C and pic
« Reply #10 on: September 09, 2010, 08:06:26 pm »
Hi, Have a read of this
http://www.epemag.wimborne.co.uk/resources.htm
The LCD pdf's are a Good read. Hope they help

The links to LCD pdf's are broken.
 

Offline djsb

  • Frequent Contributor
  • **
  • Posts: 589
  • Country: gb
David
Hertfordshire,UK
 University Electronics Technician, London PIC,CCS C,Arduino,Kicad, Altium Designer,LPKF S103,S62 Operator, Electronics instructor.  http://debuggingrules.com/ Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf