PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 09-10-2010, 10:38 AM   #1
agreement
Nhập môn đệ tử
 
Tham gia ngày: Mar 2009
Bài gửi: 1
:
đo độ rộng xung với timer1

chào các bạn. mình muốn sử dụng chức năng capture để đo độ rộng xung rồi chuyển lên LCd, nhung kq nhận được luôn là 0. Mọi người xem và giải đáp giùm. thanks!
[code]
#include <16F877.h>
#use delay(clock=10000000)
#fuses HS,NOWDT
#include <lcd.c>
#define LCD_ENABLE_PIN PIN_D0
#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


int overflow_count;
unsigned int32 start_time, end_time;
int32 pulse_ticks;

#int_TIMER1
void TIMER1_isr()
{
++overflow_count; //increment whenever an overflow occurs
}

#int_CCP2
void CCP2_isr()
{
end_time = CCP_1; //read captured timer ticks
start_time = CCP_2; //read captured timer ticks
//check for pulse time (in ticks) accounting for anyoverflow that may have occurred
pulse_ticks = (0x10000 * overflow_count) - start_time + end_time;
overflow_count = 0; //clear overflow counts

}

void main() {
setup_ccp1(CCP_CAPTURE_FE);
setup_ccp2(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);//set timer1 to run at system clock/4
enable_interrupts(INT_TIMER1); //unmask Timer1 overflow interrupt
enable_interrupts(INT_CCP2); //unmask capture event interrupt
enable_interrupts(global); //enable all unmasked interrupts

while(1){
LCD_init();
printf(lcd_putc,"\rdo rong: %u", pulse_ticks); }
}
[code]
File Kèm Theo
File Type: rar mach.rar (63 Bytes, 32 lần tải)
agreement vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


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


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam