AtomSoft
Well-Known Member
Hey guys i know not many AVR users here and most are using C perhaps but here is my code. Im not sure whats wrong tho. I know my 2313 is running at 8mhz i checked the fuses.
im i checking the data from a pin ok?
Code:
.include "tn2313def.inc"
.def MyIr = R14
.def Temp = R15
.def devTmp = R16
.def cmdTmp = R17
.def mask = R18
.def d1 = R20
.def d2 = R21
.def d3 = R22
.def sPulse = R23
.org 0x0000
rjmp RESET
RESET:
ldi sPulse, 0x0C ;12 * (200us) = 2.4mS
ldi d1, 0x00
ldi d2, 0x00
ldi d3, 0x00
ldi cmdTmp,0x00
ldi devTmp,0x00
ldi mask,0b11111110
out DDRB,mask ; port B all outputs except PB0
out PORTB,d1 ; disable pullups and set all low
MainLoop:
rcall GetSirc
cpi cmdTmp,0x01
brne notcorr
correct:
sbi PORTB,1
rjmp MainLoop
notcorr:
cbi PORTB,1
rjmp MainLoop
GetSirc:
rcall WaitLow
GetStart:
inc d1
rcall Delay200uS
in MyIR,PINB
sbrs MyIR,0 ;Check if pin hi/lo
rjmp GetStart ;Pin still low add more
cpi d1,0x0B ;The pin is now high
brlo GetSirc ;if the count is less than 11 bad start
cpi d1,0x0E ;if the count is equal to or geater than 14 bad start
brsh GetSirc
ldi d1, 0x00 ;If it made it here the start pulse was ok
ldi d2, 0x07
GetSeven:
dec d2
lsr cmdTmp
repeatS:
rcall WaitLow
inc d1
rcall Delay200uS
in MyIR,PINB
sbrs MyIR,0 ;Check if pin hi/lo
rjmp repeatS ;If pin still low repeat
cpi d1,0x05
brlo DoneOring
ori cmdTmp,$40
DoneOring:
cpi d2, 0x00 ;Check if collected 7 bits
brne GetSeven
ldi d1, 0x00
ldi d2, 0x05
GetFive:
dec d2
lsr devTmp
repeatF:
rcall WaitLow
inc d1
rcall Delay200uS
in MyIR,PINB
sbrs MyIR,0 ;Check if pin hi/lo
rjmp repeatF ;If pin still low repeat
cpi d1,0x05
brlo DoneOring2
ori devTmp,$10
DoneOring2:
cpi d2, 0x00 ;Check if collected 7 bits
brne GetFive
ldi d1, 0x00
ldi d2, 0x00
ret
Delay200uS: ;delay 202us @ 8mhz
ldi d1, $06
L2:
ldi d2, $59
L3:
dec d2
brne L3
dec d1
brne L2
ret
WaitLow:
in MyIR,PINB
sbrc MyIR,0
rjmp WaitLow
ret
im i checking the data from a pin ok?