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 CCS Technical Support

RS232 and an LED

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



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

RS232 and an LED
PostPosted: Thu Nov 20, 2008 7:46 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 20, 2008 8:26 pm     Reply with quote

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