180 likes | 342 Views
Parallel Ports. Lecture L4.1. Parallel Interfacing. Parallel I/O Ports Using Parallel Ports. Port Integration Module. Reference:. PIM_9C32 Block Guide V01.06. S12C32PIMV1.pdf. Port and Data Direction Registers. PTT ($240) DDRT($242). PTP ($258) DDRP($25A). PTJ ($268) DDRJ($26A).
E N D
Parallel Ports Lecture L4.1
Parallel Interfacing • Parallel I/O Ports • Using Parallel Ports
Port Integration Module Reference: PIM_9C32 Block Guide V01.06 S12C32PIMV1.pdf
PTT ($240) DDRT($242) PTP ($258) DDRP($25A) PTJ ($268) DDRJ($26A) PTS ($248) DDRS($24A) PORTAD ($8F) Input only PTM ($250) DDRM($252) PORTB ($1) DDRB ($3) PORTE ($8) DDRE ($9) PORTA ($0) DDRA ($2)
Parallel Interfacing • Parallel I/O Ports • Using Parallel Ports
; LED example ptp equ $258 ; Port P ddrp equ $25A ; Direction ORG $800 pb_mask db $04 red db $80 yellow db $40 green db $20 red1 db $7F yellow1 db $BF green1 db $DF init ldaa #$E0 ;PP7..PP5 outputs staa ddrp ;PP2 input ldaa #0 staa ptp ;turn off LEDs rts
ORG $4000 main bsr init ;initialize port mn0 ldx #red ;start with red LED mn1 bsr sec_delay ;wait 1 second ldaa ptp oraa 0,x staa ptp ;light next LED inx cpx #$804 bne mn1 ;light red, yellow, green mn2 bsr sec_delay ;wait 1 second ldaa ptp anda 0,x staa ptp ;turn off next LED inx cpx #$807 bne mn2 ;turn off red, yellow, green bra mn0 ;repeat sequence
#include ms_delay.asm init ldaa #$E0 ;PP7..PP5 outputs staa ddrp ;PP2 input ldaa #0 staa ptp ;turn off LEDs rts sec_delay ldy #1000 jsr ms_delay rts
Interfacing a switch input PTJ: equ $268 ; Port J DDRJ: equ $26A ; Direction ldaa PTJ anda #$80 beq sw_down
Debouncing Switch wait_pb_down ldaa ptj anda pb_mask bne wait_pb_down ;wait to push down ldy #3 jsr ms_delay ;debounce delay ldaa ptj anda pb_mask bne wait_pb_down ;wait until still down rts
Debouncing Switch wait_pb_up ldaa ptj anda pb_mask beq wait_pb_up ;wait to release ldy #3 jsr ms_delay ;debounce delay ldaa ptj anda pb_mask beq wait_pb_up ;wait until still up rts
; LED and pushbutton example ptp equ $258 ; Port P ddrp equ $25A ; Direction ptj equ $268 ; Port J ddrj equ $26A ; Direction ORG $800 pb_mask db $80 red db $80 yellow db $40 green db $20 red1 db $7F yellow1 db $BF green1 db $DF ORG $4000 main bsr init ;initialize port
ORG $4000 main bsr init ;initialize port ldx #red ;start with red LED mn1 bsr wait_pb_down ;wait to push button ldaa ptp oraa 0,x staa ptp ;light next LED bsr wait_pb_up ;wait to release button inx cpx #$804 bne mn1 ;light red, yellow, green mn2 bsr wait_pb_down ;wait to push button ldaa ptp anda 0,x staa ptp ;turn off next LED bsr wait_pb_up ;wait to release button inx cpx #$807 bne mn2 ;turn off red, yellow, green bra main ;repeat sequence