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