Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 364 → Rev 365

/roboti/Robotour/SW/motor/motor.c
0,0 → 1,86
#include "motor.h"
#use i2c(Slave,Fast,sda=PIN_B1,scl=PIN_B4,force_hw,address=0xA0) // Motor 1
//#use i2c(Slave,Fast,sda=PIN_B1,scl=PIN_B4,force_hw,address=0xA2) // Motor 2
 
#define H1 PIN_A1
#define L1 PIN_A2
#define H2 PIN_A3
#define L2 PIN_A4
 
signed int8 command;
 
#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
output_low(H1);
output_low(L1);
output_low(H2);
output_low(L2);
 
state = i2c_isr_state();
 
if(state < 0x80) //Master is sending data
{
output_toggle(PIN_A0);
command = i2c_read();
}
if(state == 0x80) //Master is requesting data
{
i2c_write(command);
}
}
 
 
void main()
{
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while(true)
{
 
if (0==command)
{
output_low(H1); // stop
output_low(H2);
output_low(L1);
output_low(L2);
continue;
};
if (command>0)
{
output_high(H1); // vpred
output_low(H2);
output_low(L1);
output_high(L2);
}
else
{
output_low(H1); // vzad
output_high(H2);
output_high(L1);
output_low(L2);
};
delay_us(127-abs(command));
output_low(H1);
output_low(H2);
output_low(L1);
output_low(L2);
}
}