DOC PREVIEW
NMT EE 308 - EE 308 Lecture 12

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

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

Unformatted text preview:

EE 308 Spring 2012Lecture 12February 13, 2012More on using the Stack and the Stack PointerIntroduction to Programming the MC9S12 in C• Examples of using the stack• Including "derivative.inc" in an assembly language program• Using a mask in an assembly language program• Using the DIP switches on the Dragon12• Putting a program into the MC9S12 EEPROM• Displaying patterns from a table on the Dragon12 LEDs• Comparison of C and Assembly language programs1EE 308 Spring 2012Examples of Using the StackConsider the following:2000 org $20002000 cf 20 00 lds #$20002003 ce 01 23 ldx #$01232006 cc ab cd ldd #$abcd2009 34 pshx200a 36 psha200b 37 pshb200c 07 04 bsr delay200e 33 pulb200f 32 pula2010 30 pulx2011 3f swi2012 34 delay: pshx2013 ce 03 e8 ldx #10002016 04 35 fd loop: dbne x,loop2019 30 pulx201a 3d rtsThe following does not work; the RTS goes to the wrong place2000 org $20002000 cf 20 00 lds #$20002003 ce 01 23 ldx #$01232006 cc ab cd ldd #$abcd2009 34 pshx200a 36 psha200b 37 pshb200c 07 04 bsr delay200e 33 pulb200f 32 pula2010 30 pulx2011 3f swi2012 34 delay: pshx2013 ce 03 e8 ldx #10002016 04 35 fd loop: dbne x,loop2019 3d rts2EE 308 Spring 2012Using Registers in Assembly Language• The DP256 version of the MC9S12 has lots of hardware registers• To use a register, you can use something like the following:PORTB equ $0001• It is not practical to memorize the addresses of all the registers• Better practice: Use a file which has all the register names with their addresses#include "derivative.inc"• Here is some of derivative.inc;*** PORTA - Port A Register; 0x00000000 ***PORTA: equ $0000 ;*** PORTA - Port A Register; 0x0000 ***;*** PORTB - Port B Register; 0x0001 ***PORTB: equ $0001 ;*** PORTB - Port B Register; 0x0001 ***;*** DDRA - Port A Data Direction Register; 0x0002 ***DDRA: equ $0002 ;*** DDRA - Port A Data Direction Register; 0x0002 ***;*** DDRB - Port B Data Direction Register; 0x0003 ***DDRB: equ $0003 ;*** DDRB - Port B Data Direction Register; 0x0003 ***3EE 308 Spring 2012Using DIP switches to get data into the MC9S12• DIP switches make or break a connection (usually to ground)DIP Switches on Breadboard4EE 308 Spring 2012• To use DIP switches, connect one end of each switch to a resistor• Connect the other end of the resistor to +5 V• Connect the junction of the DIP switch and the resistor to an input port on the MC9S12• The Dragon12-Plus has eight dip switches which are already connected to Port H (PTH).• The four least significant bits of PTH are also connected to push-button switches.– If you want to use the push-button switches, make sure the DIP switches are inthe OFF position.• When the switch is open, the input port sees a logic 1 (+5 V)• When the switch is closed, the input sees a logic 0 (0.22 V)5EE 308 Spring 2012Looking at the stat e of a few input pins• Want to look for a particular pattern on 4 input pins– For example want to do something if pattern on PH3-PH0 is 0110• Don’t know or care what are on the other 4 pins (PH7-PH4)• Here is the wrong way to do it:ldaa PTHcmpa #$06beq task• If PH7-PH4 are anything other than 0000, you will not execute the task.• You need to mask out the Don’t Care bits before checking for the pattern on the bitsyou are interested in– To mask out don’t care bits, AND the bits with a mask which has 0’s in the don’tcare bits and 1’s in the bits you want to look at.ldaa PTHanda #$0Fcmpa #$06beq task• Now, whatever pattern appears on PH7-4 is ignored6EE 308 Spring 2012Using an MC9S12 output port to control an LED• Connect an output port from the MC9S12 to an LED.Using an output port to control an LEDPA0When a current flowsthrough an LED, itemits lightResistor, LED, andground connectedinternally insidebreadboard7EE 308 Spring 2012Making a pattern on a seven-segment LED• Want to generate a particular pattern on a seven-segment LED:dcgbafe• Determine a number (hex or binary) which will generate each element of the pattern– For example, to display a 0, turn on segments a, b, c, d, e and f, or bits 0,1, 2, 3, 4 and 5 of PTB. The binary pattern is 00111111, or $3f.– To display 0 2 4 6 8, the hex numbers are $3f, $5b, $66, $7d, $7f.• Put the numbers in a table• Go through the table one by one to display the pattern• When you get to the last element, repeat the loop8EE 308 Spring 2012Flowchart to display a pattern of lights on a set of LEDsnoX < end?Inc Pointerbsr delayyestableXSTARTldaa #$ffstaa DDRBldx #tableldaa 0,xstaa PORTBl1:l2:0x3f0x5b0x660x7d0x7ftable_endPORTBOutputPoint to first entryGet entryOutput toPORTBinxcpx #table_endbra l1blo l2Wait9EE 308 Spring 2012as12, an absolute assembler for Motorola MCU’s, version 1.2h; Program to display a pattern on a seven-segment LEDdisplay#include "hcs12.inc"2000 prog: equ $20001000 data: equ $10002000 stack: equ $20000005 table_len: equ (table_end-table)2000 org prog2000 cf 20 00 lds #stack ; initialize stack pointer2003 86 ff ldaa #$ff ; Make PORTB output2005 5a 03 staa DDRB ; 0xFF -> DDRB2007 ce 10 00 l1: ldx #table ; Start pointer at table200a a6 00 l2: ldaa 0,x ; Get value200c 5a 01 staa PORTB ; Update LEDs200e 07 08 bsr delay ; Wait a bit2010 08 inx ; point to next2011 8e 10 05 cpx #table_end ; More to do?2014 25 f4 blo l2 ; Yes, keep going through table2016 20 ef bra l1 ; At end; reset pointer2018 36 delay: psha2019 34 pshx201a 86 64 ldaa #100201c ce 1f 40 loop2: ldx #8000201f 04 35 fd loop1: dbne x,loop12022 04 30 f7 dbne a,loop22025 30 pulx2026 32 pula2027 3d rts1000 org data1000 3f table: dc.b $3f1001 5b dc.b $5b1002 66 dc.b $661003 7d dc.b $7d1004 7f dc.b $7F1005 table_end:10EE 308 Spring 2012Putting a program into EEPROM on the Dragon12-Plus• EEPROM from 0x400 to 0xFFF• Program will stay in EEPROM memory even after power cycle– Data will not stay in RAM memory• If you put the above program into EEPROM, then cycle power, you will display asequency of patterns on the seven-segment LED, but the pattern will be whatever junkhappens to be in RAM• To make sure you retain you patterns, put the table in the text part of your program,not the data part• If you use a variable which needs to be stored in data, be sure you initialize that variablein your program and not by using dc.b.• The Dragon12 board use s an 8 MHz clock. The MC9S12 has an internal phase-lockedloop which can change the clock speed. DBug12 increases the clock speed from 8 MHzto 48 MHz. When you run a program from EEPROM,


View Full Document

NMT EE 308 - EE 308 Lecture 12

Documents in this Course
Load more
Download EE 308 Lecture 12
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 EE 308 Lecture 12 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 EE 308 Lecture 12 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?