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

LED Switching and functions

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







LED Switching and functions
PostPosted: Mon Jul 04, 2005 8:05 am     Reply with quote

Hello,

i am using a pic 18F458 with ccs 3.206.

What i wanted to know is if i have a function that is doing something for example getc();, can i switch on a led for 100 ms and then switch it off every 2 seconds but doing the getc() anyway and vice versa?

Because if i put delays it won't allow the getc to be done for these 2 seconds.

For example :
Code:
getc();
output_high(LED);
delay_ms(100);
output_low(LED);
delay_ms(2000);


Won't switch the led if getc didn't receive anything ...
How can i do ?

Many thanks
valemike
Guest







PostPosted: Mon Jul 04, 2005 11:00 am     Reply with quote

I think you would use the function
if kbhit()

This way, you won't block.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: LED Switching and functions
PostPosted: Mon Jul 04, 2005 11:10 am     Reply with quote

Gwo wrote:
Hello,

i am using a pic 18F458 with ccs 3.206.

What i wanted to know is if i have a function that is doing something for example getc();, can i switch on a led for 100 ms and then switch it off every 2 seconds but doing the getc() anyway and vice versa?

Because if i put delays it won't allow the getc to be done for these 2 seconds.

For example :
Code:
getc();
output_high(LED);
delay_ms(100);
output_low(LED);
delay_ms(2000);


Won't switch the led if getc didn't receive anything ...
How can i do ?

Many thanks


There are a couple of ways of doing it. I would suggest that you use a state machine along with a timer. Furthermore, unless you are using a software uart, I'd receive the data using an interrupt.
Gwo
Guest







PostPosted: Tue Jul 05, 2005 1:44 am     Reply with quote

Many thanks !!
Gwo
Guest







PostPosted: Tue Jul 05, 2005 3:37 am     Reply with quote

I wondered if i can execute my program not only for the getc function (it was just an example)but with a lot of functions, and what i need is to make flicker a green led of a device that shows that it is ON.

However i want to do what i have to do at the same time continuing switching this led.

You said i could use a state machine along with a timer. Could you tell me more about that ?

Thank you.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Tue Jul 05, 2005 6:49 am     Reply with quote

I divide my program into tasks. I try to keep the tasks as short as possible or make them only do a little bit each time I call them. From the main loop, you can call each of the tasks. This will give the appearance that all tasks are running at the same time. For anything that needs to be done on a time interval, I use a timer variable. I setup a timer to interrupt at some system tick. I usually use 1ms. I keep track of the ms count and decrement/increment the task timers in the main loop based on the count from the isr. Sort of the poor man's RTOS.
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