IO Ports - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

IO Ports

Description:

Reading Keypad. On Fox11 keypad: columns are wired to port D pins ... We need to have all Port D pins high, a set low one-by-one to scan keypad. Reading Keypad ... – PowerPoint PPT presentation

Number of Views:156
Avg rating:3.0/5.0
Slides: 10
Provided by: ROTH8
Category:
Tags: keypad | porte | ports

less

Transcript and Presenter's Notes

Title: IO Ports


1
I/O Ports
  • Standard HC11 Ports
  • PORTA 0x1000 3 out, 3 in, 2 I/O
  • PORTB 0x1004 8 out
  • Not available on Fox 11
  • PORTC 0x1004 8 I/O
  • Not available on Fox 11
  • PORTD 0x1008 6 I/O (2 used for serial port)
  • PORTE 0x100A 8 in
  • Fox 11 Ports
  • PORTB 0x1404 8 out to LEDs
  • PORTC 0x1403 8 in from DIP switches
  • PORTF 0x1401 8 out for LCD, SW Reset

2
Using I/O Ports
  • Dedicated input and output pins are generally
    ready to use at reset
  • Configurable pins (I/O) are generally set to
    input at reset, and must be configured for output
    by writing (a 1) to the corresponding data
    direction register
  • DDRC 0x1007
  • DDRD 0x1009
  • DDRA7 bit 7 of 0x1026
  • DDRA3 bit 3 of 0x1026
  • Different ports support various other peripherals
    which are configured via various other registers.
  • When port pins are configured for alternate
    functions, corresponding bit in port control
    register generally has no effect.
  • Reference Manual is best resource.

3
Reading Keypad
  • On Fox11 keypad
  • columns are wired to port D pins 25 (output)
  • rows wired to port E pins 0-3 (input)
  • rows have pull-up resistors
  • We need to have all Port D pins high, a set low
    one-by-one to scan keypad.

4
Reading Keypad
  • Sequence
  • Set DDRD bit 2-5 to output mode
  • Do not want to mess with pins we are not using
  • Want to do a read-modify-write
  • LDAA DDRD
  • ORA 0b00111100
  • STAA DDRD
  • or use BSET, but only works direct and indexed
  • Set PORTD25 high
  • Set PRTD2 low
  • Check PORTE03, if any zeros, row and column
    found.
  • If no zeros, set PORTD2 high and PORTD3 low.
  • Check PORTE03,
  • Repeats until all four columns have been pulled
    low

5
ASCII
  • Pronounced ASS-KEY
  • Standard character encoding for terminals and
    communication
  • In GNU assembler char gives ASCII value
  • LDAA 0 ? loads 48, or 0x30 into ACCA

6
Example Convert an 8-bit number to ASCII string
  • General routine
  • num/100 -gt quotient and remainder
  • convert quotient to ASCII
  • remainder/10 -gt quotient and remainder
  • convert quotient to ASCII
  • convert remainder to ASCII

7
  • convert number at some num to ascii and
    display on LCD line 2
  • ldy buffer set iY to buffer to receive ascii
    string
  • clra
  • ldab somenum
  • ldx 100
  • idiv Quotient is in X, remainder in D.
  • Convert Quotient to ASCII
  • xgdx q now in D (b actually since we know it
    is lt3
  • ldaa 0x30
  • aba ASCII value now in A
  • staa 0,y
  • iny
  • xgdx remainder back in D (B)
  • ldx 10
  • idiv
  • xgdx q now in D
  • ldaa 0x30
  • aba
  • staa 0,y

8
BCD ? ASCII
  • A little easier
  • Store number if necessary
  • Shift right 4 times (equivalent to /10)
  • Convert to ASCII (add 0x30)
  • Restore number
  • Mask off upper nibble (and 0x0F)
  • Convert to ASCII
  • Done

9
  • ldy buffer set iY to buffer to receive ascii
    string
  • ldaa somenum
  • do upper nibble first
  • lsra
  • lsra
  • lsra
  • lsra
  • ldab 0x30
  • aba ASCII value now in A
  • staa 0,y
  • iny
  • ldaa somenum
  • anda 0b00001111
  • ldab 0x30
  • aba
  • staa 0,y
  • iny
  • clr 0,y write a null
  • ldx buffer Display the second line
Write a Comment
User Comments (0)
About PowerShow.com