Subversion Repositories svnkaklik

Rev

Rev 371 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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