LED Flasher

Status
Not open for further replies.

Pappee

New Member
Hi All!

I would like to make a led flasher. I read a source code, what includes the light-time of led.It is:
Code:
t1m       movlw   d'2'
             movwf   cnt1m
tm1lp1   movlw   d'249'
             movwf   cnt500u
tm1lp2   nop
             nop
             decfsz    cnt500u,f
             goto       tm1lp2
             decfsz   cnt1m,f
             goto       tm1lp1
             return
Please help me to understand this code...
Could someone tell me, how can i calculate the lighting time of the led when i use a 10Mhz oscillator?
Please write someone a sort source, that drives a led for example:

500 ms ON
1 s OFF


Thanx a lot:

Pappee
 
Well there are two ways to go about this. First of all this would be easier with a 4MHz crystal as this means each instruction in ASM takes 1microsecond.

You could either have a delay that loops 500 times turn LED off and wait for another 500ms but twice this time and turn it on...or poll the TMR0 overflow flag so that each time it passes 255 this flag goes off - you know so much time has passed (and you can scale it with the pre-scaler).

#2: With C:

include <pic.h>
include "delay.h"

int main(void);

int main()
{
PORTA = 0x00;
TRISA = 0x00;

while(1)
{
PORTA = 0x01;
Delay(1);
// asm("clrwdt");
// Uncomment if you enable the WDT
PORTA = 0x00;
DelayMs_100(5);
}
}

The Delay/Delay_Ms routines were added into the default *delay* file supplied with PICC-Lite. Also this code doesn't depend on the crystal used, just make sure delay.h is altered respectively and compiled with the -DXTAL flag correctly too with full optimisations (-O -Zg9)

>> I've not said everything here as it would take the fun out this. If you want to learn for the first time do it with ASM then get to C, else you won't realise what's going on

Still a uC seems like a waste if *all* you want to do is flash LEDs

--Mike
 
Pappee said:
Could someone tell me, how can i calculate the lighting time of the led when i use a 10Mhz oscillator?
Please write someone a sort source, that drives a led for example:

Check my tutorials, the first ones of which flash LED's.
 
Thanx

Thank you very much all, for help. This forum is great, and they are great programmer and great person, too.

Thanx!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…