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

I have a problem about receive data (string) in CCS C

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



Joined: 28 Jun 2008
Posts: 24

View user's profile Send private message

I have a problem about receive data (string) in CCS C
PostPosted: Sun Sep 07, 2008 7:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 07, 2008 10:20 am     Reply with quote

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







PostPosted: Sun Sep 07, 2008 11:55 am     Reply with quote

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