quick example of it
Code:' ' Pic Configuration ' ================= DEFINE LOADER_USED 1 DEFINE OSC 20 ' ' Hardware configuration ' ====================== TRISA = 255 ' PORTA : all input CMCON = 7 ' disable analog comparator ADCON1 = 7 ' disable ADCs OPTION_REG = %11100001 ' TMR0 clock source = T0CKI (RA.4) ' Source edge : low to high ' Prescaller assign to TMR0 ' rate 1:4 ' ' Serial Communication definition ' =============================== DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 24h DEFINE HSER_SPBRG 129 ' 9600 Bauds ' ' Variables definition ' =================== Frequency var word TMR0IF var INTCON.2 ' ' ------------------------[Program Start Here]-------------------------- ' Start: TMR0=0 ' clear TMR0 IF PORTA.4=1 THEN START ' wait 'till T0CKI goes to low PAUSE 100 ' sampling time Frequency=TMR0<<2 ' multiply result to compensate the 1:4 rate if tmr0if then ' Overflow? frequency over 256*4=1.024 Khz hserout ["Overflow Happened",13,10] ' tmr0if=0 ' clear overflow flag else hserout ["Frequency:",dec Frequency dig 2,".",_ ' display results dec Frequency dig 1,_ dec Frequency dig 0," KHZ",13,10] endif goto start




Bookmarks