/* S+4Bits comm RX BY M.Kikuchi Tiny13a 1.2MHz 2013/12/6 ROM 190 Bytes conf=1F 6A (BOD=0 Start=14+64 Int9.6M) V2 2014/11/6 11/7 Interrupt */ char RXDAT,Bc; sbit RXPin at PINB4_bit; void cm_rx() // 420 ck+ { while(RXPin); // 1 to 0 Stert bit Delay_us(40); while(~RXPin); // 0 to 1 Delay_us(75); Bc=4; // bit set RXDAT=0; do{ RXDAT <<=1; if(RXPin) RXDAT++; Bc--; Delay_us(50); } while(Bc); PORTB=RXDAT; //Display } void PIN_in() iv IVT_ADDR_PCINT0{ PCIF_bit=0; cm_rx(); } void main() { DDRB=0b00001111; //1=output PORTB=0; PCMSK=0b00010000; //PIN Change mask PCIE_bit=1; SREG_I_bit=1; //Global interrupt while(1); // endless } --------------------------------------------------- /* S+4Bits comm TX BY M.Kikuchi Tiny13a 1.2MHz 2013/12/6 V2-2014/11/6 ROM 196 Bytes conf=1F 6A (BOD=0 Start=14+64 Int9.6M) */ char Bc,LC; sbit TXPIN at PORTB4_bit; void cm_tx(char TXDA) { TXPIN=0; //Start bit Delay_us(50); TXPIN=1; Delay_us(50); Bc=4; do { if((TXDA & 8)==8) TXPIN=1; else TXPIN=0; TXDA <<=1; Bc--; Delay_us(50); } while(Bc); TXPIN=1; } void main() { DDRB =0b00010000; //1=output TXPIN=1; Delay_ms(10); //Wait while(1){ for (LC=0;LC<8;LC++){ cm_tx(LC); Delay_ms(200); } } }