View Index by Level
RANDOM PAGE

SITE SEARCH

LOG
IN

SIGN UP

HELP

Picaxe LED


This is the AQA version closing after June 2019. Visit the the version for Eduqas instead.

To gain access to revision questions, please sign up and log in.

A2

Hello World!

When programming traditional computers, lesson one is to display "Hello World!"

With microcontrollers, lesson one is to control an LED and make it flash.

Connect an LED as shown here. The current limiting resistor is built into the PICAXE board.

PX-01-LED.JPG

Run the PICAXE programming editor.

; ===== AQA CODE - RUNS ON THE PICAXE 28X1 CHIP =====
start:
        movw    0x01            ; 00000001
        movwr   PORTB           ; Set PORTB to the binary above
        call    wait100ms       ; Call the built-in 100 ms delay
        movw    0x00            ; 00000000
        movwr   PORTB           ; Set PORTB to the binary above
        call    wait100ms       ; Call the built-in 100 ms delay
        jmp     start           ; Go back and do it all again
; ===== END OF AQA CODE =============================


; ===== NATIVE CODE FOR THE PICAXE 28X1 CHIP ========
START:
        PINS = 1
        PAUSE 100
        PINS = 0
        PAUSE 100
        
        GOTO START
; ===================================================

The code repeats for ever. Here is a line by line explanation.

Command

Explanation

start:

  • This is a label.
  • It labels an address.
  • The jmp command jumps to this address.
  • It is hard for humans to keep track of addresses so labels are used to make life easier.
  • The ASSEMBLER translates the human readable labels back into addresses.

movw 0x01

  • This moves 00000001 (binary) into the W register.
  • 0x01 is a hexadecimal number representing 00000001 (binary)

movwr PORTB        

  • This moves the contents of the W register to PORTB.
  • The effect is to make pin 0 of PORTB go high.
  • This turns ON the LED.

call wail100ms

  • This is a built-in subroutine that produces a 100 millisecond delay.
  • CALL is the keyword used to call the subroutine.
  • When the subroutine is complete, the program continues from where it left off.
  • wail100ms is a useful extra but NOT an AQA Assembler command.

movw 0x00

  • This moves 00000000 (binary) into the W register.
  • 0x01 is a hexadecimal number representing 00000000 (binary)

movwr PORTB

  • This moves the contents of the W register to PORTB.
  • The effect is to make pin 0 of PORTB go low.
  • This turns OFF the LED.

jmp start

  • This causes the program to return to the start.
  • The PROGRAM COUNTER is set to the address labelled by start:

AQA Simulator Version

CTRL+Click here to run the simulator.

This identical code runs on the AQA Simulator but you have to write your own wait100ms subroutine. The timings are not realistic.

; ===== LED FLASH =====
start:
    movw    0x01            ; 00000001
    movwr   PORTB           ; Set PORTB
    call    wait100ms       ; Call 100 ms delay
    movw    0x00            ; 00000000
    movwr   PORTB           ; Set PORTB 
    call    wait100ms       ; Call 100 ms delay
    jmp     start           ; Do it all again

wait100ms:
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    RET

 

 

 

reviseOmatic V3     Contacts, ©, Cookies, Data Protection and Disclaimers Hosted at linode.com, London