Oscilátor
Moderátor: Moderátoři
Kód: Vybrat vše
#include <p18f2550.h>
#include <delays.h>
#include "configuration.h"
//#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
//#pragma config WDT = OFF //Disable watchdog timer
#define LEDPin1 LATCbits.LATC0
#define LEDTris1 TRISCbits.TRISC0
#define LEDPin2 LATCbits.LATC1
#define LEDTris2 TRISCbits.TRISC1
void main()
{
LEDTris1 = 0;//Set LED Pin data direction to OUTPUT
LEDPin1 = 1;//Set LED Pin
LEDTris2 = 0;//Set LED Pin data direction to OUTPUT
LEDPin2 = 1;//Set LED Pin
while(1)
{
LEDPin1 = ~LEDPin1;//Toggle LED Pin
Delay10KTCYx(25);//Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles)
LEDPin2 = ~LEDPin1;//Toggle LED Pin
Delay10KTCYx(25);//Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles)
}
}
meníte niekde v kóde definovanie frekvenciu procesoru? u atmelov je to príkaz pred kniznicou delay(ako som spomínal, pic nepoznám, ale ta filozofia bude rovnaká, ako už spomínal majsi)
Kód: Vybrat vše
#define F_CPU 16E6 // 16 MHZ rychlost uPC
#include <util/delay.h>
Vies vobec co ma robit tato funkcia???
Delay10KTCYx(25);
caka 10000*25 instrukcnych cyklov. Inak povedane sa 250000 krat vykona instrukcia NOP. To znamena ze cim rychlejsi das oscilator tym kratsie sa tych 10000*25 instrukcnych cyklov vykona. Konkretne toto
Delay10KTCYx(25); trva 0,05sekundy
rata sa to asi takto
1 TCY = 1/Fosc/4 = 1/(20 000 000/4) = 0.000 000 2s = 0.2us
pre 2.5s = 2.5/0.000 000 2 = 12 500 000 TCY
takze pre delay dlhy 2.5 sekundy pouzijes pri 20 MHz
Delay10KTCYx(1250);
Delay10KTCYx(25);
caka 10000*25 instrukcnych cyklov. Inak povedane sa 250000 krat vykona instrukcia NOP. To znamena ze cim rychlejsi das oscilator tym kratsie sa tych 10000*25 instrukcnych cyklov vykona. Konkretne toto
Delay10KTCYx(25); trva 0,05sekundy
rata sa to asi takto
1 TCY = 1/Fosc/4 = 1/(20 000 000/4) = 0.000 000 2s = 0.2us
pre 2.5s = 2.5/0.000 000 2 = 12 500 000 TCY
takze pre delay dlhy 2.5 sekundy pouzijes pri 20 MHz
Delay10KTCYx(1250);