90 likes | 240 Views
Embedded Systems 7763B. Mt Druitt College of TAFE Electrical Engineering Lesson 3 Declaring variables in memory for storing data. Assignment 1b new spec. Using EQU ate. Used to declare a variable and allocate defined memory location
E N D
Embedded Systems7763B Mt Druitt College of TAFE Electrical Engineering Lesson 3Declaring variables in memory for storing data
Assignment 1b new spec. Mike Stacey 2008
Using EQUate • Used to declare a variable and allocate defined memory location • .equ pin_1 = 0x0060 ; assigns data space address 0060 to variable named pin_1. • Use .equ to assign memory space for the pin numbers in assignment 3. Mike Stacey 2008
GetPin Subroutine ; Assign data space ; address to variables.equ pin1 = 0x0060.equ pin2 = 0x0061.equ pin3 = 0x0062.equ pin4 = 0x0063 • You can then access this data using load and store instructions: • LDS ; load direct from data space. Loads 1 byte from data space to register in uC. • STS ; store direct to data space. Stores 1 byte from register in uC to data space • See DEMO of GetPin in class Mike Stacey 2008
Code example [1] ; Store PIN ldi pin_holder, '9' sts pin1, pin_holder ldi pin_holder, '1' sts pin2, pin_holder ldi pin_holder, '5' sts pin3, pin_holder ldi pin_holder, '6' sts pin4, pin_holder GetPin: rcall displayReady ldi pin_holder, $00 lds pin_holder, pin1 rcall GetKey cp pin_holder, k1 brne DisplayError lds pin_holder, pin2 rcall GetKey cp pin_holder, k1 brne DisplayError lds pin_holder, pin3 rcall GetKey cp pin_holder, k1 brne DisplayError lds pin_holder, pin4 rcall GetKey cp pin_holder, k1 brne DisplayError Mike Stacey 2008
Code example [2] DisplayOK: ldi temp, $55 out PortA, temp rjmp Clear DisplayError: ldi temp, $66 out PortA, temp rjmp Clear DisplayReady: ldi temp, $AA out PortA, temp ret Clear: rcall GetKey cpi k1, 'C' brne Clear rjmp GetPin Mike Stacey 2008
Addition to ‘GetKey’ • You need to add a bit of code that will only allow GetKey to return after the key pressed has been released Mike Stacey 2008
Code example [1] GetKey: ldi k1,$00 rcall keyscan cpi keyval,$ff breq GetKey mov k1,keyval rcall delay rcall keyscan cp k1,keyval brne GetKey ;// Only return from GetKey ;// when the key has been ;//released Release: rcall keyscan cpi keyval,$ff brne release ;/// Key pressed is ;/// in 'k1' ret Mike Stacey 2008
GetKey • See web for new version Mike Stacey 2008