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.

Unexpected behaviour of ReadAddrXLCD and ReadDataXLCD MPLAB functions

Status
Not open for further replies.

kyru27

New Member
This fucntions are working in a way I think they shouldn't be. I mean according to it's reference (https://www.electro-tech-online.com/custompdfs/2012/08/mplab_c18_libraries_51297f.pdf, page 77-81) I guess the following code:

Code:
#include <p18cxxx.h>
#include "xlcd.h"



rom char prueba[]="pruebap";
char i=0;
char j=0;



void muestraLCD(char st[],char addre)
{
unsigned char config=0xFF,i=0,addr=0,data=0;
int adr=0;
ADCON1 = 0xFF;

TRISD = 0;
PORTD = 0;	
TRISB = 0;				// Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1;  // make sure this pin is input
TRISE=0;
ADCON1=255;

	config = FOUR_BIT  & LINES_5X7;
//********  Configure LCD for four line communication and 5X7 line display *********************************

if (ini==0x00)
{
	
	OpenXLCD(config);		
	ini=0x01;
}
		busylcd2();		//wait untill LCD controller is busy

//*********** Set the starting address in the LCD RAM for display. This determines the location of display ********	
	SetDDRamAddr(0x88);
		busylcd2();		//wait untill LCD controller is busy

	putrsXLCD(prueba); //Escribe para las de tipo rom 
	putcXLCD(0x31); //"Escribe el carácter ascii correspondiente al número indicado"

	//Hay que configurarlo para lectura.



	busylcd2();
	TRISD=255;
	i=ReadDataXLCD();
	TRISD=0;
	busylcd2();

	
	SetDDRamAddr(addre-1); // addre is 0x88, so this shoud be 0x87
		
	busylcd2();
	TRISD=255;
	j=ReadDataXLCD();
	TRISD=0;

	busylcd2();
	TRISD=255;

	adr=ReadAddrXLCD();
	
	TRISD=0;
	
		busylcd2();

...................................

Being busylcd2:

Code:
void busylcd2(void)
{
	LCDDelay();
        LCDDelay();
	LCDDelay();
}

void LCDDelay(void)
{


int i=0;
for (i=0;i<100;i++);

}



Should give the following results:

i=0x31 ("1"), j= 0x71 ("r") (Actually my display displays characters backwards (https://www.electro-tech-online.com...-first-character-per-line.129225/#post1078308) and adr=0x87 or 0x0087.

But instead it gives i=0x20, j=0x20, adr=0x0066.

I've also performed the following tests with the code:

First I used a code without TRISD changes ar busylcd calls for the call of the functions that are behaving this way and it gave the same result.

Then I checked reference and seems like the functions needed a previous call of BusyXLCD(), but as this function doesn't work for me y used my own busylcd2() getting the same results.

I thought that maybe it was needed to really check the busy bit as it could take randomly long periods to deactivate so I used the following function.

Code:
void busylcd(void)
{
RS=0;
RW=1;
TRISD=255;
	E=0;
	LCDDelay();
	E=1;
while(LCDBusy==1){
	E=0;
	LCDDelay();
	E=1;
	}
TRISD=0;
}

But it gave as results i=0x20, j=0x22 and adr=0x0000 and what is worse erased what was on display on second call of ReadDataXLCD().

I also tried to use that busylcd() function instead of the busylcd2() one with the changes on TRISD, as ReadDataXLCD() didn't seem to do it on its own but same result as the previos test (0x20, 0x22,0x0000).

Finally I performed the code I'm showing with the already mentioned results.

Pins used as Input/Output for the write/read to/from the display are grounded and the display works fine for showing characters (in any case if it was problem of possible noise I guess it should be giving different results every time the code is run.

Any idea of what is failing or is it that I have misunderstood what these functions do?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top