PIC16F877A ile DC motor hız kontrolü
/* DC MOTOR KONTROL
CODE BY YAHYA KARALİ
*/
#include <16F877A.h>
#device ADC=8
#FUSES NOWDT,xt //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP
#use delay(crystal=4000000)
int X,son;
void main()
{
setup_timer_2(T2_DIV_BY_16,255, 1);
setup_ccp1(CCP_PWM); // CCP1 PWM moduna ayarlanıyor
setup_ccp2(CCP_off);
setup_adc(adc_clock_div_8);
setup_port_a(AN0);
set_adc_channel( 0 );
delay_ms(100);
while(TRUE)
{
X=read_adc();
delay_ms(10); // port okuduktan sonra belli bir süre beklenmelidir
if(son!=x)
{
set_pwm1_duty(X);
son=x;
}
}
}
Proje Dosyaları İNDİR