Ðề tài: timer
View Single Post
Old 23-03-2010, 08:39 PM   #4
dienbk36
Nhập môn đệ tử
 
Tham gia ngày: Jan 2010
Bài gửi: 6
:
//minh vua viet dc chuong trinh tao tre 0,5s dung timer0,ban thu doc xem co giup gi dc ko nhe
#include<16f877a.h>
#byte PORTB=0x06
#byte TRISB=0x86

#use delay(clock=20000000)
#int_timer0
int16 count=0;
//chuong trinh ngat timer0
void interrupts_timer0()
{
set_timer0(0);//khoi tao gia tri dem ban dau la 0
++count;
if(count==39062)//Ttimer0=256*3906220000000)=0,5
{
count=0;

PORTB^=(1<<0);
}
}
//chuong trinh chinh

void main()
{
TRISB=0x00;//dat cac chan cua portb o la chan ra
PORTB=1;//dat dien ap cao cho pin RBO}
enable_interrupts(int_timer0);//cho phep ngat timer0
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); //prescaler=1:256
enable_interrupts(global);


while(1)
{
interrupts_timer0();
}


}
dienbk36 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn