37 lines
1.2 KiB
Text
37 lines
1.2 KiB
Text
.define bit_to_recv 32
|
|
.program dht
|
|
; Clock must be set for 1µs per instruction
|
|
|
|
set pindirs, 1 ; set pin as output
|
|
set pins, 1 ; set pin to high
|
|
pull block ; Wait for start
|
|
|
|
set x, 31 ; set x register with 31 (for 31 * 32 µS)
|
|
set pins, 0 ; set pin to low
|
|
loop_init_low: ; wait 992 µs
|
|
jmp x-- loop_init_low [31]
|
|
|
|
set pins, 1 [19] ; set pin to high (for 20µS)
|
|
set pindirs, 0 ; set pin as input
|
|
|
|
wait 0 pin 0 ; Wait for low
|
|
wait 1 pin 0 ; wait for high
|
|
|
|
set y, 4 ; set the number of byte to receive - 1
|
|
init_loop_data:
|
|
set x, 7 ; Set number bit to receive - 1
|
|
loop_data:
|
|
wait 0 pin 0 ; Wait for low
|
|
wait 1 pin 0 ; wait for high
|
|
|
|
nop [29] ; wait for ~ 30 µS
|
|
nop [9] ; wait for ~ 10 µS
|
|
|
|
in pins, 1 ; read the pin state and store bit value
|
|
jmp x--, loop_data ; Loop while there are bits left to read
|
|
|
|
|
|
push iffull noblock ; Push data if full
|
|
jmp y--, init_loop_data
|
|
|
|
push ; Push the last bytes
|