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:
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
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: