Pic programlama ccs c timer1 zamanlayıcı örnek
#include<12f683.h>
#fuses nowdt,noprotect,nocpd,nomclr,noput,intrc_io,nobrownout
#use delay(internal=4m)
#use fast_io(a)
#byte TRISA = 0x85
#byte PORTA = 0x05
#byte PIR1 = 0x0C
#bit TMR1IF = PIR1.0
int16 TMR1 = 34286;
#int_timer1
void sayma()
{
if(TMR1IF)
{
PORTA = PORTA | 0x02; //GP1=1
output_toggle(pin_a0);
}
set_timer1(TMR1);
//sayma 250 mili saniye
//0.25 = (4/Fosc)*prescaler*(65536-valor)
//Fosc = 4mhz,prescaler = 1:8
//0.25 = (4/4000000)*8*(65536-valor)
// 0,524288-0,25
// TMR1 = ---------------
// 8e-6
// TMR1 = 34286
}
void main()
{
TRISA = TRISA & 0xFC; // GP0,GP1 output
PORTA = PORTA & 0xFC; // GP0,GP1 = 0
setup_timer_1(t1_internal | t1_div_by_8); // konfigirasyon
set_timer1(TMR1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(true)
{
if(!TMR1IF)
PORTA = PORTA & ~0x02; // GP1 = 0
}
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...