/* S+4Bits comm RX BY M.Kikuchi Tiny13a 1.2MHz 2013/12/6 ROM 204 Bytes conf=1F 6a (BOD=0 Start=14+64 Int9.6M) V2 2014/11/6 11/8 Interrupt 11/9 Tuning 6bit-4bit */ char RXDAT,Bc; sbit RXPin at PINB4_bit; void cm_rx() { while(RXPin); // 3.3 1 to 0 Stert bit Delay_us(35); // while(~RXPin); // 3.3 0 to 1 Delay_us(65); // 75-10 Bc=6; // 2.5 bit counter RXDAT=0; // 2.5 do{ RXDAT <<=1; // 4.17 if(RXPin) // 2.5(1) - 3.33(0) RXDAT++; // 5.83 - else Delay_us(5); // 5.0 Bc--; // 4.17 Delay_us(29); // } while(Bc); // 4.17 PORTB=(RXDAT & 15); // 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 204 Bytes conf=1F 6A (BOD=0 Start=14+64 Int9.6M) 6bit */ char Bc,LC; sbit TXPIN at PORTB4_bit; void cm_tx(char TXDA) { TXPIN=0; // 2.5uS Start bit Delay_us(48); TXPIN=1; Delay_us(48); Bc=6; do { if((TXDA & 32)==32) // 4.17 TXPIN=1; // else TXPIN=0; // 2.5 TXDA <<=1; // 2.5 Bc--; // 4.17 Delay_us(33); // 50-17 } while(Bc); // 4.17 TXPIN=1; } void main() { DDRB =0b00010000; //1=output TXPIN=1; Delay_ms(1); //Wait while(1){ for (LC=1;LC<9;LC++){ // 1 to 8 cm_tx(LC); // Delay_ms(330); } } }