Created
April 5, 2011 00:57
-
-
Save dublindan/902810 to your computer and use it in GitHub Desktop.
reading digital input pins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "p24Hxxxx.inc" | |
.text | |
.global __reset | |
__reset: | |
; Turn of analog to digital converter for all pins | |
mov #0xffff, W0 | |
mov W0, AD1PCFGL | |
; Set RA0 through RA3 as inputs (1), the rest as outputs (0) (easy way to remember: 1 looks like I for In, 0 looks like O for Out) | |
mov #0xf, W0 | |
mov W0, TRISA | |
; Set all PORTB pins as outputs | |
mov #0x0, W0 | |
mov W0, TRISB | |
; Continuously read PORTA and use the 4bit value from RA0 through RA3 to determine which PORTB pin to set | |
loop: | |
; Read input pins | |
mov PORTA, W0 | |
; Mask out the output bits | |
mov #0xf, W1 | |
and W0, W1, W0 | |
; Convert the pin number to a bit pattern with all pins 0 except the pin at PORTB[W0] | |
mov #0x1, W1 | |
sl W1, W0, W0 | |
; Set the output pin | |
mov W0, PORTB | |
; And jump back to the start | |
bra loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bset LATA, 0 | |
bset LATA, 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bset PORTA, 0 | |
bset PORTA, 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment