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