Professional Documents
Culture Documents
22-03-2010, 05:00 PM
hix ai gii thch dm mnh chng trnh ngt ny vi!Mnh thc s rt c gng c nhng chu
hiu lm!thanks
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#byte PORTB = 0x06
int16 count;
int8 a;
//Chuong trinh ngat TMR0
#int_timer0
void interrupt_timer0()
{
set_timer0(6);
++count;
if(count == 2000) // 2000*500us = 500000us = 1s
{
count=0;
rotate_left(&a,1);
}
}
//Chuong trinh chinh
void main(void)
{
set_tris_b(0);
enable_interrupts(int_timer0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
enable_interrupts(global);
set_timer0(6);// T_dinhthi = 2*(256 - 6)*1us = 500us
a = 0x01;
while(true)
{
PORTB = a;
}
}
+set_tris_b(0);//nh ngha portb l u ra s(nu nh vng lp while bn khai bo
output_b(a); th cu lnh set_tris_b(0); l khng cn thit.
+enable_interrupts(int_timer0);//mi bt u chng trnh, bn cho timer0 lm vic(bt u tnh
+setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2); //ch l chia tn s
timer0 8bit, m t 0-->255, v sau trng m li t 0. Mi ln trn nh vy l c bn tnh
thi gian nh sau:
-bn dng thch anh 4M=4000000hz. nh vy mi ln trn th c thi gian l
Delfy_Coltech
14-03-2011, 08:34 PM
setup_timer1(TMR_INTERNAL | TMR_DIV_BY_8, 4096);
Th cn dng setup Timer1 th ny cc bn gii thch gim?
Thanks!
vBulletin v3.7.2, Copyright 2000-2011, Jelsoft Enterprises Ltd.