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