CMP EMBEDDED.COM

Login | Register     Welcome Guest RFID World  Logic NVM  TeardownTV
 

Listing 1: Pseudo-code for a simple toy

; --- Power-on reset entry point ; --- Enable interrupts on falling edge of triggers 1 (tummy switch) ; --- and 2 (gravity switch), and rising edge of trigger 2. POR: LD INT_ENABLE, TG1_LO OR TG2_LO OR TG2_HI LD R0, GIGGLE ; Register 0 is used to store the next sound ; to be played when the tummy switch is pressed. STOP ; Power down and wait for interrupt.

; --- Micro jumps here when trigger 1 detects a falling edge (tummy switch is pressed). ; --- Note: Switch debouncing is performed in hardware by the microcontroller. ; --- The input pins also have internal pull-ups, so no external parts are ; --- required. TG1_LO: [rampin] ; This is a vendor-supplied macro that ramps ; the ADPCM decoder output up to its center ; point JMP R0, TG2_HI ; If the doll is upright (TG2 = high), play ; one ofthe three tummy behavior sounds below. [cry] ; Otherwise, cry [rampout] ; Ramp the decoder output back to 0V STOP

; --- Tummy behavior #1 GIGGLE: [giggle] ; Play the giggle sound LD R0, LAUGH ; Next time around, we will laugh [rampout] ; Ramp the decoder output back to 0V STOP

; --- Tummy behavior #2 LAUGH: [laugh] ; Play the laughing sound LD R0, NONSENSE ; Next time around, we will talk nonsense [rampout] ; Ramp the decoder output back to 0V STOP

; --- Tummy behavior #3 NONSENSE: [nonsense] ; Play a happy-sounding baby-talk phrase LD R0, GIGGLE ; Loop back around to the first sound in the series [rampout] ; Ramp the decoder output back to 0V STOP

; --- Micro jumps here when trigger 2 detects a falling edge (doll is laid down). TG2_LO: [rampin] ; Ramp the decoder output to its center point [snore] ; Snore for a little while [rampout] ; Ramp the decoder output back to 0V STOP

; --- Micro jumps here when trigger 1 detects a rising edge (doll is stood up). TG1_HI: [rampin] ; Ramp the decoder output to its center point [yawn] ; Good morning! Yawn. [rampout] ; Ramp the decoder output back to 0V STOP

Return to Table of Contents

Embedded.com Career Center
Ready to take that job and shove it?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS


 :