View previous topic :: View next topic |
Author |
Message |
nguyentuandang
Joined: 06 Oct 2012 Posts: 5
|
Read eeprom lost 2 address |
Posted: Tue Oct 30, 2012 11:33 am |
|
|
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
|
|
Posted: Tue Oct 30, 2012 11:56 am |
|
|
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
|
|
Posted: Tue Oct 30, 2012 2:40 pm |
|
|
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
|
thanks |
Posted: Tue Oct 30, 2012 8:55 pm |
|
|
Thanks so much:)) |
|
|
|