Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
365 kakl 1
#include "motor.h"
366 kakl 2
//#use i2c(Slave,Fast,sda=PIN_B1,scl=PIN_B4,force_hw,address=0xA0) // Motor 1
368 kakl 3
//#use i2c(Slave,Fast,sda=PIN_B1,scl=PIN_B4,force_hw,address=0xA2) // Motor 2
365 kakl 4
 
5
#define H1 PIN_A1
6
#define L1 PIN_A2
7
#define H2 PIN_A3
8
#define L2 PIN_A4
9
 
368 kakl 10
signed int8 command;  // rozsah +-127
365 kakl 11
 
12
#INT_SSP
13
void ssp_interupt ()
14
{
15
   BYTE incoming, state;
368 kakl 16
 
371 kakl 17
   output_a(0);         // vypnuti vsech budicu
365 kakl 18
 
19
	state = i2c_isr_state();
20
 
21
	if(state < 0x80)							//Master is sending data
22
	{
23
		command = i2c_read();
24
	}
368 kakl 25
 
365 kakl 26
	if(state == 0x80)							//Master is requesting data
27
	{
28
		i2c_write(command);
29
	}
30
}
31
 
32
 
33
void main()
34
{
368 kakl 35
   int8 speed;
365 kakl 36
 
37
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
38
   setup_adc(ADC_OFF);
368 kakl 39
   setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS);
365 kakl 40
   setup_timer_1(T1_DISABLED);
41
   setup_timer_2(T2_DISABLED,0,1);
42
   setup_comparator(NC_NC_NC_NC);
43
   setup_vref(FALSE);
44
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
368 kakl 45
 
365 kakl 46
   enable_interrupts(GLOBAL);
47
   enable_interrupts(INT_SSP);
368 kakl 48
 
49
   command=0;  // zastaveni po resetu
50
 
365 kakl 51
   while(true)
52
   {
53
 
368 kakl 54
      if ((0==command) || (command>127) || (command<-127)) // prikaz na odpojeni mustky nebo chybna hodnota
365 kakl 55
      {
56
         output_low(H1);      // stop
57
         output_low(H2);
58
         output_low(L1);
59
         output_low(L2);
60
         continue;
61
      };
368 kakl 62
 
63
      speed=command+127;   // posunuti 0 pro zaporna cisla
64
 
371 kakl 65
      output_a(0b10010);   // vpred
368 kakl 66
      delay_us(speed);
371 kakl 67
      output_a(0);         // vypnuti vsech budicu
368 kakl 68
      delay_us(1);
69
      restart_wdt();
371 kakl 70
      output_a(0b01100);   // vzad
368 kakl 71
      delay_us(254-speed);
371 kakl 72
      output_a(0);         // vypnuti vsech budicu
368 kakl 73
      delay_us(1);
365 kakl 74
   }
75
}
76
 
77
 
78