Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD interface with pic18f4550.

Status
Not open for further replies.

zarazagoza

Newbie level 3
Joined
May 9, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
i am trying to display data that i dictated to the LCD. lets say z=10, but the lcd only display random data not 10. can someone point me out where I did it wrong

Code:
#include <p18Cxxx.h>
#include <delays.h>
#pragma config WDT = OFF, LVP = OFF, FOSC = HS, 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);

#define LCD LATD //LCD Latch PORT
#define LCD_RS LATDbits.LATD4 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATDbits.LATD5 //Enable (Starts data read/write)
#define LCDT TRISD //LCD Tris port
void main (void)
{
char x,tmp; //Some Variables
int i;
unsigned char z[10];
OSCCON = 0x72; //8MHz clock/while(!OSCCONbits.IOFS); //Wait for OSC to become stable
ADCON1 = 0x0F; //Make all pins digital
LCD_Init(); //Initialize the LCD

z[i]=200;

while(1){SetLine(1); //Set Line 1
LCD_String((unsigned rom char*)z[i]); //Send out string
//SetLine(2); //Set Line 2
//LCD_String((unsigned rom char*)" Successful. "); //Send out string
}
}
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)
}
 

what is this?z=200;

send in ascii form,LCD_String((unsigned rom char*)z); //Send out string
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top