PIC Vietnam

Go Back   PIC Vietnam > Robotics > Cảm biến

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ảm biến Camera, siêu âm, hồng ngoại, gyro, la bàn...

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 18-04-2012, 06:49 PM   #7
hoangson_fet
Nhập môn đệ tử
 
Tham gia ngày: Mar 2012
Bài gửi: 1
:
sửa giúp em với các pro. em điều khiển PWM được rồi theo nhiệt độ LM35 được rồi. còn đo tốc độ DC bằng encoder hiện lên LCD thì hiện 48484848. xem rồi tìm chổ sai giúp em với...(encoder vào chân RA4 của PIC 16F877a)

#include "D:\avr va pic\LM\Theend.h"
#include <LCD.C>
#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#byte portb=0x06
#byte porta=0x05 // khai bao cac dic chi
#byte portD=0x08 // khai bao dia chi cho Port D neu k co khai bao nay thi se k duoc define
#bit dir=0x06.0
#bit tmr1=0x0e.0
#bit tmr0=0x01.0
#bit intcon=0x0b.0
float tocdo,soxung;
int8 a,b,c,d,a1;
int16 sovong,i,count;

#int_rtcc
void Timer0_isr() // Dem so vong quay dong co
{
count++;

}
#int_TIMER1
TIMER1_isr()
{
soxung=count;
set_timer1(55535); // Trong 1ms
if(tmr1==1)
{
intcon=0; //stop ngat
a1=1;
}
}
void hienthi(float x)
{
if(a1==1)
{
tocdo=((float)*(60*x)/(0.01*100));
a=tocdo/1000;
b=(int)(tocdo-1000*a)/100;
c=(int)(tocdo-1000*a-100*b)/10;
d=(int)tocdo%10;
lcd_gotoxy(3,2);
printf(lcd_putc,"%du",a+0x30);
lcd_gotoxy(5,2);
printf(lcd_putc,"%du",b+0x30);
lcd_gotoxy(7,2);
printf(lcd_putc,"%du",c+0x30);
lcd_gotoxy(9,2);
printf(lcd_putc,"%du",d+0x30);
lcd_gotoxy(11,2);
delay_ms(5);
tmr0=0;tmr1=0;
}
}
void vantoc(int val);
void vantoc(int val)
{
setup_ccp1(ccp_pwm);
setup_timer_2(t2_div_by_4,124,1);
Set_pwm1_duty(val);
}
void main()
{
float value;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
delay_ms(1);
set_timer0(0);
set_timer1(55535);
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_1,0,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(0);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_tris_a (0xff);
set_tris_b(0x00);
set_tris_d(0xff);
dir=1;
delay_us(10);
while(1)
{
set_adc_channel(0);
lcd_gotoxy(1,1);
value = read_adc();
delay_us(10);
value = value*455/(225);
printf(lcd_putc,"T=%f C",value);

if(value <20)
{
delay_us(10);
dir=1;
}
if(value>20&& value<23)
{
delay_us(10);
dir=0;
vantoc(50);
}
if(value >23 && value<27)
{
delay_us(10);
dir=0;
vantoc(80);
}
if(value > 27&& value < 30)
{
delay_us(10);
dir=0;
vantoc(110);
}
if(value>30)
{
setup_ccp1(ccp_off);
}
hienthi(sovong);
}

// TODO: USER CODE!!

}
hoangson_fet 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

Similar Threads
Ðề tài Người gửi Chuyên mục Trả lời Bài mới
Mạch đếm dùng cho encoder thaychua Cảm biến 23 17-04-2015 12:54 AM
Encoder: absolute và incremental? Dùng loại nào? falleaf Cơ cấu chấp hành (Actuator) 43 13-01-2012 01:00 AM
Encoder: absolute và incremental? Dùng loại nào? falleaf Cảm biến 40 21-05-2011 01:55 PM
Các vấn đề về encoder? caonam Cơ cấu chấp hành (Actuator) 14 25-11-2010 12:01 PM
cần mua encoder tuyệt đối kienvq Tìm mua sản phẩm 1 08-05-2006 09:50 PM


Múi giờ GMT. Hiện tại là 02:01 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