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

RS-232 Woes

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



Joined: 21 Sep 2003
Posts: 5
Location: Saginaw, MI

View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number

RS-232 Woes
PostPosted: Sun Sep 28, 2003 1:03 pm     Reply with quote

I am a bit new to PCW and MCUs in general. I am trying to get some RS-232 communication going between two chips (16f877), more or less as practice. Yet, I am encountering two main problems: my receiving code and my sending code Embarassed . Alright, for my receiving code, I am having the program wait for a byte to arrive and then when one arrives, it just toggles an output so i know it worked. Yet, regardless of what I hook the RX pin to, my designated output pin toggles more or less at the speed of my main loop (very fast). The code is as follows:

#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7, ERRORS)

#include "C:\Documents and Settings\Admin Bin\My Documents\ECE497\Code\rs232test.h"


void main() {
int toggle = 0;
int i = 0;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_psp(PSP_DISABLED);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);

set_tris_a(0x00);
output_a(0x00);

for(;;)
{
if(kbhit())
{
if(toggle==0){toggle = 1; output_low(PIN_A0);}
if(toggle==1){toggle = 0; output_high(PIN_A0);}
}
delay_us(10);
}

}

My only problem with transmitting is that I don't know how to tell if it is working at all since I can't receive it Confused. Here is the sending code though:

#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)

#include "C:\Documents and Settings\Admin Bin\My Documents\ECE497\Code\controlsystem.h"


void main() {

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);

set_tris_a(0x00);
output_a(0xAA);

// Main Loop
for(;;)
{
putc("a");
delay_ms(10);
putc("b");
delay_ms(10);
putc("c");
delay_ms(10);

}

}


Any help would be greatly appreciated.

Thanks
_________________
- - - - -
-- Wrocko --
- - - - -
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 28, 2003 2:13 pm     Reply with quote

// Main Loop
for(;;)
{
putc("a");
delay_ms(10);
putc("b");
delay_ms(10);
putc("c");
delay_ms(10);
}


I wonder what version of the compiler you're using ?
Because, with a late version of the compiler (PCM vs. 3.176),
it gives the error: "A numeric expression must appear here",
when you use a quoted string with putc().

So as an experiment, I compiled it with PCM vs. 2.734.
Result: No errors, but no code produced for those lines, at all.

So, I conclude that you're using an early version of the compiler.
You need to change the double quotes to be single quotes.
Like this:

putc('a');
putc('b');
putc('c');
wrocko



Joined: 21 Sep 2003
Posts: 5
Location: Saginaw, MI

View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number

PostPosted: Sun Sep 28, 2003 8:51 pm     Reply with quote

Thanks, that did the trick for the transmitter. I solved my own problems on the receiver. I wasn't emptying the characters that came with getc() so the loop kept going into the toggle area. The toggle was messed up too but that is just icing on the cake. Im all set now, thanks again. Very Happy
_________________
- - - - -
-- Wrocko --
- - - - -
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