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
372 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
 
372 kakl 49
   command=-128;  // zastaveni po resetu
368 kakl 50
 
365 kakl 51
   while(true)
52
   {
53
 
372 kakl 54
      if (command==-128) // prikaz na odpojeni mustku nebo chybna hodnota
365 kakl 55
      {
372 kakl 56
         output_a(0);   // volnobeh
365 kakl 57
         continue;
58
      };
368 kakl 59
 
60
      speed=command+127;   // posunuti 0 pro zaporna cisla
61
 
371 kakl 62
      output_a(0b10010);   // vpred
368 kakl 63
      delay_us(speed);
371 kakl 64
      output_a(0);         // vypnuti vsech budicu
368 kakl 65
      delay_us(1);
66
      restart_wdt();
371 kakl 67
      output_a(0b01100);   // vzad
368 kakl 68
      delay_us(254-speed);
371 kakl 69
      output_a(0);         // vypnuti vsech budicu
368 kakl 70
      delay_us(1);
365 kakl 71
   }
72
}
73
 
74
 
75