DOC PREVIEW
NMT EE 308 - Another Example of using a subroutine

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:

EE 308 Spring 2002Another example of using a subroutineUsing a subroutine to wait for an event to occur, then take an action.Wait until bit 7 of address $00C4 is set.Write the value in ACCA to address $00C7.; This routine waits until the HC12 serial; port is ready, then sends a byte of data; to the HC12 serial portputchar: brclr $00C4,#$80staa $00C7rtsProgram to send the word hello to the HC12 serial port; Program fragment to write the word "hello" to the; HC12 serial portldx $strloop: ldaa 1,x+ ; get next charbeq done ; char == 0 => no morejsr putcharbra loopswistr: dc.b "hello",01EE 308 Spring 2002Using DIP switches to get data into the HC12DIP switches make or break a connection (usually to ground)+5VDIP Switches on Breadboard2EE 308 Spring 2002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 theHC12+5V+5V+5V +5V+5VPB1PB0Using DIP Switches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 V)3EE 308 Spring 2002Looking at the state 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 PB3-PB0 is 0110Don’t know or care what are on the other 4 pins (PB7-PB4)Here is the wrong way to do it:ldaa PORTBcmpa #b0110beq taskIf PB7-PB4 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 onthe bits you are interested inldaa PORTBanda #b00001111cmpa #b00000110beq taskNow, whatever pattern appears on PB7-4 is ignored4EE 308 Spring 2002Using an HC12 output port to control an LEDConnect an output port from the HC12 to an LED.Using an output port to control an LEDPA0When a current flowsthrough an LED, itemits lightResistor, LED, andground connectedinternally insidebreadboard5EE 308 Spring 2002Making a pattern on a set of LEDsWant to generate a particular pattern on a set of LEDs:6EE 308 Spring 2002Determine a number (hex or binary) which will generate each element of thepatternPut these numbers in a tableGo through the table one by one to display the patternWhen you get to the last element, repeat the loop0x000x800xC00XE00xF00xF80xFC0xFE0xFFSet up a table.Successively load data from tableStart over again when at end of table7EE 308 Spring 2002Flowchart to display a pattern of lights on a set of LEDsX < end?Inc PointerOutput toPORTAPORTAOutputPoint to first entryGet entrytable0x000x800xC00xE00xF00xF80xFC0xFE0xFFtable_endXSTARTldaa #$ffstaa DDRAldx #tableldaa 0,xstaa PORTAinxcpx #table_endbls l2bra l1l1:l2:8EE 308 Spring 2002; Program using subroutine to make a time delayprog: equ $0800data: equ $0800stack: equ $0A00PORTA: equ $0000DDRA: equ $0002CODE: section .textorg proglds #stack ; initialize stack pointerldaa #$ff ; Make PORTA outputstaa DDRA ; 0xFF -> DDRAl1: ldx #table ; Start pointer at tablel2: ldaa 1,x+ ; Get value; point to nextstaa PORTA ; Update LEDsjsr delay ; Wait a bitcpx #table_end ; More to do?bls l2 ; Yes, keep going through; tablebra l1 ; At end; reset pointerDATA: section .dataorg datatable: dc.b $00dc.b $80dc.b $C0dc.b $E0dc.b $F0dc.b $F8dc.b $FCdc.b $FEtable_end: dc.b $FF9EE 308 Spring 2002; Subroutine to wait for 100 msdelay: pshapshxldaa #250loop2: ldx #800loop1: dexbne loop1decabne


View Full Document

NMT EE 308 - Another Example of using a subroutine

Documents in this Course
Load more
Download Another Example of using a subroutine
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 Another Example of using a subroutine 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 Another Example of using a subroutine 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?