1 |
//#include "C:\Users\Honza\Documents\pic\I2C_HUB\main.h" |
- |
|
2 |
|
- |
|
3 |
#include "main.h" |
1 |
#include "main.h" |
4 |
//I2CHUB |
2 |
//I2CHUB |
5 |
//ADRESA pro èteni 0xE1 |
3 |
//ADRESA pro èteni 0xE1 |
6 |
//pro zápis 0xE0 |
4 |
//pro zápis 0xE0 |
7 |
|
5 |
|
8 |
|
- |
|
9 |
#define EEPROM_SDA PIN_C4 |
- |
|
10 |
#define EEPROM_SCL PIN_C3 |
- |
|
11 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
6 |
#use i2c(master, sda=PIN_C4, scl=PIN_C3) |
12 |
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD |
7 |
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD |
13 |
|
8 |
|
14 |
void setHUB(int d) //vstupuje 1-8 |
9 |
void setHUB(int d) //vstupuje 1-8 |
15 |
//hodnota udava jaky port bude pripojen na master I2C |
10 |
//hodnota udava jaky port bude pripojen na master I2C |
16 |
//zde je nastaveno propojeni jen jedne brany, je mozne propojit i vice bran naraz |
11 |
//zde je nastaveno propojeni jen jedne brany, je mozne propojit i vice bran naraz |
17 |
{ |
12 |
{ |
18 |
switch (d) { |
13 |
switch (d) { |
19 |
|
14 |
|
20 |
case 1: d=0x01; |
15 |
case 1: d=0x01; |
21 |
|
16 |
|
22 |
break; |
17 |
break; |
23 |
|
18 |
|
24 |
case 2: d=0x02; |
19 |
case 2: d=0x02; |
25 |
|
20 |
|
26 |
break; |
21 |
break; |
27 |
|
22 |
|
28 |
case 3: d=0x04; |
23 |
case 3: d=0x04; |
29 |
|
24 |
|
30 |
break; |
25 |
break; |
31 |
|
26 |
|
32 |
case 4: d=0x08; |
27 |
case 4: d=0x08; |
33 |
|
28 |
|
34 |
break; |
29 |
break; |
35 |
case 5: d=0x10; |
30 |
case 5: d=0x10; |
36 |
|
31 |
|
37 |
break; |
32 |
break; |
38 |
|
33 |
|
39 |
case 6: d=0x20; |
34 |
case 6: d=0x20; |
40 |
|
35 |
|
41 |
break; |
36 |
break; |
42 |
case 7: d=0x40; |
37 |
case 7: d=0x40; |
43 |
|
38 |
|
44 |
break; |
39 |
break; |
45 |
|
40 |
|
46 |
case 8: d=0x80; |
41 |
case 8: d=0x80; |
47 |
|
42 |
|
48 |
break; |
43 |
break; |
49 |
|
44 |
|
50 |
default:printf("chyba"); |
45 |
default:printf("chyba"); |
51 |
|
46 |
|
52 |
break; } |
47 |
break; } |
53 |
|
48 |
|
54 |
i2c_start(); |
49 |
i2c_start(); |
55 |
I2C_Write(0xE0); |
50 |
I2C_Write(0xE0); |
56 |
|
51 |
|
57 |
I2C_write(d); |
52 |
I2C_write(d); |
58 |
i2c_stop(); |
53 |
i2c_stop(); |
59 |
|
54 |
|
60 |
} |
55 |
} |
61 |
|
56 |
|
62 |
|
57 |
|
63 |
void main() |
58 |
void main() |
64 |
{ |
59 |
{ |
65 |
|
60 |
|
66 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
61 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
67 |
setup_adc(ADC_CLOCK_DIV_2); |
62 |
setup_adc(ADC_CLOCK_DIV_2); |
68 |
setup_spi(SPI_SS_DISABLED); |
63 |
setup_spi(SPI_SS_DISABLED); |
69 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
64 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
70 |
setup_timer_1(T1_DISABLED); |
65 |
setup_timer_1(T1_DISABLED); |
71 |
setup_timer_2(T2_DISABLED,0,1); |
66 |
setup_timer_2(T2_DISABLED,0,1); |
72 |
setup_ccp1(CCP_OFF); |
67 |
setup_ccp1(CCP_OFF); |
73 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
68 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
74 |
|
69 |
|
75 |
printf("I2CHUB \r\n",); |
70 |
printf("I2CHUB \r\n",); |
76 |
printf("(c)MLAB 2013 JACHO \r\n",); |
71 |
printf("(c)MLAB 2013 JACHO \r\n",); |
77 |
|
72 |
|
78 |
while(TRUE) |
73 |
while(TRUE) |
79 |
{ |
74 |
{ |
80 |
setHUB(3); //pripoji prislusnou branu |
75 |
setHUB(3); //pripoji prislusnou branu |
81 |
delay_ms(1000); |
76 |
delay_ms(1000); |
82 |
} |
77 |
} |
83 |
} |
78 |
} |
84 |
|
79 |
|