Subversion Repositories svnkaklik

Rev

Rev 366 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 366 Rev 368
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;
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_low(H1);
17
   output_low(H1);
18
   output_low(L1);
18
   output_low(L1);
19
   output_low(H2);
19
   output_low(H2);
20
   output_low(L2);
20
   output_low(L2);
21
 
21
 
22
	state = i2c_isr_state();
22
	state = i2c_isr_state();
23
 
23
 
24
	if(state < 0x80)							//Master is sending data
24
	if(state < 0x80)							//Master is sending data
25
	{
25
	{
26
      output_toggle(PIN_A0);
26
//      output_toggle(PIN_A0);
27
		command = i2c_read();
27
		command = i2c_read();
28
	}
28
	}
29
   
29
 
30
	if(state == 0x80)							//Master is requesting data
30
	if(state == 0x80)							//Master is requesting data
31
	{
31
	{
32
		i2c_write(command);
32
		i2c_write(command);
33
	}
33
	}
34
}
34
}
35
 
35
 
36
 
36
 
37
void main()
37
void main()
38
{
38
{
-
 
39
   int8 speed;
39
 
40
 
40
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
41
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
41
   setup_adc(ADC_OFF);
42
   setup_adc(ADC_OFF);
42
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
43
//   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
-
 
44
   setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS);
43
   setup_timer_1(T1_DISABLED);
45
   setup_timer_1(T1_DISABLED);
44
   setup_timer_2(T2_DISABLED,0,1);
46
   setup_timer_2(T2_DISABLED,0,1);
45
   setup_comparator(NC_NC_NC_NC);
47
   setup_comparator(NC_NC_NC_NC);
46
   setup_vref(FALSE);
48
   setup_vref(FALSE);
47
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
49
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
48
   
50
 
49
   enable_interrupts(GLOBAL);
51
   enable_interrupts(GLOBAL);
50
   enable_interrupts(INT_SSP);
52
   enable_interrupts(INT_SSP);
-
 
53
 
-
 
54
   command=0;  // zastaveni po resetu
51
   
55
 
52
   while(true)
56
   while(true)
53
   {
57
   {
54
 
58
 
55
      if (0==command)
59
      if ((0==command) || (command>127) || (command<-127)) // prikaz na odpojeni mustky nebo chybna hodnota
56
      {
60
      {
57
         output_low(H1);      // stop
61
         output_low(H1);      // stop
58
         output_low(H2);
62
         output_low(H2);
59
         output_low(L1);
63
         output_low(L1);
60
         output_low(L2);
64
         output_low(L2);
61
         continue;
65
         continue;
62
      };
66
      };
-
 
67
 
-
 
68
      speed=command+127;   // posunuti 0 pro zaporna cisla
-
 
69
 
63
      if (command>0)
70
      output_a(0b10010);
64
      {
71
      delay_us(speed);
65
         output_high(H1);     // vpred
72
      output_a(0);
66
         output_low(H2);
73
      delay_us(1);
67
         output_low(L1);
74
      restart_wdt();
68
         output_high(L2);
75
      output_a(0b01100);
-
 
76
      delay_us(254-speed);
69
      }
77
      output_a(0);
70
      else
78
      delay_us(1);
-
 
79
 
71
      {
80
/*
72
         output_low(H1);      // vzad
81
      output_high(H1);     // vpred
73
         output_high(H2);
82
      output_high(L2);
-
 
83
      delay_us(speed);
-
 
84
 
-
 
85
      output_low(H1);      // stop, aby se neseply tranzistory proti sobe!
74
         output_high(L1);
86
      output_low(H2);
75
         output_low(L2);
87
      output_low(L1);
76
      };
88
      output_low(L2);
-
 
89
 
77
      delay_us(abs(command));
90
      output_high(H2);     // vzad
78
      output_low(H1);
91
      output_high(L1);
-
 
92
      delay_us(32-speed);
-
 
93
 
-
 
94
      output_low(H1);      // stop, aby se neseply tranzistory proti sobe!
79
      output_low(H2);
95
      output_low(H2);
80
      output_low(L1);
96
      output_low(L1);
81
      output_low(L2);
97
      output_low(L2);
-
 
98
*/
82
   }
99
   }
83
}
100
}
84
 
101
 
85
 
102
 
86
 
103