IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
RS232 and an LED |
Posted: Thu Nov 20, 2008 7:46 pm |
|
|
I'm trying to turn an LED with the serial port and get a confirmation but some how my code doesn't work, what am I doing wrong?
Code: |
#include <16F887.h> // header file for the PIC16F887
// includes built-in functions and constants
// for arguments/returns.
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT //No brown out, so the pic will work under 4.0V
#FUSES XT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////
void main() {
while(TRUE){
if ('a' == getc()) output_high(PIN_D0);
printf("led on\r\n");
else output_low(PIN_D0);
delay_ms(100);
printf("led off\r\n");
delay_ms(100);
}
}
|
|
|
MarcosAmbrose
Joined: 25 Sep 2006 Posts: 38 Location: Adelaide, Australia
|
|
Posted: Thu Nov 20, 2008 8:26 pm |
|
|
Try this
Code: |
void main()
{
while(TRUE)
{
if(kbhit())
{
if(getc()=='a')
{
output_high(PIN_D0);
printf("led on\r\n");
}
else
{
output_low(PIN_D0);
printf("led off\r\n");
}
}
}
}
|
Also, when you're posting code use the "Code" tags to preserve your codes formating. Makes it easier to read. |
|