Ðề tài: Đo độ rộng xung
View Single Post
Old 15-11-2010, 05:17 PM   #1
xuanmanh88
Nhập môn đệ tử
 
Tham gia ngày: Nov 2010
Bài gửi: 1
:
Unhappy Đo độ rộng xung

Các anh xem hộ em code này với,em sai ở đâu mà không đo được độ rộng xung.

#include <16F877.h>
#use delay(clock=20000000)
#fuses HS,NOWDT
#include <lcd.c>
#define LCD_ENABLE_PIN PIN_D3
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#use fast_io(c)
unsigned int32 overflow_count;
float end_time;
float pulse_ticks;

#int_TIMER1
void TIMER1_isr()
{
++overflow_count;
}

#int_CCP2
void CCP2_isr()
{

end_time = get_timer1();
pulse_ticks = (0x10000 * overflow_count) + end_time;

LCD_init();
printf(lcd_putc,"\rdo rong: %u", pulse_ticks);
}
#int_CCP1
void CCP1_isr()
{
overflow_count = 0;
set_timer1(0x00);
}

void main() {
set_tris_c(0xff);
set_tris_b(0xff);
lcd_putc("STARTING");
for(i = 1; i < 9; i++){
lcd_putc(".");
delay_ms(100);
}
setup_ccp1(CCP_CAPTURE_FE);
setup_ccp2(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_CCP2);
enable_interrupts(INT_CCP1);
enable_interrupts(global);

while(1){

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