#define SEND_TIME 43 ;determines cycles per bit for sending #define RECEIVE_TIME 16 ;determines cycles per bit for receiving .nolist #include "ti83plus.inc" .list .org $9D93 .db t2ByteTok, tAsmCmp status .db 0 ;*****PROGRAM EXECUTION STARTS HERE start: DI ;turn interrupts off (or else operating system will break timing) call turn_on ;serial line default state is high ;*****INSERT YOUR CODE HERE ;************************************************************** ;* get_byte-waits for serial byte to be received ;* stores to register C ;* destroys a, b, c ;************************************************************** get_byte: ld c, 0 ;for the data ld b, 8 ;counter get_byte0: in a, (0) ;loop until data start detected bit 0, a ;check red wire jr NZ, get_byte0 ;stay in loop if red wire high call uart_delay ;(time-1)*14+39 cycles get_byte1 call uart_delay ;(time-1)*14+39 cycles call uart_delay ;(time-1)*14+39 cycles in a, (0) ;store a bit from linkport bit 0, a ;check if 1 or 0 jr NZ, get_byte3 ;branch if bit is 1 get_byte2: scf ;clear carry flag ccf ;flip the carry flag ld a, 0 ;just wasting clock cycles ld a, 0 ;i used ld because it uses an odd number of clock cycles ld a, 0 ; jr get_byte4 ;skip over the 1 condition get_byte3: scf ;set carry flag nop ;-the important thing is that nop ;-get_byte2 and get_byte3 nop ;-take the EXACT same number of nop ;-clock cycles, which is a difficulty nop ;-because asm instructions on the nop ;-calc take up differing number of nop ;-clock cycles. I.E. I've got them nop ;-exactly balanced, so DO NOT MESS get_byte4: rr c ;move data bit into storage djnz get_byte1 ;we need to do it for all 8 bits ret ;************************************************************** ;* send_byte-sends a byte over serial ;* input byte is in register C ;* destroys a, b, c ;************************************************************** send_byte: ld a, c ;flip the byte's bits (because lows mean 1 on serial line) xor 255 ld c, a ld b, 9 ;counter scf ;start bit send_byte0: jr NC, send_byte1 ;is it a one or a 0? nop ;waste time call turn_off ;bring line low (send a 1) cp 0 ;waste cycles cp 0 cp 0 jr send_byte2 ;skip the send 0 routine send_byte1: call turn_on ;bring line high (send a 0) nop ;waste time nop nop nop nop nop nop nop send_byte2: ld a, SEND_TIME ;delay time send_byte3: ;(time-1)*14+5 dec a jr NZ, send_byte3 sra c ;get the next bit into carry djnz send_byte0 ;we need to send all bits nop ;waste time nop nop nop call turn_on ;bring line to default state (stop bit) ld b, 255 ;make sure we don't send new data too soon call delay ret ;************************************************************** ;* uart_delay-One half bit delay ;* destroys a ;************************************************************** uart_delay: ;(time-1)*14+39 clock cycles ld a, RECEIVE_TIME uart_delay0: dec a jr NZ, uart_delay0 ret ;************************************************************** ;* delay-A short delay ;************************************************************** delay: djnz delay ;13 or 8 ret ;10 ;************************************************************** ;* turn_on-sets white wire high ;* destroys a ;************************************************************** turn_on: ld a, 0D0h ;ld set white wire high out (0), a ret ;************************************************************** ;* turn_off-sets white wire low ;* destroys a ;************************************************************** turn_off: ld a, 0D2h ;set white wire low out (0), a ret .end .end