DOC PREVIEW
NMT EE 308 - Input and Output Ports

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2011 • More on programming in assembly language • Introduction to Ports on the HC12 o Input and Output Ports  Simplified input port  Simplified output port  Simplified input/output port  PORTA, PORTB, DDRA, DDRB  A simple program to use PORTA and PORTB o Good programming style o Tips for writing programs o A program to average the numbers in a memory array o Flow charts o Assembly language program o Assembly listing fileEE 308 Spring 2011 Input and Output Ports • How do you get data into a computer from the outside? Any read from address $0000 gets signals from outside LDAA $00 Puts data from outside into accumulator A. Data from outside looks like a memory location. A Tri-State Buffer acts like a switch If TRI is not active, the switch is open: OUT will not be drived by IN Some other device can drive OUTEE 308 Spring 2011 • How do you get data out of computer to the outside? Any write to address $01 latches data into FF, so data goes to external pins MOVB #$AA,$01 Puts $AA on the external pins When a port is configured as output and you read from that port, the data you read is the data which was written to that port: MOVB #$AA, $01 LDAA $01 Accumulator A will have $AA after thisEE 308 Spring 2011 • Most I/O ports on MC9S12 can be configured as either input or output • A write to address 0x0000 writes data to the flip-flop A read from address 0x0000 reads data on pin • If Bit 7 of DDRA is 0, the port is an input port. Data written to FF does not get to pin though tri-state buffer • If Bit 7 of DDRA is 1, the port is an output port. Data written to flip-flop does get to pin though tri-state buffer • DDRA (Data Direction Register A) is located at 0x0002EE 308 Spring 2011EE 308 Spring 2011 Ports on the HC12 • How do you get data out of computer to the outside? • A Port on the HC12 is a device that the HC12 uses to control some hardware. • Many of the HC12 ports are used to communicate with hardware outside of the HC12. • The HC12 ports are accessed by the HC12 by reading and writing memory locations $0000 to $03FF. • Some of the ports we will use in this course are PORTA, PORTB, PTJ and PTP: • PORTA is accessed by reading and writing address $0000. - DDRA is accessed by reading and writing address $0002. • PORTB is accessed by reading and writing address $0001. - DDRB is accessed by reading and writing address $0003. • PTJ is accessed by reading and writing address $0268. - DDRJ is accessed by reading and writing address $026A. • PTP is accessed by reading and writing address $0258. - DDRP is accessed by reading and writing address $025A. • On the DRAGON12-Plus EVB, eight LEDs and four seven-segment LEDs are connected to PTB. -Before you can use the eight individual LEDs or the seven-segment LEDs, you need to enable them. - Bit 1 of PTJ must be low to enable the eight individual LEDs - Bits 3-0 of PTP are used to enable the four seven-segment LEDs * A low PTP0 enables the left-most (Digit 3) seven-segment LED * A low PTP1 enables the second from the left (Digit 2) seven-segment LED * A low PTP2 enables the third from the left (Digit 1) seven-segment LED * A low PTP3 enables the right-most (Digit 0) seven-segment LED – To use the eight individual LEDs and turn off the seven-segment LEDs, write ones to Bits 3-0 of PTP:EE 308 Spring 2011 BSET #$0F,DDRP ; Make PTP3 through PTP0 outputs BSET #$0F,PTP ; Turn off seven-segment LEDs • On the DRAGON12-Plus EVB, the LCD display is connected to PTK • When you power up or reset the HC12, PORTA, PORTB, PTJ and PTP are input ports. • You can make any or all bits of PORTA, PORTB PTP and PTJ outputs by writing a 1 to the corresponding bits of their Data Direction Registers. – You can use DBug-12 to manipulate the IO ports on the 68HCS12 * To make PTB an output, use MM to change the contents of address $0003 (DDRB) to an $FF. * You can now use MM to change contents of address $0001 (PORTB), which changes the logic levels on the PORTB pins. * If the data direction register makes the port an input, you can use MD to display the values on the external pins.EE 308 Spring 2011 Using Port A of the 68HC12 To make a bit of Port A an output port, write a 1 to the corresponding bit of DDRA (address 0x0002). To make a bit of Port A an input port, write a 0 to the corresponding bit of DDRA. On reset, DDRA is set to $00, so Port A is an input port. DDRA7 DDRA6 DDRA5 DDRA4 DDRA3 DDRA2 DDRA1 DDRA0 Reset 0 0 0 0 0 0 0 0 $0002 For example, to make bits 7−4 output and bits 3−0 of Port A input, write a 0xF0 to DDRA. To send data to the output pins, write to PORTA (address 0x0000). When you read from PORTA input pins will return the value of the signals on them (0 ⇒ 0V, 1 ⇒ 5V); output pins will return the value written to them. PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 Reset - - - - - - - - $0000 Port B works the same, except DDRB is at address 0x0003 and PORTB is at address 0x0001. ;A simple program to make PORTA output and PORTB input, then read the ; signals on PORTB and write these values out to PORTA prog: equ $1000 PORTA: equ $00 PORTB: equ $01 DDRA: equ $02 DDRB: equ $03 org prog movb #$ff,DDRA ; Make PORTA output movb #$00,DDRB ; Make PORTB input ldaa PORTB staa PORTA swiEE 308 Spring 2011 • Because DDRA and DDRB are in consecutive address locations, you could make PORTA and output and PORTB and input in one instruction: movw #$ff00,DDRA ; FF -> DDRA, 00 -> DDRBEE 308 Spring 2011 GOOD PROGRAMMING STYLE 1. Make programs easy to read and understand. • Use comments • Do not use tricks 2. Make programs easy to modify • Top-down design • Structured programming – no spaghetti code • Self contained subroutines 3. Keep programs short BUT do not sacrifice items 1 and 2 to do so TIPS FOR WRITING PROGRAMS 1. Think about how data will be stored in memory. • Draw a picture 2. Think about how to process data • Draw a flowchart 3. Start with big picture. Break into smaller parts until reduced to individual instructions • Top-down design 4. Use names instead of numbersEE 308 Spring 2011 Another Example of an Assembly Language Program • Find the


View Full Document

NMT EE 308 - Input and Output Ports

Documents in this Course
Load more
Download Input and Output Ports
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Input and Output Ports and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Input and Output Ports 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?