Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Check the operation of E, RS and RW ... You need to set ANSELH = 0 to turn off the analog inputs on these pins
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
#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.
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.
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)
I sent it to your email straight after I got your PM....
I'll post it here..