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 Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 03-05-2012, 06:01 PM   #1
quanghuan299
Nhập môn đệ tử
 
Tham gia ngày: Mar 2012
Bài gửi: 3
:
Send a message via Yahoo to quanghuan299
giúp em codec điều khiển động cơ này,sai ở đâu?

#include <16F877A.h>
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits

#use delay(clock=24000000)


#define dc_t(x) set_pwm1_duty(x)
#define dc_p(x) set_pwm2_duty(x)
#define dir_t_l output_low(pin_c2) // dc_1 muc thap
#define dir_t_h output_high(pin_c3) // dc_1 muc cao
#define dir_p_l output_low(pin_c0) // dc_2 muc thap
#define dir_p_h output_high(pin_c1) // dc_2 muc cao
/////////////////////////////////////////////
INT8 SENSOR=0xfc;
INT1 LEFT,RIGHT;
INT8 SPEED; //toc do dong co
int8 nguong = 100; // nguong cam bien /////////////////////////////////////////////////////////////////////////
INT8 DELTA_P=0;
INT8 DELTA_T=0;

VOID scan()

{

int8 k;
sensor=0;
for(k=0;k<=5;k++)
{
set_adc_channel(k);
delay_ms(10);
if(read_adc()>150) bit_set(sensor,k);

}

}

VOID TU_DONG_TIEN()
{
if (sensor==0b00100000){dc_t(10);dc_p(60);}
if (sensor==0b00010000){dc_t(10);dc_p(50);}
if (sensor==0b00001000){dc_t(10);dc_p(40);}
if (sensor==0b00001100){dc_t(50);dc_p(50);}
if (sensor==0b00000100){dc_t(60);dc_p(10);}
if (sensor==0b00000010){dc_t(50);dc_p(10);}
if (sensor==0b00000001){dc_t(40);dc_p(0);}
}


void main()
{

setup_timer_2(T2_div_by_4,100,1);
setup_ccp1(ccp_pwm);
setup_ccp2(ccp_pwm);


//Dinh huong cong vao ra
set_tris_a(255); // Cong A vao
set_tris_c(0); // Cong C ra
//set_timer0(0xFFFE);


while(1)
{
scan();
//sensor=0b00000001
void tu_dong_tien();/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//sensor=0b00000000;

}


}
quanghuan299 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

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à 01:22 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