|
|
View previous topic :: View next topic |
Author |
Message |
ds
Joined: 01 Nov 2009 Posts: 15
|
Serial Port Funny Business |
Posted: Fri Mar 26, 2010 9:20 pm |
|
|
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
|
|
Posted: Fri Mar 26, 2010 9:46 pm |
|
|
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: 19552
|
|
Posted: Sat Mar 27, 2010 4:08 pm |
|
|
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 |
|
|
|
|
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
|