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

Pic to PC interface

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



Joined: 22 Aug 2010
Posts: 43

View user's profile Send private message

Pic to PC interface
PostPosted: Thu Oct 28, 2010 8:33 am     Reply with quote

am trying to make an interface between pc and pic16f877A, which allows me to switch a led on and off using a push button.
i made the gui in matlab and programed the bushbutton, and then i wrote the microcontroller program, but while i was simulating it nothing happens, i didn't recognize the problem.
this is the code
#include <16f877A.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 4MHZ)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
main()
{ byte a;
setup_uart(9600);





while(1)
{

output_low(PIN_B0);
output_low(PIN_B2);
a=getch();
if(a=="g")
{ output_high(PIN_B0);
delay_ms(500);
}

else
{output_high(PIN_B2);
delay_ms(100);
}
}


}


thanks for help
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Oct 28, 2010 8:44 am     Reply with quote

First problem:-

Code:

if(a=="g")

Double qoutes ("") are used to indicate the start and end of a string for the compiler. a is defined as a byte (single char).

Try changing your condition to
Code:

if(a=='g')

Note the use of single quotes, these are used to indicate a single char to the compiler.

I am assuming your matlab code sends the char 'g' when you press the button!
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