/* uart_soft copyright John Steggall 2009 */ /* Copyright 2009 John Steggall (steggall.j@gmail.com) Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. */ #include /* BITLENGTH is the time for a bit cycle worked out at F_CPU / BAUD. Gives a rough but usable figure. Wouldn't like to try * anything faster than 9600! */ #define BITLENGTH 833 #define SFT_TX_EN 7 #define SF_UART_TX 1 #define SF_UART_RX 2 .section .data rxdata: .byte 0 txShifter: .byte 0 txBitcount: .byte 0 rxShifter: .byte 0 rxBitcount: .byte 0 status: .byte 0 .section .text /********************************************* * External interrupt * * RX pin has gone low. */ .global INT0_vect INT0_vect: push r16 lds r16,SREG push r16 lds r16,PIND sbrc r16,0 // anti glitch rjmp ignore nop nop nop nop lds r16,PIND sbrc r16,0 // just make sure rjmp ignore push r17 // grab timer value lds r16,TCNT3L lds r17,TCNT3H // set trigger for RX timer (will need to add a little more though) sts OCR3CH,r17 sts OCR3CL,r16 pop r17 // set bitcount to 0 ldi r16,0 sts rxBitcount,r16 // turn off interrupt, will get annoying. cbi 0x1D,0 // turn on interrupt on compare match sbi 0x18,OCF3C lds r16,TIMSK3 ori r16,(1<