|
|
View previous topic :: View next topic |
Author |
Message |
atomy_kwang
Joined: 28 Jun 2008 Posts: 24
|
I have a problem about receive data (string) in CCS C |
Posted: Sun Sep 07, 2008 7:56 am |
|
|
This is my code, it have something wrong.
Code: |
#include <16f877a.h>
#fuses HS,NOLVP,NOPROTECT,NOWDT
#use delay(clock = 20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
#byte port_b=6
#INT_RDA
void receive_data(void)
{
char data[20] ;
gets(data)
while(data == 'radio')
{ output_high(pin_b0);
delay_ms(1000);
output_low(pin_b0);
delay_ms(1000);
}
while(data == 'tv')
{ output_high(pin_b0);
delay_ms(1000);
output_low(pin_b0);
delay_ms(1000);
}
}
void main()
{
set_tris_b(0x00);
port_b=0x00;
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
while(true)
{
;
}
} |
I have a problem that i would like everyone to help.
1. I want to receive data in string but the loop while
it cannot do
2. Assume that i succeed in solution 1. If receive data correct, it is
work especially in that loop. Although I put the data 2 correct
it does not work.
I want to do on data that i sent from vb.
Assume i send the word 'radio' led at rb0 on, but if i send 'tv'
led at rb1 on and rb0 off.
help me please |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sun Sep 07, 2008 10:20 am |
|
|
2 thoughts:
1) for comparing string, use C function strcmp().
You have to have:
#include <string.h>
However, strings have to be terminated by '\0' character, not "\r".
2) dont use delay_ms in any interrupt routine.
You can use timers and their interrupts, or the main loop for delay purposes |
|
|
Ttelmah Guest
|
|
Posted: Sun Sep 07, 2008 11:55 am |
|
|
Also, understand, that INT_RDA, implies just _one_ character is waiting to be received. 'gets', waits for a complete _string_ of characters, including a terminating line feed. Using gets, spoils the 'point' of using interrupts. If you want to wait for a whole string, do this in the main, and don't use interrupts. If you want to use interrupt driven serial, so you can do other things, look at ex_sisr, which shows how to buffer data from the interrupt. Do your own assembly into a 'string' in the main code.
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
|