Subversion Repositories svnkaklik

Rev

Rev 365 | Go to most recent revision | Details | Compare with Previous | 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
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
 
10
signed int8 command;
11
 
12
#INT_SSP
13
void ssp_interupt ()
14
{
15
   BYTE incoming, state;
16
 
17
   output_low(H1);
18
   output_low(L1);
19
   output_low(H2);
20
   output_low(L2);
21
 
22
	state = i2c_isr_state();
23
 
24
	if(state < 0x80)							//Master is sending data
25
	{
26
      output_toggle(PIN_A0);
27
		command = i2c_read();
28
	}
29
 
30
	if(state == 0x80)							//Master is requesting data
31
	{
32
		i2c_write(command);
33
	}
34
}
35
 
36
 
37
void main()
38
{
39
 
40
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
41
   setup_adc(ADC_OFF);
42
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
43
   setup_timer_1(T1_DISABLED);
44
   setup_timer_2(T2_DISABLED,0,1);
45
   setup_comparator(NC_NC_NC_NC);
46
   setup_vref(FALSE);
47
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
48
 
49
   enable_interrupts(GLOBAL);
50
   enable_interrupts(INT_SSP);
51
 
52
   while(true)
53
   {
54
 
55
      if (0==command)
56
      {
57
         output_low(H1);      // stop
58
         output_low(H2);
59
         output_low(L1);
60
         output_low(L2);
61
         continue;
62
      };
63
      if (command>0)
64
      {
65
         output_high(H1);     // vpred
66
         output_low(H2);
67
         output_low(L1);
68
         output_high(L2);
69
      }
70
      else
71
      {
72
         output_low(H1);      // vzad
73
         output_high(H2);
74
         output_high(L1);
75
         output_low(L2);
76
      };
366 kakl 77
      delay_us(abs(command));
365 kakl 78
      output_low(H1);
79
      output_low(H2);
80
      output_low(L1);
81
      output_low(L2);
82
   }
83
}
84
 
85
 
86