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