#device PIC18F4680
#include <18f4680.h>
#fuses xt,nowdt,noprotect, nobrownout, nolvp, noput, nowrt, nocpd
#use delay (clock=4000000)
#use fast_io(b)
unsigned int16 sayac = 0, hedef_ileri = 0, hedef_geri=0, yon=1;
#int_timer1
void timer1_interrupts()
{
set_timer1(64923);
output_high(pin_c2);
delay_us(20);
output_low(pin_c2);
sayac++;
if(sayac==hedef_ileri)
{
yon=2;
output_low(pin_c1);// motor geri gidiyor
}
if(sayac==hedef_geri)
{
sayac=0;
yon=1;
output_high(pin_c1);// motor yönü belirlendi
//disable_interrupts(int_timer1);// motor calısıyor fakat pulse uretmıyor
}
}
void main()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //262 ms overflow //65,5 ms overflow
setup_timer_2 (T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
set_tris_b(0x00);
output_b(0x00);
set_tris_c(0x00);
output_c(0x00);
enable_interrupts(INT_timer1);
enable_interrupts(GLOBAL);
output_high(pin_c3);// motor aktif
delay_ms(100);
output_high(pin_c1);// motor yönü belirlendi
yon=1;//ileri yon
delay_us(50);
hedef_ileri=3200;//400*8
hedef_geri=6400;
sayac=0;
set_timer1(64923);
while(TRUE)
{
//TODO: User Code
}
}