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 support@ccsinfo.com

REally newbie question. Led flashing

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



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

REally newbie question. Led flashing
PostPosted: Sat Aug 06, 2005 5:32 pm     Reply with quote

Hi!

I want to flash/blink with 3 or 4 leds, but the rythm om the third(or 4th) should be different than the two first one.
Example: I want to switch between the two first led with in a delay at 100ms, and on/off the third(or between the 4th) every 180ms.


So my question is how to solve this, maybe use a timer???

Thanks for all help

Regards
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Aug 06, 2005 7:35 pm     Reply with quote

I think I would set up a timer to cycle every 20ms. Every cycle I would run one counter from 1 to 5 for the first two LEDs and another counter from 1 to 9 for the third LED.
If you are using one of the smaller PICs like I do you could even pack the two counters into a single byte to save RAM, but that is a subject for Advanced Newbies. ;-)
_________________
The search for better is endless. Instead simply find very good and get the job done.
SveinR



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

PostPosted: Sun Aug 07, 2005 2:29 am     Reply with quote

But how to do that in code??

I manage all of this except the timer stuff.

Can anyone write down a short code for me Rolling Eyes

Thanks

(I'm using for the moment 12F629 , but I normally use 16f628. So I can switch between A,B and GPIO ports Laughing )
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Aug 07, 2005 6:48 pm     Reply with quote

Code:

#include <16F628.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16)
#FUSES NOCPD                    //No EE protection

#use delay(clock=4000000)  // Change accordingly

#use fast_io(b)

int8 RL1_counter, RL2_counter, YL1_counter, YL2_counter;

#define Red_Led_1   PIN_B7
#define Red_Led_2   PIN_B6
#define Yel_Led_1   PIN_B5
#define Yel_Led_2   PIN_B4


// LEDs blinking-time constants

#define Red_Led_1_blink  12   (12 * 8.1ms = 97ms)
#define Red_Led_2_blink  12   (12 * 8.1ms = 97ms)
#define Yel_Led_1_blink  22   (22 * 8.1ms = 178ms)
#define Yel_Led_2_blink  44   (44 * 8.1ms = 356ms)

//____________________________________________________________

#int_RTCC
RTCC_isr()
{
   RL1_counter--;
   if( !RL1_counter )
     {  RL1_counter = Red_Led_1_blink;
        output_toggle(Red_Led_1); }

   RL2_counter--;
   if( !RL2_counter )
     {  RL2_counter = Red_Led_2_blink;
        output_toggle(Red_Led_2); }

   YL1_counter--;
   if( !YL1_counter )
     {  YL1_counter = Yel_Led_1_blink;
        output_toggle(Yel_Led_1); }

   YL2_counter--;
   if( !YL2_counter )
     {  YL2_counter = Yel_Led_2_blink;
        output_toggle(Yel_Led_2); }

}

//____________________________________________________________

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);   // every 8.1 ms
   RL1_counter = Red_Led_1_blink;
   RL2_counter = Red_Led_2_blink;
   YL1_counter = Yel_Led_1_blink;
   YL2_counter = Yel_Led_2_blink;

   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);

 do
   {
    //.....
    // Your can do anything here while
    // your Leds are blinking in background
    //.....
   }while(1); 

}

//____________________________________________________________



Humberto
SveinR



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

PostPosted: Tue Aug 09, 2005 4:17 pm     Reply with quote

THANKS Very Happy Very Happy Very Happy Very Happy
Guest








PostPosted: Thu Dec 01, 2005 3:45 pm     Reply with quote

Hi all, I have just started to learn programming, and want to play with this led flashing code above. I have access to the CCS complier and a programmer but do not understand this 12f629.h file part.

Can someone explain this or can someone please send me the .c file and .h file for a flashing led so I can start.

I have searched the internet for hours and no such luck.

Many thanks for any help in advance.

James909f@hotmail.co.uk
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 01, 2005 3:54 pm     Reply with quote

Quote:
I have searched the internet for hours and no such luck.

This I don't believe. I searched for less than a minute using Google
and found it.
Guest








PostPosted: Thu Dec 01, 2005 4:07 pm     Reply with quote

What did you search for?

I have been searching for hours and its come to posting on the forum as last resort!

I can find the c source code but don't understand this .h part?
James909



Joined: 01 Dec 2005
Posts: 3

View user's profile Send private message

PostPosted: Thu Dec 01, 2005 4:12 pm     Reply with quote

OK. thanks for making me think. I found the file on the computer i am working on Embarassed

Is it a definition file?

More question i am sure will follow!

It compiled so lets see if it works.

Thanks again
James
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Thu Dec 01, 2005 4:30 pm     Reply with quote

(I just read your response prior to posting, you've started to show some hope.... )


A couple of suggestions that may lead to a warmer response from the experts here that offer up a lot of their valuable time to help others:

1. Register and log-in. (Demonstrates that you are sincere and are truley interested in learning, not just a "drive by poster looking for homework answers.)

2. Explain (with some detail) what you have attempted so far and what the result has been. "I've searched for hours" doesn't provide much background.

3. Read the forum etiquette at the top of the forum. It will provide some details that I won't waste my time re-typing.

4. If you are going to essentially start a new thread, then start a new thread. Don't exhume a dead one. Simply start a new thread and refer back to the thread in question with a link to make it easier for the experts to access it.


With that gentle admonishment complete, it appears your first problem is explaining exactly what your problem is.

All I could gather is that you need some files and you don't understand the 12f629.h file.

If you need the header file for the 12f629 part, then it will be in your devices directory. If it isn't there your version of the compiler probably won't support that part.

You shouldn't need the .c file. Humberto was generous enough to write and post that for the previous person. Simply copy and paste and save it.

Understanding the header file can be as complex as you'd like to make it. It is merely part specific information that makes writing your program easier. Lots of defines to make accessing ports more readable, set up information, etc. Read the compiler manual and ask specific questions. "I don't understand" is quite a broad statement to try to address for someone trying to help you while sitting at a keyboard.....


Good luck,

John
James909



Joined: 01 Dec 2005
Posts: 3

View user's profile Send private message

PostPosted: Thu Dec 01, 2005 4:52 pm     Reply with quote

Thanks for your reply John, I will try and follow the forum rules in the future, I did register but for some reason it posted under the guess member. That’s all sorted now.

Thanks for the information concerning the .h file. I now understand at face value what it does.

Until yesterday I had never heard of pic and today with only the internet as support I have managed to program my first pic to flash a led! All credit has to go to the author of the code tho.

My goal is to program a Motorola PLL using a 629 pic. So I am on a long mission, but having enough fun flashing led's at the moment!

My next hurdle is to get the PIC using a 4mhz crystal as its clock and not the internal one.
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