Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Character Lcd with Microchip C

Status
Not open for further replies.

binzer

Member
I can't seem to get this to work, it seems simple enough, I can see data on the RB lines but no display, what am I doing wrong??
 

Attachments

  • 40P_Lcd_1.c
    2.5 KB · Views: 157
Check the operation of E, RS and RW ... You need to set ANSELH = 0 to turn off the analog inputs on these pins

The OpenXLCD in c18 is supposed to do that from what I read. I had hoped someone here had used C18 and could tell me the routines actually work.
Ok. I want to go back to basics. If I put power to it ( pin-1 = gnd, pin 2 = +5) and some voltage between gnd and 5v on pin 3 I should get something, correct??
 
Have a look over here it should get you on track openXLD is made for the lower bits to be data
https://www.microchip.com/forums/tm.aspx?m=92849

Hi,
as I've got initialisation errors with my 2 line LCD (often did show a garbage
after the reset - the same project with other compiler works ok). I've found
that openxlcd.c library doesn't provides the correct sequence for the 44780
hitachi controller. There shall be a sequence:
- port setting
- e,rw,rs setting
- 3x init as 8bit interface (even you have 4 bit - the original code
is switching here from 8bit to 4bit if you using UPPER or Lower)
- init for 4line or 8line
- other lcd settings
I am using 4 bit UPPER lcd configuration and this code below works finaly:
 
Have a look over here it should get you on track openXLD is made for the lower bits to be data
https://www.microchip.com/forums/tm.aspx?m=92849

You can pick upper or lower for the 4 bit mode, but you use the upper bits (4-7) on the display.

I also see something else (#define TRIS_RS DDRDbits.RD6 ) compared to (#define TRIS_RS TRISBbits.TRISB1 ), what's the difference, why 2 different defines??

I have read a bunch of stuff and it all seems to contradict each other in some way, confusing. I did find an actual real example but I can't cut / paste it to try.

I also see some wiring diagrams where if using the 4 bit you tie the lower 4 bits of the display to gnd, but saw some not tied..??

I am really looking for a working example with Microchips c18 as I would like to stay with one compiler.. It's prob me and lack of sleep, we just got our phone / internet back today (been out a week from the storm, 4 days no power)..

I had planned on doing the 8 bit interface but the board I have avail for now is setup for 4 bit.

Back to more reading...Tnx..
 
Last edited:
Atom did this you can look at it

Code:
#include <p18Cxxx.h>
#include <delays.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF
void SendLCD(unsigned char Byte, char type);
void E_TOG(void);
void SendNyb(unsigned char Byte);
void LCD_Init(void);
void SetLine (char line);
void LCD_String(unsigned rom char *string);
/*
PINOUT:
LCD - PIC
-------------
DB4 - RA0
DB5 - RA1
DB6 - RA2
DB7 - RA3
RS - RA4
E - RA5
R/W - GND
*/
#define LCD LATA //LCD Latch PORT
#define LCD_RS LATAbits.LATA4 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATAbits.LATA5 //Enable (Starts data read/write)
#define LCDT TRISA //LCD Tris port
void main (void)
{
char x,tmp; //Some Variables
OSCCON = 0x72; //8MHz clock
while(!OSCCONbits.IOFS); //Wait for OSC to become stable
ADCON1 = 0x0F; //Make all pins digital
LCD_Init(); //Initialize the LCD
SetLine(1); //Set Line 1
LCD_String((unsigned rom char*)" AtomSoftTech "); //Send out string
SetLine(2); //Set Line 2
LCD_String((unsigned rom char*)" 2x16 LCD Demo. "); //Send out string
while(1){
}
}
void LCD_String(unsigned rom char *string){
while(*string != 0){ //While the data pointed to isnt a 0x00 do below
SendLCD(*string++,1); //Send out the current byte pointed to
}
}
void LCD_Init(void){
LCDT = 0x00; //Set LCD Pins as output
LCD &= 0xF0; //clear only te db4:db7 pins
Delay10KTCYx(3); //delay 15mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay10KTCYx(1); //delay 5mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x02); //Function set (Interface is 8 bits long.)
Delay100TCYx(1); //delay 50uS
SendLCD(0x28,0); //Function set (Interface is 4 bits long.) 2-lines, 5x8 dots
Delay100TCYx(1); //delay 50uS
SendLCD(0x10,0); //Cursor move, Shift to the Left
Delay100TCYx(1); //delay 50uS
SendLCD(0x06,0); //Increment
Delay100TCYx(1); //delay 50uS
SendLCD(0x0D,0); //Sets entire display On ,cursor Off, and blinking of cursor position ON
Delay100TCYx(1); //delay 50uS
SendLCD(0x01,0); //Clears entire display and sets DDRAM address 0 in address counter.
Delay10KTCYx(1); //delay 5mS
}
void E_TOG(void){
LCD_E = 1; //Set Enable High
Delay10TCY(); //Delay 5uS
LCD_E = 0; //Set Enable Low
}
void SetLine (char line){
if(line == 1) SendLCD(0x80,0); //Send 0x80 to set line to 1
if(line == 2) SendLCD(0xC0,0); //Send 0xC0 to set line to 2
Delay100TCYx(1); //delay 50uS
}
void SendLCD(unsigned char Byte, char type){
char ByteL;
LCD_RS = type; //Set whether it is a Command (0) or Data/Char (1)
ByteL = Byte & 0x0F; //Place Byte in ByteL and Clear the high part of byte
Byte >>= 4; //Shift over Byte by 4
LCD &= 0xF0; //Clear the LCD portion on the PORTA only
LCD |= Byte; //OR the new data to the LCD portion of PORTA (sending high part of byte)
E_TOG(); //Toggle the E(enable)
Delay10TCY(); //Delay 5uS
LCD &= 0xF0; //Same as above
LCD |= ByteL; //Same as above (sending low part of byte)
E_TOG(); //same as above
}
void SendNyb(unsigned char Byte){
Byte &=0x0F; //Clear the top half of byte
LCD &= 0xF0; //Clear the LCD half of PORTA
LCD |= Byte; //OR the new data into LCD part of PORTA
E_TOG(); //Toggle E(enable)
}
 
Binzer... The XLcd routines DO NOT take other pin functions into account, Its up to you to do that.

Ok, but it does look like it sets this up, if I read it correctly (not very good at programming) in the OpenXLCD.c file, looks to set the port to outputs.

I do understand there are problems with some of these routines, and it looks like I suffer from them, so I need to use other routines and tweek them for what I need.

I was silly and thought that their routines would work and it was the easiest route to get flying, but after reading I see they do things the 44780 specs tell you not to do.

Looks like I'll borrow stuff from AtomSoft and tweek it, I'll prob learn more by doing it this way.

Tnx, Mike..
 
I would look over Atoms code it real good example. From what I hear the openXlcd if you change pins you have to make changes to the h file for it and the C file and the run a batch scrip. And the fact that it really is not made for the 44780. Atom posted a pdf that is real helpful I would down load it. and keep a copy.
 
I would look over Atoms code it real good example. From what I hear the openXlcd if you change pins you have to make changes to the h file for it and the C file and the run a batch scrip. And the fact that it really is not made for the 44780. Atom posted a pdf that is real helpful I would down load it. and keep a copy.

Yes, From doing more reading I guess you edit and recompile the whole ' XLCD lib' to fit your use.
I have seen the Atom cheat sheet and code, it's good, it has code on it for a 4bit 44780 setup,
got that in the editor right now looking it over and see if I can mod it and test my setup.
Thanks guys...mike.
 
Binzer....Do you want a copy of mine!!! I have written it for my boards so there's no definitions each low level routine needs changing but it works great... I have a portb version (nibble type) or portd version (byte type)
 
Binzer....Do you want a copy of mine!!! I have written it for my boards so there's no definitions each low level routine needs changing but it works great... I have a portb version (nibble type) or portd version (byte type)

Sure, I'll take a copy to play with, tnx, I'll try doing a pm to you with my email.

Just been searching for the DDram addresses for the beginning of each line for a 4 line display, found it.
Address Locations
2-Line Display
LCD
Line 1 00 hex, 01 hex, 02 hex,...........
Line 2 40 hex, 41 hex, 42 hex,...........

4-Line Display
LCD
Line 1 00 hex, 01 hex, 02 hex,...........
Line 2 40 hex, 41 hex, 42 hex,...........
Line 3 20 hex, 21 hex, 22 hex,...........
Line 4 60 hex, 61 hex, 62 hex,...........
 
Last edited:
Binzer....Do you want a copy of mine!!! I have written it for my boards so there's no definitions each low level routine needs changing but it works great... I have a portb version (nibble type) or portd version (byte type)

Did you get my P.M. with email address???

I did wire another connector on my board for 8-bits and tweaked my program.
I have not gotten a chance to program the chip and try it out, busy with other things and Work (which I am off to now).
 
Status
Not open for further replies.

Latest threads

Back
Top