PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT 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

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 30-08-2012, 09:42 PM   #1
qloi
Đệ tử 3 túi
 
Tham gia ngày: Sep 2010
Bài gửi: 55
:
Arrow mTouch dùng phương pháp CVD

Các cao nhân có ai đã làm touch button theo phương pháp CVD sủ dụng ADC hoàn chỉnh cho mình hỏi đoạn code mình viết bên dưới theo như chỉ dẫn của Microchip nhưng có vẻ nó hoạt động không ổn định(không dứt khoát về 0 hoặc 1 mà nháy nháy hoặc sáng mờ) và không được nhạy lắm.khi lập trình 1 nút thì còn đở , bổ sung thêm 1 nút thì có khi vừa khởi động là sáng lun,có khi rờ nút này thì đèn kia lại sáng.giúp dùm nhé,ai có code điều khiển nhiều nút theo phương pháp này cho mình tham khảo với ?

Code:
#include <16f88.h>
#device *=16 ADC=10
#fuses intrc
#use delay(clock=4000000)
#use fast_io(a)
#use fast_io(b)
//#byte porta = 0x05

int16 average[5];
int16 temp=0,temp1=0,sens1=0,sens2=0;
unsigned char i;

void read_sensor1()
{
   set_adc_channel(0);
   set_tris_a(0);
   output_a(0x01);
   set_tris_a(0xff);
   set_adc_channel(1);
   sens1 = read_adc();
   //sens1 = sens1*5;
   delay_us(10);
   if(sens1<temp) output_high(pin_b0);
   else output_low(pin_b0);
   
}
void read_sensor2()
{
   set_adc_channel(0);
   set_tris_a(0);
   output_a(0x01);
   set_tris_a(0xff);
   set_adc_channel(2);
   sens2 = read_adc();
   //sens2 = sens2*5;
   delay_us(10);
   if(sens2<temp1) output_high(pin_b1);
   else output_low(pin_b1);
   
}

void main()
{
   setup_adc(adc_clock_internal);
   setup_adc_ports(all_analog | VSS_VDD);
   set_tris_b(0xc0);
   output_b(0);
   set_adc_channel(0); //chon kenh 0 lam analog in
   set_tris_a(0);          //port a out all
   output_a(0x01);      //set chan a0 = 1
   set_tris_a(0xff);      //set port a in all
   set_adc_channel(1);//chon read adc nut 1
   for(i=0;i<5;i++)       //lay mau 5 lan
   {
      average[i] = read_adc();
      delay_us(8);
      temp = temp + average[i]; //cong don va lay gia tri trung bình
   }
   temp = temp/5;
   
   set_adc_channel(0);
   set_tris_a(0);
   output_a(0x01);
   set_tris_a(0xff);
   set_adc_channel(2);
   for(i=0;i<5;i++)
   {
      average[i] = read_adc();
      delay_us(8);
      temp1 = temp1 + average[i];
   }
   temp1 = temp1/5;

   while(1)
   {
      read_sensor1();
      read_sensor2();
      
      
   }
}
__________________
heart.touching.2010@gmail.com!
qloi 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:45 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