PIC16F876A and LCD interfacing issues with HITECH C

Status
Not open for further replies.

sunil21

Advanced Member level 4
Joined
Dec 2, 2010
Messages
119
Helped
4
Reputation
8
Reaction score
5
Trophy points
1,298
Visit site
Activity points
2,514
I have a PICKIT2 clone.
I am trying to interface LCD with PIC16F876A.
As seen in most of the examples, I grounded the RW.
When I used MPLAB HITECH C first , no matter what I did it didn't work. Only showing square black blocks on the first row.

Then I tried mikroe C for pic. It worked fine - Great..
but the code crashed most of the time and was unable to debug without a Mikroe programmer.

so with no option I had to switch back to MPLAB.
I tried the demo board with 12mhz crystal. I tried codes from net for LCD interface.
Lot of delays here and there.. Played with it adjusted... Okay I got it working.

Then I had to work with TIMER1 interrupt and for calculation with FOSC/4 thing , I tried with 12mhz (effective 3mhz (12/4 - I think instruction period is fraction or something).


I found it better to use 4mhz or 8mhz XL so that timing calculations will be easy.

I replaced 12MHZ with 8MHZ Crystal. Now in HITECH C , I again get square blocks.
I tried Mikroe.. it is perfect.

Please tell me what magic mikroe guys have in their code ... Is there some other way to read busy flag??

May be I have to use the RW pin also. One more thing: When I simuate the Mikroe code in proteus it works fine. But with hitech c code it is blank.
Got 10 messages , 1 says : Controller received command whilst busy (must be timing - delay duration)

Any suggestions ?
 

Save the attached file as lcd.h and include it in your code. Test for different clock frequencies. I have used Hi-Tech C __delay_us() and __delay_ms() functions. You might have to include delays.h file. Check in Compiler includes folder.
 

Attachments

  • lcd.h.txt
    4.4 KB · Views: 82

Thanks for the Code...
Can you provide an example main function to run on MPLAB 8.56
 

Try attached MPLAB 8.92 Hi-Tech PICC 9.83 project. You only have to include lcd.h in your projects and use the LCD functions in the main code.

I have tested for 20 MHz Clock in Proteus and it works fine. Test for different clocks in Proteus and also hadware. When clock is changed remember to modify the line


Code C - [expand]
1
#define _XTAL_FREQ 20000000UL

and also the config settings. I have set config in IDE. You can set it also in IDE or in code. For 20 MHz I have set to HS type. If you test it for 4 MHz then set it for XT.
 

Attachments

  • LCD.rar
    95.8 KB · Views: 62

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…