Falls es jemanden interessiert, was Bascom bei "PULSEIN" produziert:
Hat ja drei Loops:
1 Warten auf Pinx != state (count 0-65535)
2 Warten auf Pinx == state (count 0-65535)
3 Warten auf Pinx != state (count 0-65535 mit 10µS Loop)
Um die timeoutwerte zu ändern, müßt man den Code-ändern
Code:
// DIM result as WORD
// Pulsein Result , Pind , 2 , 1
LDI ZL,0x30 // PIND
LDI r24,0x02 // PinNr
LDI r16,0xFF // State
CALL PULSEIN
LDI XL,0x60 // addr "result"
LDI XH,0x00
ST X+,r24 // store result
ST X,r25
...............................................
PULSEIN:
CALL Clear_ErrBit
CLR ZH
CLR XL // clear Timout Lo
CLR XH // clear Timout Hi
CALL MakeMask // R24 Mask, R25 neg Mask
AND r16,r24
LDD r0,Z + 1 // DDRD
AND r0,r25 // Make Pin (2) Input
STD Z + 1,r0 // DDRD
L_0x00D8: // ------------- Loop 1
LDD r0,Z + 0 // PIND
AND r0,r24 // PIND & Mask
EOR r0,r16 // (PIND & Mask) ^ State
BRNE L_0x00E6 // Ok PIN != State
ADIW XL,0x0001 // Timeout counter++
BREQ L_0x0118 // elapsed->ERR-Exit
RJMP L_0x00D8 // cont'd Loop
L_0x00E6:
CLR XL // clear Timout Lo
CLR XH // clear Timout Hi
L_0x00EA: // ------------- Loop 2
LDD r0,Z + 0 // PIND
AND r0,r24 // PIND & Mask
EOR r0,r16 // (PIND & Mask) ^ State
BREQ L_0x00F8 // Ok PIN == State
ADIW XL,0x0001 // Timeout counter++
BREQ L_0x0118 // elapsed->ERR-Exit
RJMP L_0x00EA // cont'd Loop
L_0x00F8:
CLR XL // clear Timout Lo
CLR XH // clear Timout Hi
L_0x00FC: ------------ 10 µS Loop 3
PUSH ZL // Save
PUSH ZH
LDI ZL,0x20 // calc from $XTAL
LDI ZH,0x00
CALL L_0x009C // 10 µS Idle
POP ZH // Restore
POP ZL
LDD r0,Z + 0 // PIND
AND r0,r24 // PIND & Mask
EOR r0,r16 // (PIND & Mask) ^ State
BRNE L_0x011C // OK, Pulsein done *********
ADIW XL,0x0001 // PulseCounter++
BRNE L_0x00FC // cont'd Loop
L_0x0118:
CALL Set_ErrBit
L_0x011C:
MOV r24,XL // result --> R24:r25
MOV r25,XH
RET // that's it
// idle Loop
L_0x009C:
SBIW ZL,0x0001
BRNE L_0x009C
RET
Set_ErrBit:
SET
BLD r6,2
RET
Clear_ErrBit:
CLT
BLD r6,2
RET
MakeMask:
LDI r25,0x01
AND r24,r24
BREQ L_0x00BC
CLC
L_0x00B6:
ROL r25
DEC r24
BRNE L_0x00B6
L_0x00BC:
MOV r24,r25
COM r25
RET
Lesezeichen