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

Serial Port Funny Business

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



Joined: 01 Nov 2009
Posts: 15

View user's profile Send private message

Serial Port Funny Business
PostPosted: Fri Mar 26, 2010 9:20 pm     Reply with quote

Hi all,
So I got my PIC16F688 talking to my computer via serial port! Yay!! For a test I have made a simple program to turn a led on and off at 500ms intervals. Depending on where I put the printf statements, the programs works and blinks the led at the correct timing...or it flickers the led but sends the LED on / off statement to the computer with the correct timing.

Here is the first version that doesn't work:


Code:

#include <16F887.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5,ERRORS,PARITY=N,) 

void main()
{
while(1){
delay_ms(500);
output_high(PIN_C0);
printf("\r\nLED On\r\n");
delay_ms(500);
output_low(PIN_C0);
printf("\r\nLED Off\r\n");
}
}



and the second version which does work:

Code:

#include <16F887.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5,ERRORS,PARITY=N,) 

void main()
{
while(1){
delay_ms(500);
printf("\r\nLED On\r\n");
output_high(PIN_C0);
delay_ms(500);
printf("\r\nLED Off\r\n");
output_low(PIN_C0);

}
}


As you can see... all that I have done is put the printf before the pin output statement as opposed to after the output statement.
Can anyone tell me what is going on here?

Thanks!
DS.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 26, 2010 9:46 pm     Reply with quote

Post your compiler version.

Quote:

So I got my PIC16F688 talking to my computer via serial port

#include <16F887.h>

Confirm which PIC you are using.
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Sat Mar 27, 2010 4:08 pm     Reply with quote

It actually sounds like RMW.
It appears that he is using a software serial port, and as such, this will need to read/write portC. I'd suspect that the LED circuit, is slightly overloading the PIC pin, and when the serial I/O takes place, the LED output, is read as low, and therefore turned off.
Do a search here on the term 'RMW', and try a larger series resistor feeding the LED.

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