CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Can't Write/Read from EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
palazzolojoe



Joined: 04 Feb 2012
Posts: 7

View user's profile Send private message

Can't Write/Read from EEPROM
PostPosted: Sat Feb 04, 2012 11:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 2:00 pm     Reply with quote

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: 19520

View user's profile Send private message

PostPosted: Sat Feb 04, 2012 4:05 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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