gia thiet bi ve sinh chinh hang, doc truyen truyện tranh cười Việt Nam doc truyen ma kinh di truyen tinh yeu lãng mạn, tin tuc onlinethiet bi nha ve sinh Việt Nam - Voi hoa sen

kiem tien online

[Code PIC] Mạch đo điện dung

Được đăng bởi NetVN Chủ Nhật, 22 tháng 4, 2012 0 nhận xét
Code PIC mạch đo điện dung:
************************************************** *****************************
Project : Frequency Measurement
Author : pk
************************************************** *****************************/
#include <16f887.h>
#device *=16
#FUSES NOWDT, NOPUT,XT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock = 4M)


#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

/*
#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_C3
#define LCD_DATA4 PIN_E2
#define LCD_DATA5 PIN_E1
#define LCD_DATA6 PIN_E0
#define LCD_DATA7 PIN_A5
*/

#include <lcd.c>
#use fast_io(c)
//************************************************** ****************************
int i;
float temp,verify;
//************************************************** ****************************

#INT_CCP1
void synchronous_re(){
temp = get_timer1();
set_timer1(0);
}
//------------------------------------------------------------------------------
#INT_CCP2
void synchronous_fe(){
temp = get_timer1();
set_timer1(0);
}
//************************************************** ****************************
void lcd_put_int(int num){
int temp;
unsigned char i = 0, c[5];
temp = num;
if (temp != 0) {
while(temp){
c[i++] = temp%10;
temp /= 10;
}
while(i) lcd_putc(c[--i] + '0');
}
else lcd_putc('0');
}
//************************************************** ****************************
void lcd_put_float(float num){
unsigned int temp;

temp = num/1;
lcd_put_int(temp);
temp = (num - temp)*100;
lcd_putc(',');
lcd_put_int(temp);

}
//************************************************** ****************************
void main(){
set_tris_c(0xff);
set_tris_b(0xff);

lcd_init();
lcd_putc("STARTING");
for(i = 1; i < 9; i++){
lcd_putc(".");
delay_ms(100);
}
SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_4);
//SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);

SETUP_CCP1(CCP_CAPTURE_RE);
SETUP_CCP2(CCP_CAPTURE_FE);

ENABLE_INTERRUPTS(INT_CCP1);
ENABLE_INTERRUPTS(INT_CCP2);
ENABLE_INTERRUPTS(global);

lcd_putc('\f');
lcd_putc("TAN SO HIEN TAI:");

while(1){
if(temp != verify){
verify = temp;
lcd_gotoxy(1,2);
lcd_putc(" ");
lcd_gotoxy(5,2);
lcd_put_float(500000/temp);
lcd_putc("Hz");
delay_ms(100);
}
}
}

0 nhận xét:

Đăng nhận xét

Lưu trữ bài viết

Người theo dõi

Thống kê truy cập