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.

Anyone know how can i Display data on my LCD?

Status
Not open for further replies.

ooicheesan

Junior Member level 1
Joined
Sep 28, 2004
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
353
xlcd.h

Currently i am doing the serial communication between my VB at comm 1 and the PICDEM 2 BOARD..do i just wonder why i cant send my data to light up the LCD at my board?using the MPLAB ICD2?here i submit on the cod efor you to have a look whether i got miss out anything or not?thanks...

#include <p18f452.h>
#include <xlcd.h>
#include <delays.h>
#include <usart.h>


char Data[2];

void Initialise_Serial_Port_Pin(void)
{
// Serial TX & Rx pins configuration.
// TX - port C pin 6
TRISCbits.TRISC6 = 0;

// Rx - port C pin 7
TRISCbits.TRISC7 = 1;
}

void Process_Information(void)
{

switch (Data[0]) {
case 'A':
PORTA = Data[1];
break;

case 'B':

PORTB = Data[1];
break;

case 'C':
PORTC = Data[1];
break;

default:
putrsUSART("Error!");
return;

};

putrsUSART("Ok");

}

char getcharusart()
{
while (!PIR1bits.RCIF)
continue;

PIR1bits.RCIF = 0;

return RCREG;
}

void DelayFor18TCY( void )
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD( void )
{
Delay1KTCYx(60); //Delay of 15ms
return;
}
void DelayXLCD( void )
{
Delay1KTCYx(20); //Delay of 5ms
return;
}




void main()
{
unsigned char count = 0;
char temp;


// Serial TX & Rx pins configuration.
Initialise_Serial_Port_Pin();


// configure external LCD
OpenXLCD( EIGHT_BIT & LINES_5X7 );



// configure USART
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF & //usart configuration
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,25 );


while(1)
{
temp = getcharusart();
Data[count++] = temp;
if (count == 2)
{
Process_Information();
putsXLCD(temp);
count = 0;
}
}


{
CloseUSART();
}
}
 

openxlcd

First of all I must say that I am not using Microchip C 18 ...

When I look at your code in main I am not sure that I understand what you want to do here:

while(1)
{
temp = getcharusart();
Data[count++] = temp;
if (count == 2)
{
Process_Information();
putsXLCD(temp);
count = 0;
}
}

I think putsXLCD prints a string to the LCD if you want to print temp to the LCD in decimal you will have to convert it to a printable string first.

Something like this should work:

#include <stdlib.h>
char buffer[10];
putsXLCD(btoa(temp, &buffer));

You could also use:
putcXLCD(temp);

But this would put the binary value of temp to your LCD which might not be very useful.

You should also clear the display each time before you print your value ...

hope this helps and best regards
 

putsxlcd

Thanks for your help there...just wanna tell you how the program work here..
temp = getcharusart(); //get the data and store it in temp
Data[count++] = temp; //get the second data and store in temp
if (count == 2) // if 2 data received then compare is it port A,B or c
{
Process_Information(); // compare then display A[02] or etc
putsXLCD(btoa(temp, &buffer));
count = 0;

So..i tried on putting in the putsXLCD(btoa(temp, &buffer));and include <stdlib.h> and also declare the char temp, buffer[10]; in my project and still it doesnt work it dont show the value on my lcd..so hope you can have a look at my program again..here i submitt it once more after the alteration..thanks..

#include <p18f452.h>
#include <xlcd.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>

char Data[2];

void Initialise_Serial_Port_Pin(void)
{
// Serial TX & Rx pins configuration.
// TX - port C pin 6
TRISCbits.TRISC6 = 0;

// Rx - port C pin 7
TRISCbits.TRISC7 = 1;
}

void Process_Information(void)
{

switch (Data[0]) {
case 'A':
PORTA = Data[1];
break;

case 'B':

PORTB = Data[1];
break;

case 'C':
PORTC = Data[1];
break;

default:
putrsUSART("Error!");
return;

};

putrsUSART("Ok");

}

char getcharusart()
{
while (!PIR1bits.RCIF)
continue;

PIR1bits.RCIF = 0;

return RCREG;
}

void DelayFor18TCY( void )
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD( void )
{
Delay1KTCYx(60); //Delay of 15ms
return;
}
void DelayXLCD( void )
{
Delay1KTCYx(20); //Delay of 5ms
return;
}




void main()
{
unsigned char count = 0;
char temp, buffer[10];


// Serial TX & Rx pins configuration.
Initialise_Serial_Port_Pin();


// configure external LCD
OpenXLCD( EIGHT_BIT & LINES_5X7 );



// configure USART
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF & //usart configuration
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,25 );


while(1)
{
temp = getcharusart();
Data[count++] = temp;
if (count == 2)
{
Process_Information();
putsXLCD(btoa(temp, &buffer));
count = 0;
}

}


{
CloseUSART();
}
}
 

delayfor18tcy

Sorry I can not see any problem in the moment.

Are you sure that you receive anything from your PC?

Is the baudrate correct?

One good thing is to check for overrun because this condition will disable your USART reception.

char getcharusart()
{
while (!PIR1bits.RCIF)
continue;

if(RCSTAbits.OERR)
{
RCSTAbits.CREN=FALSE;
RCSTAbits.CREN=TRUE;
}

PIR1bits.RCIF = 0;
return RCREG;
}

Maybe somebody who uses Microchip C18 can have a look at your program?

Edit: do you really nead to open another thread with exactly the same question?


best regards
 

param_sclass

Ya...C men..i can receive the data send from my Vb to the board because i use the hyperterminal to check the dta sent out from VB so just wondering how am i going to display the data for examples A[02] to my LCD on this PICDEM 2 PLUS board?or that really sound weird for you..i would like to ask you one question regarding the putsUSART() and putrsUSART() functions in the MPLAB ICD 2...i understand that this function write strings including the null character out right..?then for examples if i wanted to send a "ok" out to my hyperterminal or Vb at comm 1 how can i write the code?i tried writitng it by putc("ok"),but then the compiler stated there
Error - could not find definition of symbol 'putc' in file 'C:\mcc18\Myproj\Code.o'.

So..how am i going to send the "ok" out then?hope you can help..
 

xlcd.h example

The most simple way would be to use the built in putcUSART() function:
putcUSART('o');
putcUSART('k');

You could also write your own string -> USART function ...

best regards
 

    ooicheesan

    Points: 2
    Helpful Answer Positive Rating
xlcd.c

Thanks a lot C man...i got to display the 'ok' to my Vb there already..then i can enable the timing to delay it for prompting out error messages..so the problem is how to display the data i enter to be display on my LCD...i submitted on the code already but then when i run and compile it...the LCD screen do light up but then it didnt show anything...so hope you can help...thanks..
 

xlcd.h 4 bit

I still can not find a problem except when you enter for example B1 your routine writes to PORTB but the LCD is connected to PORTB so this PORT can not be used for anything else, avoid writing to PORTB when you use the LCD.

You also do not set the data direction for PORTA and PORTC, these ports are by default inputs but you want to use them as outputs !!

You can test your LCD by using one of the example programs from the C18 library documentation.

#include <p18C452.h>
#include <xlcd.h>
#include <delays.h>
#include <usart.h>
void DelayFor18TCY( void )
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD( void )
{
Delay1KTCYx(60); //Delay of 15ms
return;
}
void DelayXLCD( void )
{
Delay1KTCYx(20); //Delay of 5ms
return;
}
void main( void )
{
char data;
// configure external LCD
OpenXLCD( EIGHT_BIT & LINES_5X7 );
// configure USART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX,
25);
while(1)
{
while(!DataRdyUSART()); //wait for data
data = ReadUSART(); //read data
WriteDataXLCD(data); //write to LCD
if(data=='Q')
break;
}
CloseUSART();
}

best regards
 

c18 xlcd example

Hello there... regarding to what you wrote for me the data that i am sending is not to port B is just that this is to compare it whether is it 'B' only and the important thing i want to do is to display out the character B02 on my LCD..so not that i am sending the data there to port B...because the data port is port D..so i tried on to change the port setting and pins setting on the Xlcd.h and trying to recompile it...the program that you sent me is the one that included in the mcc 18 examples..so i tried it before but i think i got to recompile and set all the I/o pins in the .h files first before the xlcd.h could function..hear from you then..
 

btoa c18

OK so how did you connect your LCD to the pic and what is connected to the contrast pin (I think it is pin3) of the LCD?

And as I do not use Microchip C18 can you PM me the necessary source code of XLCD .c and .h that you are using so that I can take a look at it?

best regards
 

delayfor18tcy()

ya..now i am sending you the xlcd.h code and also my lcd.c code,what i need to do now is to define the
#ifndef __XLCD_H
#define __XLCD_H
for your information i have changed the code in the DATA_PORT code and the CTRL_PORT.I am using the __18CXX part only so you need not care for others....
another thing is that i need to have to recompile the p18f452.lib file then
find a makeonep.bat file in your mcc18/src dir then start it with this parameter:
makeonep.bat 18f452
i send the p18f452.lib file to you too..so can you direct me how to define the #ifndef __XLCD_H
#define __XLCD_H
and also recompile the p18f452.lib file then find a makeonep.bat file because i tried and there is still error there...so thanks a lot ....

THIS IS THE XLCD.H files......

#ifndef __XLCD_H
#define __XLCD_H

/* PIC 17Cxxx and 18Cxxx XLCD peripheral routines.
*
* Notes:
* - These libraries routines are written to support the
* Hitachi HD44780 LCD controller.
* - The user must define the following items:
* - The LCD interface type (4- or 8-bits)
* - If 4-bit mode
* - whether using the upper or lower nibble
* - The data port
* - The tris register for data port
* - The control signal ports and pins
* - The control signal port tris and pins
* - The user must provide three delay routines:
* - DelayFor18TCY() provides a 18 Tcy delay
* - DelayPORXLCD() provides at least 15ms delay
* - DelayXLCD() provides at least 5ms delay
*/

/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
/* #define UPPER */

/* DATA_PORT defines the port to which the LCD data lines are connected */
#if __18CXX
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD
#else /* 17CXX */
#define DATA_PORT PORTC
#define TRIS_DATA_PORT DDRC
#endif

/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#if __18CXX
#define RW_PIN PORTBbits.RA2 /* PORT for RW */
#define TRIS_RW DDRAbits.RA2 /* TRIS for RW */
#define RS_PIN PORTAbits.RA3 /* PORT for RS */
#define TRIS_RS DDRAbits.RA3 /* TRIS for RS */
#define E_PIN PORTAbits.RA1 /* PORT for E */
#define TRIS_E DDRAbits.RA1 /* TRIS for E */
#else /* 17CXX */
#define RW_PIN PORTCbits.RC5 /* Port for RW */
#define TRIS_RW DDRCbits.RC5 /* TRIS for RW */
#define RS_PIN PORTCbits.RC4 /* Port for RS */
#define TRIS_RS DDRCbits.RC4 /* TRIS for RS */
#define E_PIN PORTCbits.RC6 /* PORT for E */
#define TRIS_E DDRCbits.RC6 /* TRIS for E */
#endif

/* Display ON/OFF Control defines */
#define DON 0b00001111 /* Display on */
#define DOFF 0b00001011 /* Display off */
#define CURSOR_ON 0b00001111 /* Cursor on */
#define CURSOR_OFF 0b00001101 /* Cursor off */
#define BLINK_ON 0b00001111 /* Cursor Blink */
#define BLINK_OFF 0b00001110 /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT 0b00010011 /* Cursor shifts to the left */
#define SHIFT_CUR_RIGHT 0b00010111 /* Cursor shifts to the right */
#define SHIFT_DISP_LEFT 0b00011011 /* Display shifts to the left */
#define SHIFT_DISP_RIGHT 0b00011111 /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT 0b00101111 /* 4-bit Interface */
#define EIGHT_BIT 0b00111111 /* 8-bit Interface */
#define LINE_5X7 0b00110011 /* 5x7 characters, single line */
#define LINE_5X10 0b00110111 /* 5x10 characters */
#define LINES_5X7 0b00111011 /* 5x7 characters, multiple line */

#if __18CXX
#define PARAM_SCLASS auto
#define MEM_MODEL far /* Change this to near for small memory model */
#else /* 17CXX */
#define PARAM_SCLASS static
#define MEM_MODEL
#endif

/* OpenXLCD
* Configures I/O pins for external LCD
*/
void OpenXLCD(PARAM_SCLASS unsigned char);

/* SetCGRamAddr
* Sets the character generator address
*/
void SetCGRamAddr(PARAM_SCLASS unsigned char);

/* SetDDRamAddr
* Sets the display data address
*/
void SetDDRamAddr(PARAM_SCLASS unsigned char);

/* BusyXLCD
* Returns the busy status of the LCD
*/
unsigned char BusyXLCD(void);

/* ReadAddrXLCD
* Reads the current address
*/
unsigned char ReadAddrXLCD(void);

/* ReadDataXLCD
* Reads a byte of data
*/
char ReadDataXLCD(void);

/* WriteCmdXLCD
* Writes a command to the LCD
*/
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

/* WriteDataXLCD
* Writes a data byte to the LCD
*/
void WriteDataXLCD(PARAM_SCLASS char);

/* putcXLCD
* A putc is a write
*/
#define putcXLCD WriteDataXLCD

/* putsXLCD
* Writes a string of characters to the LCD
*/
void putsXLCD(PARAM_SCLASS char *);

/* putrsXLCD
* Writes a string of characters in ROM to the LCD
*/
void putrsXLCD(PARAM_SCLASS const MEM_MODEL rom char *);

/* User defines these routines according to the oscillator frequency */
#if __18CXX
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);
#else /* 17CXX */
extern far void DelayFor18TCY(void);
extern far void DelayPORXLCD(void);
extern far void DelayXLCD(void);
#endif

#endif

i cant send the p18f452.lib to you....so you have a look on the defining part first then let me tell me the procedure to define and the step to recompile the p18f452.lib file then
find a makeonep.bat file... :(
 

void putsxlcd( char *buffer );

OK as you are using PORTA to drive your display control lines you should know that at power up porta is configured as all analog and you can not use it as digital I/O (see the attached page from the manual) :-(

As I already said I am not using (and having) Microchip C18 so it does not make much sense to send me batch files ...

All I do is read the C18 library manual (downloaded from microchip website) and try to help you.

Maybe you could use OpenADC(ADC_0ANA_0REF, ADC_INT_OFF) to configure PORTA as all digital and try to continue to get your program running.

best regards
 

delayporxlcd

8) ... Thanks a lot really for your help..although you are not using the mcc18..but then now.. I understand that the code there is to be change the DATA_PORT there..then now the LCD runs..and it shows Activated words on the first row and the data on the second row...but then the strange thing is this..the data i sent out that is B02 is displayed as 2 only..and i wonder how am i going to display the 'B' character infront of the byte sent....because when i debug through the program it in ICD2 it shows that the data B is capture and i lost it somewhere to display it out..so here i submit the the part of the code for you to have a look...thanks..










void Process_Information(void)
{

switch (Data[0]) {

case 'A':
PORTA = Data[1];

break;

case 'B':

PORTB = Data[1];

break;

case 'C':
PORTC = Data[1];

break;

default:

putrsUSART((const rom char *)"Error!");
return;

};
putcUSART('o');
putcUSART('k');

}

char getcharusart(void)
{
while (!PIR1bits.RCIF)
continue;

PIR1bits.RCIF = 0;

return RCREG;
}


void main()
{
unsigned char count = 0;
char temp, buffer[10];

char start_msg[] = "Activated";


// Serial TX & Rx pins configuration.
Initialise_Serial_Port_Pin();


// configure external LCD

ADCON1 = 0b00001110; // set PORTA pin 0 for analog rest DIGITAL I/O
LCD_init (); // configure LCD


// configure USART
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF & //usart configuration
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,25 );

LCD_display (1, 1, start_msg);


while(1)
{
temp = getcharusart();
Data[count++] = temp;

if (count == 2)
{

Process_Information();
btoa(temp, buffer);

// LCD_display (2, 1, port_A);
LCD_display (2, 2, buffer); //display on the second line of LCD
count = 0;
}

}


{
CloseUSART();
}
}
 

#ifndef __xlcd_h

What about this:
if (count == 2)
{
Process_Information();
buffer[0]=Data[0]
btoa(temp, &buffer[1]);
LCD_display (2, 2, buffer); //display on the second line of LCD
count = 0;
}

You should also take a look at your Process_Information() routine as this routine uses PORTA or PORTB or PORTC as destination and your display is connected to PORTA this could lead to a malfunction of the dsiplay.

best regards
 

mcc18 xlcd library

:eek: ... Hey there C man...thanks a lot for your code there..but then i discovered out how can i display the B2 on the LCD..so now there is a problems here..that is how can i display the data i send to LCD continuously like A2B2C and etc and dont want it to be overwrite..so hope to hear from you then...
 

dspic30f xlcd.h

ooicheesan said:
:eek: ... Hey there C man...thanks a lot for your code there..but then i discovered out how can i display the B2 on the LCD..so now there is a problems here..that is how can i display the data i send to LCD continuously like A2B2C and etc and dont want it to be overwrite..so hope to hear from you then...

You could buffer the last X datas in a ringbuffer and print them to your display whenever you receive new datas ...

Please dont get me wrong but I would recommend learning the basics of C and reading a book about algorithms and data structures like this one for example:


best regards
 

openxlcd( four_bit & lines_5x7 )

8O .. Thanks then..i will try to look out for the code and try working it out on sending data and displaying it on sequences...then the other thing is that when i send the data B64 then after that when i trying to send B4 then the display will overwrite the second data and left the third one there.. for the examples it will show B44 rather then B4 after i send B64.. so is there anyway to write off the third data.....so hope to hear from you then...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top