DOC PREVIEW
NMT EE 308 - Input and Output Ports

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 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 10 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 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

• Another simple program in assembly language • Using the stack and the stack pointer • Huang Section 4.3 o A program to add all the odd numbers in a memory array o Flow charts o Assembly language program o Assembly listing file o Assembly map file o The Stack and the Stack Pointer o The stack is an area of memory used for temporary storage o The stack pointer points to the last byte pushed onto the stack o Some instructions which use the stack, and how data is pushed onto and pulled off of the stack. 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 $00Puts data from outside into accumulator A.Data from outside looks like a memory location.A Tri-State Buffer acts like a switchIf TRI is not active, the switch is open: OUT will not be drived by INSome other device can drive OUT• 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 pints MOVB #$AA,$01Puts $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 $01Accumulator A will have $AA after thisPorts on the HC12• How do you get data out of computer to the outside?• A Port on the HC12 is device 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 and PTH• PORTA is accessed by reading and writing address $0000.• PORTB is accessed by reading and writing address $0001.• PTH is accessed by reading and writing address $0260.• You can connect signals from the outside by connecting wires to pins 39 to 46 (PORTA), 18 to 25 (PORTB), and to pins 32 to 35 and 49 to 52 (PTH).– On the MiniDRAGON+ EVB, a seven-segment LED is connected to PTH.• When you power up or reset the HC12, PORTA, PORTB and PTH are input ports.• You can make any or all bits of PORTA, PORTB and PTH outputs by writing a 1 to the corresponding bits of their Data Direction Registers.– The Data Direction Register for PORTA is located at memory addres $0002. It is called DDRA. To make all bits of PORTA output, write a $FF to DDRA. To make the lower four bits of PORTA output and the upper four bits of PORTA input, write a $0F to DDRA.– The Data Dirction Register for PORTB is located at memory addres $0003. It is called DDRB. To make all bits of PORTB output, write a $FF to DDRB.– The Data Dirction Register for PTH is located at memory addres $0262. It is called DDRH. To make all bits of PTH output, write a $FF to DDRH.– You can use DBug-12 to easily manipulate the IO ports on the 68HCS12_ To make PTH an output, use MM to change the contents of address $0262 (DDRH) to an $FF._ You can now use MM to change contents of address $0260 (PTH), which changes the logic levels on the PTH pins._ If the data direction register makes the port an input, you can use MD to display the values on the external pins.Using Port A of the 68HC12To 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.DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0Reset 0 0 0 0 0 0 0 0 $0002For example, to make bits 3−0 of Port A input, and bits 7−4 output, 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 PA0Reset - - - - - - - - $0000Port 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 PORTAprog: equ $1000PORTA: equ $00PORTB: equ $01DDRA: equ $02DDRB: equ $03org progmovb #$ff,DDRA ; Make PORTA outputmovb #$00,DDRB ; Make PORTB inputldaa PORTBstaa PORTAswi• 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 -> DDRBGOOD PROGRAMMING STYLE1. Make programs easy to read and understand.• Use comments• Do not use tricks2. Make programs easy to modify• Top-down design• Structured programming – no spaghetti code• Self contained subroutines3. Keep programs short BUT do not sacrifice items 1 and 2 to do soTIPS FOR WRITING PROGRAMS1. Think about how data will be stored in memory.• Draw a picture2. Think about how to process data• Draw a flowchart3. Start with big picture. Break into smaller parts until reduced to individualinstructions• Top-down design4. Use names instead of numbersAnother Example of an Assembly Language Program• Add the odd numbers in an array of data.• The numbers are 8-bit unsigned numbers.• The address of the first number is $E000 and the address of the final number is $E01F.• Save the result in a variable called answer at address $2000.Start by drawing a picture of the data structure in memory:SUM ODD NUMBERS IN ARRAY FROM 0xE000 TO 0xE01fTreat numbers as 8−bit unsigned numbers4 0xE0005186110xE01FStart with the big picture4 0xE0005186110xE01FAdd details to blocks4 0xE0005186110xE01FDecide on how to use CPU registers for processing dataPointer: X or Y −− use XSum: 16−bit registerD or YNo way to add 8−bit number to DCan use ABY to add 8−bit number to YAdd more details: Expand another blockX -> 4 0xE0005186110xE01FMore details: How to tell if number is odd, how to tell when doneHow to test if even?LSB = 0 − check LSB of memoryBRCLR 0,X,$01,evenHow to check if more to do?If X < 0xE020, more to do.CMPX #$E020BL0 or BLT loop?Address in unsigned, use unsigned compareBLO loopConvert blocks to assembly codeX -> 4 0xE0005186110xE01FHow to test if even?LSB = 0 − check LSB of memoryBRCLR 0,X,$01,evenHow to check if more to do?If X < 0xE020, more to do.BLO loopWrite program;Program to sum odd numbers in a memory arrayprog: equ $1000data: equ $2000array: equ $E000len: equ $20org


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?