Jump to content
ajbeavan

Lcd Not Resetting Busy Flag

Recommended Posts

Hello

I would be grateful for some help, before I go completely mad!!!! been working on this for 2 weeks.

 

Have setup a simple circuit to write some output to an LCD which is controlled by a pic16F690. Everything

works fine in the simulation. I have built the circuit, and now my problems start..... I have checked

the wring and placed LED's on each of the control and data ports to see what is happening.

I have managed to isolate the problem down to the LCD not resetting the BF flag after I have done the

System reset and set the 4-bit function mode. The controller is a cheap JHd162A which is compatible with

the HD44780, I have read the data sheet and really relaxed the timing, but no success.

 

Please help, before a take a hammer to the whole lot, Have attached the LCD driver routine

 

#include <system.h>

#include <stdlib.h>

#include "LCD_4BitHeader.h"

 

 

VOID lcd_initial(){

/*****************************************

Intialisation Of the LCD

******************************************/

trisc=trisb=OUTPUT; //set all data pins as output

portb=portc=0; //clear the ports

 

//configure portb to recieve code

portb=WRITE_CODE;

 

//Initial reset and delay sequence,not worried

//about nibbles so send as a whole byte

delay_ms(500);

writeNIBBLE(0x30); //LCD System Reset

delay_ms(200);

writeNIBBLE(0x30);

delay_ms(200);

writeNIBBLE(0x30);

delay_ms(200);

writeNIBBLE(0x20); //Set 4-bit function mode

delay_ms(200);

writeToLCD(0x2C);

delay_ms(200);

 

writeToLCD(0x01);

delay_ms(200);

writeToLCD(0x06);

delay_ms(200);

writeToLCD(0x08);

delay_ms(200);

writeToLCD(0x0F);

delay_ms(200);

 

 

portb=WRITE_DATA; //write the letter 'Z'

writeToLCD(0x5A);

}

 

VOID writeToLCD(UCHAR data){

/*****************************************

Running in 4-bit mode so need to write

the High and Low nibbles to the LCD.

******************************************/

writeNIBBLE(data & 0xF0); //mask the lower nibble

writeNIBBLE(data << 4); //mask upper nibble

waitBFLAG(); //check BF, still processing

}

 

VOID writeNIBBLE(UCHAR d){

/*****************************************

Write the data onto portC and toggle the

enable pin.

******************************************/

portc=d;

//toggle the enable pin

portb |= ENABLE_PIN;

asm nop //pulse delay for enable

portb &= ~ENABLE_PIN;

}

 

VOID waitBFLAG(){

/******************************************

Read portC and check the status of the

BF flag on DB7

*******************************************/

UCHAR Hnibble=0x00,Lnibble=0x00;

UCHAR tempb=0x00,tempc=0x00,count=0x00;

UCHAR BFLAG=0x00; //assume BFlag is set at start

 

tempb=portb; //store the current state of ports

tempc=portc;

 

trisc=INPUT;

portb=READ_CODE;

 

do {//check the status of busy flag

//Read the High Nibble

portb |= ENABLE_PIN; //Toggle Enable Pin

asm nop

Hnibble=portc & 0xF0;

portb &= ~ENABLE_PIN;

 

//Read the Low Nibble

portb |= ENABLE_PIN; //Toggle Enable Pin

asm nop

Lnibble=(portc & 0xF0)>>4;

portb &= ~ENABLE_PIN;

 

//Combine nibbles to form busy status

BFLAG=Hnibble+Lnibble;

 

//Check to see if BF is timming out

if(count++ == 0xFF){

trisa=OUTPUT;

BFLAG=0x00;

trisc=OUTPUT; //what sequence is failing

portc=tempc;

set_bit(porta,2);

 

while(1)

;

}

} while(BFLAG & 0x80);

 

trisc=OUTPUT;

portb=tempb; //restore portb

count=0x00;

}

Share this post


Link to post
Share on other sites

ajbeavan,

Is the error here ?

while(1) // wait forever ????

;

}

} while(BFLAG & 0x80);

 

Regards

Dave

Share this post


Link to post
Share on other sites

Sorry, I added this line deliberately to hang the code, so that I could monitor the LED states on each of the DB ports at the

point the BF flag was set....

Share this post


Link to post
Share on other sites

ajbeavan,

Sorry, I added this line deliberately to hang the code, so that I could monitor the LED states on each of the DB ports at the

point the BF flag was set....

Have you considered ignoring the busy flag and just using a time delay. Many applications do this to save an output, ie then the read/write connection is not needed?

Doing this may give a clue to the problem.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave

Finally managed to sort the problem out, after spending so much time thinking about initialisation and 4-bit

data mode, I forgot to check if the device had been wired the correct way.....

I had everything back to front, so now after 2 weeks and writing my own LCD routines, it was simply a case

of wiring. Feel like a real idiot.

Sorry to waste your time

 

adam

Share this post


Link to post
Share on other sites

Hi

 

:lol: :lol: :lol: :lol:

 

Everybody been there and done that,

Don't take it too seriously.

After all the only thing you can be sure is that this won't be the last time. :D

 

 

Best regards

Jorge

Share this post


Link to post
Share on other sites

Thanks...... well I certainly learnt a lot, though I can't say that being a LCD expert was ever high on my ambition list.

 

But I am glad I didnt take a hammer to the whole!!!!

 

adam

Share this post


Link to post
Share on other sites

ajbeavan,

Finally managed to sort the problem out, after spending so much time thinking about initialisation and 4-bit

data mode, I forgot to check if the device had been wired the correct way.....

I had everything back to front, so now after 2 weeks and writing my own LCD routines, it was simply a case

of wiring. Feel like a real idiot.

You always learn much more from things that don't work, the extra time is therefore not actually wasted.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...