View previous topic :: View next topic |
Author |
Message |
aschenk
Joined: 06 Jul 2009 Posts: 4
|
Pic16F877 and Serial LCD |
Posted: Mon Jul 06, 2009 8:02 pm |
|
|
Hi all
ok just starting out in PIC micros and C programming. I played with them a bit usings PICASM but I couldn't wrap my head around it. I bought the Martin P Bates book Programming 8-bit Pic Microcontrollers in C. Overall the book is good in my opinion. I'm trying to get some code to work simulating a 16F877A and LCD using Lab Center ISIS.
The code is taken directly out of Martin P Bates book.
Code: |
#include "16F877a.h"
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1)
void main()
{
char acap='A';
delay_ms(1000);
putc(254); putc(1);
delay_ms(10);
while(1)
{
putc(acap);
putc(254); putc(192); delay_ms(10);
printf("ASCII %c CHAR %d ",acap,acap);
while(1);
} |
The LCD is the [spam] 16x2 serial LCD. When the code is executed all I get is a series of Xs on the display.
Anybody have an idea to the cause? |
|
|
Guest
|
|
Posted: Mon Jul 06, 2009 9:11 pm |
|
|
Hi,
Those displays appear to use the Scott Edwards 'backpack' serial modules. The data sheet for the backpack module says that the serial input can be 'RS232 or INVERTED TTL levels'. You are using TTL levels, so you need to add the INVERT option to your #use rs232 definition.
John |
|
|
Guest
|
|
Posted: Tue Jul 07, 2009 6:15 am |
|
|
Hi,
One other thing I thought of is that the 'invert' option only works with a 'software' serial port (ie. if you ARE NOT using the hardware UART). I don't have a datasheet handy, but I don't think you are. Please check! If you do need to use the hardware serial port, you'd need to add a hardware inverter between the PIC and the serial display.
John |
|
|
aschenk
Joined: 06 Jul 2009 Posts: 4
|
Re: Pic16F877 and Serial LCD |
Posted: Tue Jul 07, 2009 11:37 am |
|
|
OK I got my code to work. Funny, all I had to do is change the clock from 4000000 to 8000000 and it works. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 07, 2009 12:49 pm |
|
|
You're using the Proteus simulator. Probably most of us don't have
Proteus. So there's no way for us to test your problem. Furthermore,
we can't go "look up" the data sheet for the LCD. It's a simulation.
That's why you didn't get many posts offering help. |
|
|
Guest
|
|
Posted: Tue Jul 07, 2009 9:03 pm |
|
|
PCMProgrammer said: "That's why you didn't get many posts offering help."
Excuse me? Based on the limited information presented, I make a good faith effort to help this user solve his problem. Your comment seems a bit dismissive of my efforts
John |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 07, 2009 9:26 pm |
|
|
I was talking about the original poster, not you. I like your posts.
I halfway regretted making that post. I should have followed my
instinct and not made it. |
|
|
aschenk
Joined: 06 Jul 2009 Posts: 4
|
Re: Pic16F877 and Serial LCD |
Posted: Wed Jul 08, 2009 6:54 am |
|
|
Hey John
Thanks for your help!
A[
quote="aschenk"]Hi all
ok just starting out in PIC micros and C programming. I played with them a bit usings PICASM but I couldn't wrap my head around it. I bought the Martin P Bates book Programming 8-bit Pic Microcontrollers in C. Overall the book is good in my opinion. I'm trying to get some code to work simulating a 16F877A and LCD using Lab Center ISIS.
The code is taken directly out of Martin P Bates book.
Code: |
#include "16F877a.h"
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1)
void main()
{
char acap='A';
delay_ms(1000);
putc(254); putc(1);
delay_ms(10);
while(1)
{
putc(acap);
putc(254); putc(192); delay_ms(10);
printf("ASCII %c CHAR %d ",acap,acap);
while(1);
} |
The LCD is the [spam] 16x2 serial LCD. When the code is executed all I get is a series of Xs on the display.
Anybody have an idea to the cause?[/quote] |
|
|
|