Conversation Between *06201046* and phamhtruong82
Showing Visitor Messages 1 to 2 of 2
-
-
chao moi người !! xin giúp đỡ mình đang làm đồ án chương trinh chạy mô phỏng ok, nhưng nạp vào ic thực tế thì chân ccp1 không thể điều khiển được và lúc nào cũng ở mức 1. xin mọi ng giúp đỡ vì cũng xắp hết hạn nộp bài rồi đây là code mình dùng l293b.
#include<16f877a.h>
//No Watch Dog Timer
#FUSES NOWDT
#FUSES XT
#FUSES NOPUT
#FUSES NOPROTECT
#FUSES NODEBUG
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOCPD
#FUSES NOWRT
#USE DELAY(CLOCK=10000000)
#use fast_io(b)
#byte portb=0x6
int16 duty=0;
void main()
{
setup_ccp1(CCP_PWM);//khoi tao bo pwm1
setup_timer_2(T2_div_by_16,154,1);//tao xung 1ms
set_pwm1_duty(duty);
while(true)
{
if(!bit_test(portb,0))//che do quay thuan
{
output_bit( pin_c3 , 1 );
output_bit( pin_c4 , 0 );
duty=0;
set_pwm1_duty(duty);
delay_ms(1000);
goto next;
}
if(!bit_test(portb,1))//che do quay nghich
{
output_bit( pin_c3 , 0 );
output_bit( pin_c4 , 1 );
duty=0;
set_pwm1_duty(duty);
delay_ms(1000);
goto next;
}
next:
if(!bit_test(portb,4))//che do off
{
output_bit( pin_c3 , 0 );
output_bit( pin_c4 , 0 );
set_pwm1_duty(0);
}
while(!bit_test(portb,3))//che do tang toc
{delay_ms(1000);
duty=duty < 600 ? duty +10 : 600;
delay_ms(20);
set_pwm1_duty(duty);
break;
}
while(!bit_test(portb,2))//che do giam toc
{
duty=duty >0 ? duty - 10 : 0;
delay_ms(20);
set_pwm1_duty(duty);
break;
}
}
}