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 $00C7rtsProgram 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 HC12DIP switches make or break a connection (usually to ground)+5VDIP Switches on Breadboard2EE 308 Spring 2002To use DIP switches, connect one end of each switch to a resistorConnect the other end of the resistor to +5 VConnect the junction of the DIP switch and the resistor to an input port on theHC12+5V+5V+5V +5V+5VPB1PB0Using DIP SwitchesWhen 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 pinsWant to look for a particular pattern on 4 input pins– For example want to do something if pattern on PB3-PB0 is 0110Don’t know or care what are on the other 4 pins (PB7-PB4)Here is the wrong way to do it:ldaa PORTBcmpa #b0110beq taskIf 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 taskNow, whatever pattern appears on PB7-4 is ignored4EE 308 Spring 2002Using an HC12 output port to control an LEDConnect 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 LEDsWant to generate a particular pattern on a set of LEDs:6EE 308 Spring 2002Determine a number (hex or binary) which will generate each element of thepatternPut these numbers in a tableGo through the table one by one to display the patternWhen 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