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

Problem with using switch and interrupt

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



Joined: 28 Jun 2008
Posts: 24

View user's profile Send private message

Problem with using switch and interrupt
PostPosted: Mon Jul 21, 2008 11:51 pm     Reply with quote

hello everyone, i have a question. How to use switch with interrupts

I will tell you a detail in the below :

Using : PIC16F877
Program : CCS C
led : port d bit 0
sw1 (switch1) : port b bit 0
sw2 (switch2) : port b bit 1
Interrupt from : RS232

goal : want to turn on LED
condition : If press sw1 or sw2 , LED will not
work immediately but it must have a
external signal from rs232 (i am waiting to receive a
value from rs232) in to PIC16F877 too,
also led will work, and if have external signal into
PIC16F877 before press sw1 or sw2
led will not work

Please help me for a code

Thank you very much
vijay s



Joined: 20 Oct 2007
Posts: 17
Location: coimbatore,india

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Jul 22, 2008 12:44 am     Reply with quote

it's simple.
Set a flag like switch = true in portb change interrupt when you press a switch. In uart interrupt routine check that a switch flag is true. If it is then turn on a LED, else turn off LED.
_________________
with regards
vijay s
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 1:19 am     Reply with quote

Don't use the word "switch" as a variable use something like int sw;
switch is a keyword in C and the compiler will most likely complain.
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