Subversion Repositories svnkaklik

Rev

Rev 366 | Go to most recent revision | Blame | Last modification | View Log | Download

#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;  // rozsah +-127

#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()
{
   int8 speed;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
//   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS);
   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);

   command=0;  // zastaveni po resetu

   while(true)
   {

      if ((0==command) || (command>127) || (command<-127)) // prikaz na odpojeni mustky nebo chybna hodnota
      {
         output_low(H1);      // stop
         output_low(H2);
         output_low(L1);
         output_low(L2);
         continue;
      };

      speed=command+127;   // posunuti 0 pro zaporna cisla

      output_a(0b10010);
      delay_us(speed);
      output_a(0);
      delay_us(1);
      restart_wdt();
      output_a(0b01100);
      delay_us(254-speed);
      output_a(0);
      delay_us(1);

/*
      output_high(H1);     // vpred
      output_high(L2);
      delay_us(speed);

      output_low(H1);      // stop, aby se neseply tranzistory proti sobe!
      output_low(H2);
      output_low(L1);
      output_low(L2);

      output_high(H2);     // vzad
      output_high(L1);
      delay_us(32-speed);

      output_low(H1);      // stop, aby se neseply tranzistory proti sobe!
      output_low(H2);
      output_low(L1);
      output_low(L2);
*/
   }
}