+SAMPLE:
+
+ ; sample as long as there is storage capacity and signal
+ cpi state,2
+ brne SAMPLE
+
+ ; disable interrupts
+ rcall INT0_IR_DISABLE
+ rcall TIMER1_INT_DISABLE
+
+ ; signal finish
+ ldi uart_rxtx,0x66
+ rcall UART_TX
+
+IDLE:
+
+ ; wait for commands via uart
+ rcall UART_RX
+
+ ; decode instruction
+ cpi uart_rxtx,0x52
+ breq RESET
+ cpi uart_rxtx,0x54
+ breq TRANSFER
+
+ rjmp IDLE
+
+TRANSFER:
+
+ ; reset storage pointer
+ ldi ZL,low(STORAGE)
+ ldi ZH,high(STORAGE)
+ ldi scount,1
+
+ ; transmit number of sampled words
+ mov uart_rxtx,count
+ rcall UART_TX
+
+TRANSFER_LOOP:
+
+ ; send data and counter
+ ld uart_rxtx,Z+
+ rcall UART_TX
+ ld uart_rxtx,Z+
+ rcall UART_TX
+
+ ; count sent data
+ add scount,one