PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   cần Giúp hàm Delay_ms... (http://www.picvietnam.com/forum/showthread.php?t=32746)

thuanbk1989 02-09-2013 10:11 AM

cần Giúp hàm Delay_ms...
 
hi!
Chào mọi người. mọi người giúp e với nhé.
E dùng lệnh delay_ms(10000); nói chung là lệnh delay thì nó chạy k có đúng lệnh delay_ms(10000) mà nó chạy 13,5s lận. e phải làm sao giờ tại e cần độ chính xác xíu.
Nọi thứ đều hoạt động tốt chỉ sai chỗ này thui .e có dùng lênh #use delay( clock = 20000000)
CODE:
#int_EXT
#use delay( clock = 20000000)
void EXT_isr(void)
{
//delay_ms(1000);
Output_high(pin_a1);
//delay_ms(2000);
}
void main()
{

setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
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_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
ext_int_edge (0 ,L_TO_H) ; //chon kieu ngat tu muc thap len cao
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

// TODO: USER CODE!!
set_tris_a(0b00000101);
//set_tris_c(0b00000000);

while(1) {
Output_high(pin_a1);
delay_ms(5000);
Output_low(pin_a1);
delay_ms(5000);

}
cảm ơn moi người trước nhé

thuanbk1989 02-09-2013 10:28 AM

Ai ghé qua giúp e nhé

thuanbk1989 02-09-2013 05:33 PM

Chawcs ngày lễ không ai giúp cả

buivantuyen89th 11-09-2013 05:02 PM

Trích:

Nguyên văn bởi thuanbk1989 (Post 82852)
hi!
Chào mọi người. mọi người giúp e với nhé.
E dùng lệnh delay_ms(10000); nói chung là lệnh delay thì nó chạy k có đúng lệnh delay_ms(10000) mà nó chạy 13,5s lận. e phải làm sao giờ tại e cần độ chính xác xíu.
Nọi thứ đều hoạt động tốt chỉ sai chỗ này thui .e có dùng lênh #use delay( clock = 20000000)
CODE:
#int_EXT
#use delay( clock = 20000000)
void EXT_isr(void)
{
//delay_ms(1000);
Output_high(pin_a1);
//delay_ms(2000);
}
void main()
{

setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
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_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
ext_int_edge (0 ,L_TO_H) ; //chon kieu ngat tu muc thap len cao
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

// TODO: USER CODE!!
set_tris_a(0b00000101);
//set_tris_c(0b00000000);

while(1) {
Output_high(pin_a1);
delay_ms(5000);
Output_low(pin_a1);
delay_ms(5000);

}
cảm ơn moi người trước nhé

Mình cũng chưa có điều kiện thử độ chính xác của delay.hi. nhưng mình nghĩ thế này.bạn làm xem có được không nhé.
bỏ hết các ngắt khác ( chỉ để mình ngắt ngoài để kiểm tra) và chuyển lệnh use delay lên bên trên int_EXT.
Chúc bạn thành công!

binhbk247 18-09-2013 11:19 AM

Delay bị sai chủ yếu do mạch. Trong code chỉ cần bạn khai báo đúng tần số thạch anh mà bạn sử dụng là được. Nếu đã khai báo đúng rồi mà vẫn sai thì có thể do thạch anh hư, do chip ko nhận thạch anh và cũng có thể do 2 con tụ dao dộng. Bạn thử thay thạch anh thử. Mình gặp nhiều trường hợp bị lỗi thạch anh rồi lắm


Múi giờ GMT. Hiện tại là 11:50 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam