|
|
View previous topic :: View next topic |
Author |
Message |
palazzolojoe
Joined: 04 Feb 2012 Posts: 7
|
Can't Write/Read from EEPROM |
Posted: Sat Feb 04, 2012 11:41 am |
|
|
I have created a VB application to read serial input from the PIC. I have leds hooked up to B6/B7 to debug what state I'm in. When I use the following code I do not receive anything back on the VB side but I do see the LEDs light up showing that the states are changing. note* the vb code works if I do a simple echo. Any help would be appreciated.
Code: |
#include <C:\Program Files\PICC\Devices\16F877A.h>
#fuses hs,nowdt,noprotect,put,nobrownout
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=pin_c6,rcv=pin_c7)
//******Declaring Universal Variables******
//#define ref 0x21
char rcv;
char out;
void main()
{
//output_b(128);
while(1)
{
if (kbhit())
{
rcv=getc();
output_b(128);
if (rcv=='a'){output_b(64);}
else
{
output_b(128);
delay_ms(1000);
output_b(64);
delay_ms(1000);
write_eeprom(0x00,rcv);
out=read_eeprom(0x00);
putc(out);
}
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 04, 2012 2:00 pm |
|
|
If you appear to get nothing on terminal window, it might be getting
non-displayable characters (control codes). To test for this, comment
out the putc() and substitute a printf() statement to do the output in hex.
Then if the PIC is truly sending something, you will see it on the terminal
window. Example of diagnostic code:
Code: |
// putc(out);
printf("%x ", out);
|
Also, it's helpful, just to prove that it's working, to put a "start" statement
at the beginning of your program. Then you know your terminal can
receive characters from this program. Example:
Code: |
void main()
{
printf("Start: \n\r");
.
.
.
.
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Feb 04, 2012 4:05 pm |
|
|
Also, add 'errors' to the RS232 declaration.
This _must_ always be included when using the hardware UART, unless you are handling errors yourself, especially if there are any periods when you don't read the comm port, or the UART _will_ become hung.
If (for instance), you typed 'a', then hit the carriage return key, your PIC would stop working.
Reason is that the carriage return typically sends a line feed and a carriage return (depending on your terminal program settings), and if this happens, the code will be sitting in the 2 seconds of delay, and the UART will be hung.....
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|