single master multi slave concept in i2c

37
single master multi slave concept in i2c . . . Real Time Clock (RTC) ( DS1307 )( i2c ).. EEPROM ( 24c0x )(i2c) communication with 8051... with source code .. . #include<reg51.h> sbit scl=P3^0; sbit sda=P3^1; void delay(int i) { int j; while(i--) for(j=0;j<1223;j++); } void start(void) { /*to start make high to low of sda with a clock is high */ sda=1; scl=1; sda=0; //scl=0; } void stop()

Upload: harshith-gowda-r

Post on 16-Jan-2016

34 views

Category:

Documents


0 download

DESCRIPTION

d

TRANSCRIPT

Page 1: Single Master Multi Slave Concept in i2c

single master multi slave concept in i2c . . . Real Time Clock (RTC) ( DS1307 )( i2c ).. EEPROM ( 24c0x )(i2c) communication with 8051... with source code .. .

#include<reg51.h> sbit scl=P3^0; sbit sda=P3^1; void delay(int i) { int j; while(i--) for(j=0;j<1223;j++); } void start(void) { /*to start make high to low of sda with a clock is high */ sda=1; scl=1; sda=0; //scl=0; } void stop()

Page 2: Single Master Multi Slave Concept in i2c

{ /* to stop the i2c make an low to high of sda with scl =1*/ // scl=0; sda=0; scl=1; sda=1; //scl=0; } void write(unsigned char dat) { unsigned char i; for(i=0;i<8;i++) { scl=0; sda=(dat&0x80>>i)?1:0; scl=1; } } void ack(void) { scl=0; sda=1; scl=1; scl=0; } void noack(void) { scl=0; sda=1; scl=1; } unsigned char read() { unsigned char i,buff=0; sda=1; for(i=0;i<8;i++) { scl=1;

Page 3: Single Master Multi Slave Concept in i2c

if(sda) buff|=(0x80>>i); scl=0; } return buff; } void save_i2c(char sa,char addr,char ch) { start(); write(sa); ack(); write(addr); ack(); write(ch); ack(); stop(); delay(10); } char read_i2c(char sa,char addr) { unsigned char buff; start(); write(sa); ack(); write(addr); ack(); start(); write(sa|1); ack(); buff=read(); noack(); stop();

Page 4: Single Master Multi Slave Concept in i2c

return buff; } #define LCD_data P1 sbit rs=P2^0; sbit rw=P2^1; sbit en=P2^2; void cmd_LCD(unsigned char value) { P1=value; rs=0; rw=0; en=1; delay(1); en=0; } void data_LCD(unsigned char value) { P1=value; rs=1; rw=0; en=1; delay(1); en=0; } void init_LCD() { cmd_LCD(0x38); //2 lines and 5*7 matrix cmd_LCD(0x80); //force curser to begin in the first line cmd_LCD(0x01); //clr displayyy cmd_LCD(0x0c); } void main() { int i;char ch; init_LCD(); cmd_LCD(0x80);

Page 5: Single Master Multi Slave Concept in i2c

save_i2c(0xd0,0X00,0X00); save_i2c(0xd0,0X01,0X25); save_i2c(0xd0,0X02,0X09); for(i=0;i<16;i++) { save_i2c(0xa0,i,i+'a'); ch=read_i2c(0xa0,i); data_LCD(ch) ; } while(1) { cmd_LCD(0xc0); ch=read_i2c(0xd0,0X02); data_LCD(ch/16+48); data_LCD(ch%16+48); data_LCD('-'); ch=read_i2c(0xd0,0X01); data_LCD(ch/16+48); data_LCD(ch%16+48); data_LCD('-'); ch=read_i2c(0xd0,0X00); data_LCD(ch/16+48); data_LCD(ch%16+48); } }

DS18b20 (1 WIRE temperature sensor ) Interface using 8051

1- WIRE protocol implementation..... 8051 with ds18b20 1- wire protocol based temperature sensor ...11.0592 crystal..... refer 18b20 data sheet .. see d timing diagrams of 1 wire protocol..... incase of any bugs let me know....

Page 6: Single Master Multi Slave Concept in i2c

# include<reg51.h> sbit dq = P3^5; // connect with DS1820 Data pin sbit rs=P3^0; sbit en=P3^1; void delay_ms(int j) { unsigned char i; for(;j;j--) for(i=122;i<=0;i--); } void data_lcd(unsigned char dat) { P2=dat; rs=1; en=1; delay_ms(200); en=0; } void cmd_lcd(unsigned char cmd) { P2=cmd; rs=0;

Page 7: Single Master Multi Slave Concept in i2c

en=1; delay_ms(200); en=0; } void init_lcd() { cmd_lcd(0x38); cmd_lcd(0x01); cmd_lcd(0x0c); } void str_lcd(unsigned char *p) { while(*p) data_lcd(*p++); } void delayus(int us) { int i; for (i=0; i<us; i++); } bit reset(void) { bit presence; dq = 0; delayus(29); dq = 1; delayus(3); presence = dq; delayus(25); return(presence); } bit readbit(void) { unsigned char i=0; dq = 0; dq=1; for (i=0; i < 3; i++); return(dq); }

Page 8: Single Master Multi Slave Concept in i2c

void writebit(bit Dbit) { unsigned char i=0; dq=0; dq = Dbit?1:0; delayus(5); dq = 1; } unsigned char readbyte(void) { unsigned char i; unsigned char din = 0; for (i=0;i<8;i++) { din|=readbit()? 0x01<<i:din; delayus(6); } return(din); } void writebyte(unsigned char dout) { unsigned char i; for (i=0; i<8; i++) { writebit((bit)(dout & 0x1)); dout = dout >> 1; } delayus(5); } unsigned char * ReadTemp() { unsigned char n; unsigned char buff[2]=0; reset(); writebyte(0xcc); writebyte(0x44); while (readbyte()==0xff); delay_ms(500);

Page 9: Single Master Multi Slave Concept in i2c

reset(); writebyte(0xcc); writebyte(0xbe); for (n=0; n<9; n++) buff[n]=readbyte(); return buff; } void int_lcd(int dat) { int str[5]={0},i=0; if(dat==0) data_lcd('0'); else while(dat>0) { str[i]= (dat%10)+48; dat=dat/10; i++; } i--; for(;i>=0;i--) data_lcd(str[i]); } void main() { unsigned char tp,*temp,t=0x00; init_lcd(); cmd_lcd(0x80); while(1) { temp=ReadTemp(); temp[1]=temp[1]&0x07; tp=temp[0]>>4; temp[1]=temp[1]<<4;

Page 10: Single Master Multi Slave Concept in i2c

tp=tp+temp[1]; cmd_lcd(0x80); str_lcd("temperature is "); cmd_lcd(0xc0); int_lcd(tp); data_lcd(223); } }

NOKIA 1100 LCD INTERFACING WITH 8051

8051 UART (BIT BANGING)

Page 11: Single Master Multi Slave Concept in i2c

11.0592 crystal # include<reg51.h> # include<intrins.h> # define uart_ch1 0 # define uart_ch2 2 sbit tx = P2^0; sbit rx = P2^1; void delay() { int i; for(i=6;i;i--); _nop_(); _nop_(); } void delay_ms(int i) { int j; for(; i ;i--) for(j=122;j;j--); } void tx_data(char data_ , char val) {

Page 12: Single Master Multi Slave Concept in i2c

char i; P2 |= 0x03; tx = 0; // send start bit P2 &= ~(1<<val); delay(); for(i = 0;i < 8 ; i++) { if(((data_>>i)&(0x01)) == 0x01) { P2 |=(1 << val); } else { P2 &= ~(1<<val); } delay(); } P2 |= (1 << val); delay(); // delay_ms(1); } void init_uart() { tx = 1; } void str(char *ch , char uart0_tx) { while(*ch) { tx_data(*ch++ , uart0_tx); } } void init() { SCON=0x50; TMOD=0x20; TH1=TL1=253; TR1=1; }

Page 13: Single Master Multi Slave Concept in i2c

void tx1(char ch) { SBUF = ch; while(!TI); TI=0; } void str1(char *ch) { while(*ch) { tx1(*ch++); } } void main() { init_uart(); init(); while(1) { str(".........P2^0 IO PIN UART....\n\r", uart_ch1); str(".........P2^1 IO PIN UART.....\n\r", uart_ch2); str1(".........INBUILT UART ....\n\r"); } }

led display using 8051 (serial communication)

Page 14: Single Master Multi Slave Concept in i2c

# include<reg51.h> code char luk[182]= { 'A',0X81,0XEE,0XEE,0XEE,0X81,0XFF,//A 'B',0X80,0XB6,0XB6,0XB6,0XC9,0xFF,//B 'C',0XC1,0XBE,0XBE,0XBE,0XDD,0XFF,//C 'D',0X80,0XBE,0xBE,0XBE,0XC1,0XFF,//D 'E',0X80,0XB6,0XB6,0XB6,0XB6,0XFF,//E 'F',0X80,0XF6,0XF6,0XF6,0XFE,0XFF,//F 'G',0XC1,0XBE,0XB6,0XB6,0XC5,0XFF,//G 'H',0X80,0XF7,0XF7,0XF7,0X80,0XFF,//H 'I',0XBE,0XBE,0X80,0XBE,0XBE,0XFF,//I 'J',0XDD,0XBE,0X80,0XFE,0XFE,0XFF,//J 'K',0X80,0XF7,0XED,0XDD,0XBE,0XFF,//K 'L',0X80,0XBF,0XBF,0XBF,0XBF,0XFF,//L 'M',0X80,0XFD,0XF3,0XFD,0X80,0XFF,//M 'N',0X80,0XFD,0XE3,0XDF,0X80,0XFF,//N 'O',0XC1,0XBE,0XBE,0XBE,0XC1,0XFF,//O 'P',0X80,0XF6,0XF6,0XF6,0XF9,0XFF,//P 'Q',0XE1,0XDE,0XCE,0XDE,0XA1,0XFF,//Q 'R',0X80,0XF6,0XE6,0XD6,0XB9,0XFF,//R 'S',0XB9,0XB6,0XB6,0XB6,0XCE,0XFF,//S

Page 15: Single Master Multi Slave Concept in i2c

'T',0XFE,0XFE,0X80,0XFE,0XFE,0XFF,//T 'U',0XC0,0XBF,0XBF,0XBF,0XC0,0XFF,//U 'V',0XE0,0XDF,0XBF,0XDF,0XE0,0XFF,//V 'W',0X80,0XDF,0XEF,0XDF,0X80,0XFF,//W 'X',0X9C,0XEB,0XFF,0XEB,0X9C,0XFF,//X 'Y',0XFC,0XFB,0X87,0XFB,0XFC,0XFF,//Y 'Z',0X9E,0XAE,0XBE,0XB9,0XBC,0XFF,//Z }; void delay(int i) { int j; for(;i;i--) for(j=60;j;j--); } void tx(unsigned char tx) { SBUF=tx; while(TI == 0); TI=0; } unsigned char receive() { unsigned char rx; while(RI == 0); rx=SBUF; RI=0; RI=0; return rx; } void main() { int i,j=0,k=0,l; char str_led[90]; char str[20]; unsigned char rx;

Page 16: Single Master Multi Slave Concept in i2c

SCON=0X50; /*mode1*/ TMOD=0X20; /*auto reload*/ TH1=0XFD; /*9600 baud rate*/ TR1=1; for(i=0;i<90;i++) str_led[i]=0xff; delay(250); do{ rx=receive(); tx(rx); }while(rx != '*'); for(l=0;l<10;l++) { str[l]=receive(); tx(str[l]); if(str[l]=='*') break; } for(l=0;l<32;l++) str_led[l]=0xff; for(i=0;i<20;i++) { if(str[i]==' ') str_led[l++]=0xff; for(j=0;j<182;j++) { if(str[i]==luk[j]) { for(k=1;k<=6;k++) { str_led[l++]=luk[j+k]; } break; }

Page 17: Single Master Multi Slave Concept in i2c

} } for(j=0;j<32;j++) str_led[l++]=0xff; while(1) { for(j=0;j<l-32;j++) for(k=0;k<5;k++) for(i=0;i<32;i++) { if(i<16) { P1=i; P1=P1|0x20; } else//(i>=16) { P1=i; P1=P1|0x10; } P2=str_led[i+j]; delay(1); } } }

Page 18: Single Master Multi Slave Concept in i2c

ORG 00H START: MOV R0,#0 MOV DPTR,#LOOKUP;LOOKUP TABLE LOCATION FOR: MOV A,R0 ;A = R0 = 0 MOVC A,@A+DPTR ;BRINGING LOOKUP TABLE VALUES TO A MOV P1,A ;P1 = A LCALL DELAY ;DELAY INC R0 ;R0++ CJNE R0,#10,FOR ;COMPARE AND JUMP IF NOT EQUAL ;ROTATE 10 TIMES SJMP START /************** DELAY LOOP ***********/ DELAY: MOV R5,#4 LOOP2: MOV R6,#222 LOOP1: MOV R7,#222 DJNZ R7,$

Page 19: Single Master Multi Slave Concept in i2c

DJNZ R6,LOOP1 DJNZ R5,LOOP2 RET /************ END OF DELAY LOOP *********/ /***** LOOKUP TABLE *****/ LOOKUP: DB 3FH,06H,5BH,4FH,66H DB 6DH,7DH,07H,7FH,6FH DB 01H END

Multiplexing Of 7-Segment Display using 8051 Microcontroller

/**** 7-SEGMENT DISPLAY *****/ SEG1 BIT P3.0 SEG2 BIT P3.1 SWTCH BIT P3.7 ORG 00H

/******* MAIN ******************/ START: MOV A,#0 MOV R0,#0 MOV R1,#1 JB SWTCH,LABLE1 ;IF SWITCH PRESS LOOKUP TABLE1 MOV DPTR,#TABLE2;ELSE LOOKUP TABALE2 SJMP MAIN LABLE1: MOV DPTR,#TABLE1 ;IF SWITCH PRESS LOOKUP TABLE1 MAIN: MOV R3,#200 ; FOR CLEAR VISULATION VISUAL: /*********** SEGMENT1 ************/

Page 20: Single Master Multi Slave Concept in i2c

MOV A,R0 ;A = R0 MOVC A,@A+DPTR ;BRINGING LOOKUP TABLE VALUE TO A MOV P2,A ;SENDING TO PORT2 CLR SEG1 ;ENABLING SEGMENT 1 ACALL DELAY ;DELAY SETB SEG1 ;OFF FIRST DISPLY /*********** SEGMENT2 ************/ MOV A,R1 MOVC A,@A+DPTR MOV P2,A CLR SEG2 ACALL DELAY SETB SEG2 JNB SWTCH,START ;IN CASE IF SWITCH IT JUMPS TOO ;TABLE2 DJNZ R3,VISUAL INC R0 INC R1 CJNE R0,#12,MAIN LJMP START /********** DELAY LOOP ***********/ DELAY: MOV R7,#2 BACK: MOV R6,#254 DJNZ R6,$ DJNZ R7,BACK RET /********** DELAY LOOP ***********/ /************** LOOK UP TABLE ************/ TABLE1: DB 00H,00H,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H TABLE2: DB 00H,00H,76H,79H,38H,38H,3FH,3FH,00H END

Page 21: Single Master Multi Slave Concept in i2c

serial to parallel converter(74ls164) application using 8051

/***serial to parallel converter 75LS164 **/ # include<reg51.h>

Page 22: Single Master Multi Slave Concept in i2c

sbit clk = P2^0; sbit din = P2^1; code char seg[]={ 0x3F,0x06,0x5B,0x4F,0x66, 0x6D,0x7D,0x07,0x7F,0x6F, 0x00,0x00,0x00,0x00, 0x76,0x79,0x38,0x38,0x3F,0x3F, 0x00,0x00}; void delay(int j) { int i; for(;j;j--) for(i=122;i;i--); } void main() { char j,i,dat; while(1) { for(i=0;i<21;i++) { dat = seg[i]; for(j=0;j<8;j++) { din = (dat&(0x80>>j))?1:0; clk = 0; clk = 1; } delay(500); } } }

LED Display Interfacing With 8051 Microcntroller

Page 23: Single Master Multi Slave Concept in i2c

Under standing of LED DISPLAY If u want in embedded c comment .... we will help u to convert /**** BASIC LED DISPLY ****/ ORG 00H START: MOV A,#0 CALL FUNCTION MOV A,#1 CALL FUNCTION MOV A,#2 CALL FUNCTION MOV A,#3 CALL FUNCTION SJMP START FUNCTION: ADD A,ACC MOV DPTR,#FUNCTIONTAB JMP @A+DPTR FUNCTIONTAB: AJMP LOOP1 AJMP LOOP2 AJMP LOOP3 AJMP LOOP4 /*************** left to right *****************/ LOOP1:

Page 24: Single Master Multi Slave Concept in i2c

MOV R0,#8 MOV A,#01H DISP_1: MOV P3,A MOV P2,#00H RL A LCALL DELAY DJNZ R0,DISP_1 RET /*************** right to left *****************/ LOOP2: MOV R0,#8 MOV A,#80H DISP_2: MOV P3,A MOV P2,#00H RR A LCALL DELAY DJNZ R0,DISP_2 RET /*************** up to down *****************/ LOOP3: MOV R0,#8 MOV A,#0FEH DISP_3: MOV P2,A MOV P3,#0FFH RL A LCALL DELAY DJNZ R0,DISP_3 RET /*************** down to up *****************/ LOOP4: MOV R0,#8 MOV A,#07FH DISP_4: MOV P2,A MOV P3,#0FFH RR A LCALL DELAY DJNZ R0,DISP_4

Page 25: Single Master Multi Slave Concept in i2c

RET /*************** delay *****************/ DELAY: MOV R5,#2 FOR2: MOV R7,#254 FOR1: MOV R6,#254 DJNZ R6,$ DJNZ R7,FOR1 DJNZ R5,FOR2 RET /***************end of delay *************/ END

MCP3204 Interfacing With 8051 Microcontroller

# include<reg51.h> # include<stdio.h> sbit cs=P2^7; sbit miso=P2^6; sbit mosi=P2^5; sbit clk=P2^4;

Page 26: Single Master Multi Slave Concept in i2c

float readadc(bit d1,bit d0) { unsigned int adc_val=0; float temp; char i; cs=1; clk=mosi=1; cs=0; clk=0;clk=1; clk=0;mosi=1;clk=1; clk=0;mosi=1;clk=1; clk=0;mosi=d1;clk=1; clk=0;mosi=d0;clk=1; clk=0;clk=1; clk=0;clk=1; for(i=11;i>=0;i--) { clk=0; if(miso) adc_val|=(1<<i); clk=1; } cs=1; temp=((adc_val*5.0)/4095); return temp; } void init_uart() { SCON=0X50; TMOD=0X20; TH1=TL1=253; TR1=1; TI=1; }

Page 27: Single Master Multi Slave Concept in i2c

int main() { int i=0; init_uart(); while(1) { printf("mcp3004.........................................\n\n"); printf("chnl1 :: %f\n",readadc(0,0)); printf("chnl2 :: %f\n",readadc(0,1)); printf("chnl3 :: %f\n",readadc(1,0)); printf("chnl4 :: %f\n",readadc(1,1)); printf("................................................\n\n"); for(i=0;i<30000;i++); for(i=0;i<30000;i++); for(i=0;i<30000;i++); } return 0; }

7-Segment Interfacing With 8051,, Incrementing And Decrementing

8051 7-segment multiplexing with increment and decrement buttons...... #include<reg51.h>

Page 28: Single Master Multi Slave Concept in i2c

sbit sel1 = P3^2; sbit sel2 = P3^3; sbit sw1 = P3^6; sbit sw2 = P3^7; unsigned char luk[]= { 0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90 }; void delay(int i) { unsigned int j; for(;i;i--) for(j=12;j;j--); } void display(int i) { P2 = luk[i/10]; sel1 = 1; delay(1); sel1 = 0; P2 = luk[i%10]; sel2 = 1; delay(1); sel2 = 0; } void main() { int i=0; while(1) { display(i); if(sw1 == 0) { i++; while(sw1==0) display(i); } if(sw2 == 0)

Page 29: Single Master Multi Slave Concept in i2c

{ i--; while(sw2==0) display(i); } } }

keypad and lcd interfacing with 8051 ,,, lock application

#include<reg51.h> #include<string.h> sbit en=P3^1; sbit rs=P3^0; sbit red=P3^6; sbit grn=P3^7; void delay(unsigned int i) { int j; for(;i;i--) for(j=122;j;j--); } void data_lcd(unsigned char dat) {

Page 30: Single Master Multi Slave Concept in i2c

P2=dat; rs=1; en=1; delay(100); en=0; } void str(unsigned char *ptr) { while(*ptr) data_lcd(*ptr++); } void cmd_lcd(unsigned char cmd) { P2=cmd; rs=0; en=1; delay(100); en=0; } void init() { cmd_lcd(0x38); cmd_lcd(0x01); cmd_lcd(0x0e); cmd_lcd(0x0c); cmd_lcd(0x80); } sbit r0=P1^0; sbit r1=P1^1; sbit r2=P1^2; sbit r3=P1^3; sbit c0=P1^4; sbit c1=P1^5; sbit c2=P1^6; code char lut[4][3]={ '1','2','3', '4','5','6', '7','8','9', '*','0','#' }; bit colscan() {

Page 31: Single Master Multi Slave Concept in i2c

return (c0&c1&c2); } unsigned char row,col; char key() { c0=c1=c2=1; r0=r1=r2=r3=0; while(colscan()); r0=0;r1=1;r2=1;r3=1; if(!colscan()) { row=0; goto colcheck; } r0=1;r1=0;r2=1;r3=1; if(!colscan()) { row=1; goto colcheck; } r0=1;r1=1;r2=0;r3=1 ; if(!colscan()) { row=2; goto colcheck; } r0=1;r1=1;r2=1;r3=0 ; if(!colscan()) { row=3; goto colcheck; } colcheck: if(c0==0) col=0; else if(c1==0) col=1; else if(c2==0) col=2; while(!colscan()); return lut[row][col]; } void main() { char ch,a[5],i;

Page 32: Single Master Multi Slave Concept in i2c

init(); cmd_lcd(0x80); str("press any key:"); ch=key(); data_lcd(ch); cmd_lcd(0x80); str("keypad working "); delay(1000); cmd_lcd(0x80); str("enter password "); cmd_lcd(0xc0); while(1) { red = grn =0; cmd_lcd(0x80); str("enter password "); cmd_lcd(0xc0); for(i=0;i<4;i++) { a[i]=key(); data_lcd(a[i]); } a[i] = '\0'; if(!(strcmp(a,"1234"))) { grn =1; cmd_lcd(0x01); str("correct password "); } else { red = 1; cmd_lcd(0x01); str("wrong password "); } delay(1000); } }

Page 33: Single Master Multi Slave Concept in i2c

8051 serial communication (UART) programing , ,graphical user interface using visual basic 2010

#include<reg51.h> void init() { SCON=0x50; TMOD=0x20; TH1=TL1=253; TR1=1; } void tx(char ch) { SBUF=ch; while(!TI); TI=0; } rx() { while(!RI); RI=0; return SBUF;

Page 34: Single Master Multi Slave Concept in i2c

} #define lcd_data P1 sbit rs=P3^6; sbit en=P3^7; void delay(unsigned int time) { int i; for(;time>0;time--) for(i=0;i<127;i++); } void cmd_lcd(unsigned char value) { lcd_data=value; rs=0; en=1; delay(10); en=0; } void data_lcd(unsigned char value) { lcd_data=value; rs=1; en=1; delay(10); en=0; } void init_lcd() { cmd_lcd(0x38); //2 lines and 5*7 matrix cmd_lcd(0x01); //clr displayyy cmd_lcd(0x0c); cmd_lcd(0x80); //force curser to begin in the first line } void str_lcd(unsigned char *str) { while(*str) { data_lcd(*str++); }

Page 35: Single Master Multi Slave Concept in i2c

} void main() { char ch=0; init(); init_lcd(); data_lcd('a'); while(1) { ch =rx(); // data_lcd(ch); cmd_lcd(0x80); if(ch == '1') { str_lcd("led 1 on"); P2 = 0X01; } else if(ch == '2') { str_lcd("led 2 on"); P2 = 0X02; } else if(ch == '3') { str_lcd("led 3 on"); P2 = 0X04; } else if(ch == '4') { str_lcd("led 4 on"); P2 = 0X08; } } }

Max7221 Interfacing With 8051 Microcntroller

Page 36: Single Master Multi Slave Concept in i2c

#include<reg51.h> sbit ss = P1^0; sbit din = P1^1; sbit scl = P1^2; void delay(int i) { int j; for(;i;i--) for(j=122;j;j--); } void spi(char cmd,char dat) { int i; ss = 1; ss = 0; for(i=0;i<8;i++) { scl=0; din=(cmd&0x80>>i)?1:0; scl=1; }

Page 37: Single Master Multi Slave Concept in i2c

for(i=0;i<8;i++) { scl=0; din=(dat&0x80>>i)?1:0; scl=1; } ss =1; } int main() { spi(0x0a,0x0f); spi(0x09,0xff); spi(0x0b,0x07); spi(0x0c,0x01); spi(0x01,0x08); delay(1000); spi(0x02,0x07); delay(1000); spi(0x03,0x06); delay(1000); spi(0x04,0x05); delay(1000); spi(0x05,0x04); delay(1000); spi(0x06,0x03); delay(1000); spi(0x07,0x02); delay(1000); spi(0x08,0x01); while(1); }