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)
-   -   dùng capture của pic 16f887 để đo độ rộng xung (http://www.picvietnam.com/forum/showthread.php?t=32363)

navypro 01-06-2013 01:46 PM

dùng capture của pic 16f887 để đo độ rộng xung
 
các cao thủ cho em hỏi quá trình đo độ rộng xung dùng capture của con 887 có giồng như con 877a không ah em dùng code này mà không đo được mong các cao thủ chỉ giáo, code này với con 877a chạy ngon ah

#include <16F887.h>
#use delay(clock=4000000)
#fuses XT
#include "hienthiLCD.c"

float g;
int count;
unsigned int32 suon_len, suon_xuong;
int32 d;
int8 x;

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

#int_CCP2
void CCP2_isr()
{
suon_len = CCP_2;
suon_xuong = CCP_1;
d = suon_len-suon_xuong;
set_timer1(1);



}


void main()
{

setup_ccp2(CCP_CAPTURE_FE);
setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_4 );//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(true)
{

LCD_init();
if(d<126)
{
g=-1*((126-d)*30/75);

}
if(d>126)
{
x=(d-126)%5;
if(x==0)
g=((d-126)*30/75);
else
g=1+((d-126)*30/75);
}
if(d==126)
g=0;

lcd_gotoxy(1,1);
printf(lcd_putc,"do rong: %lu", d);
lcd_gotoxy(1,2);
printf(lcd_putc,"goc = %f",g);
delay_ms(2000);
}
}


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

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