PDA

View Full Version : timer1-giúp mình gấp với


phamtrieu138
16-03-2008, 02:14 AM
#include "C:\Documents and Settings\tungdinh's computer\My Documents\timer0\ff.h"
#use fast_io(c)
#use fast_io(a)
int dem;
#int_TIMER1
TIMER1_isr()
{
if (pin_A4)
{
dem++;
}
set_timer1(1000);
}



void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_timer1(1000);
set_tris_c(0);
set_tris_a(0b111111);
output_high(pin_c1);output_high(pin_c2);
dem=0;
while(dem<5)
{
}
output_low(pin_c1);output_low(pin_c2);
// TODO: USER CODE!!

}
sao mìnhcho A4 1 lần=1 mà c1=0;c2=0????????

0903579509
16-03-2008, 09:38 PM
Bạn nên cho biết rõ yêu cầu của đề tài. Đoạn code trên sau khi reset thì c1=c2=1, khi cho A4 = 1 một khoảng thời gian bằng 4 hoặc 5 lần ngắt timer1 gì đó thì c1 và c2 = 0
Đoạn code Timer1_isr() sửa lại như sau:
#int_TIMER1
TIMER1_isr()
{
if (input(pin_A4)) // sửa ở đây
{
dem++;
}
set_timer1(1000);
}