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 support@ccsinfo.com

Read eeprom lost 2 address

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



Joined: 06 Oct 2012
Posts: 5

View user's profile Send private message

Read eeprom lost 2 address
PostPosted: Tue Oct 30, 2012 11:33 am     Reply with quote

Code:

#include <16f877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=12000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)


main(){
int8 e,g,f;
g=0;
e=0;

while(g<50)
  {
   write_eeprom(50+g,71);
   g++;
   }

while(e<50)
  {
   f=read_eeprom (50+e);
   putc(f);
   e++;
  }

}

I use vb6 for rs232 communication.
When i used this code, in vb6 only show 48 character and lost 2 chacracters. I don't know why. Someone help me please.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 11:56 am     Reply with quote

This is the same old problem. You should not let your program fall off
the end of main(). That's because CCS puts a hidden sleep instruction there.
Here is the situation:
Code:

void main()
{



}
#asm  SLEEP  #endasm    // Hidden sleep instruction


When the PIC executes the SLEEP instruction, it shuts down the oscillator.
This means the UART will stop running. The UART has a buffer that can
hold one character. Also, the output shift register in the UART can hold
another character. When the UART is shut down by the SLEEP instruction
those two characters will not be shifted out. You will lose two characters
at the end of the message.

To fix this, you need to add a continuous loop at the end of the program:
Code:

void main()
{


while(1);   // Add this line here
}
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:40 pm     Reply with quote

Hey thanks PCM - I normally don't escape from main(), but I wasn't aware of that tidbit about the sleep instruction. See if I can remember it - handy to know anyway.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
nguyentuandang



Joined: 06 Oct 2012
Posts: 5

View user's profile Send private message

thanks
PostPosted: Tue Oct 30, 2012 8:55 pm     Reply with quote

Thanks so much:))
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