Picaxe LED |
|
To gain access to revision questions, please sign up and log in.
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.
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: |
|
movw 0x01 |
|
movwr PORTB |
|
call wail100ms |
|
movw 0x00 |
|
movwr PORTB |
|
jmp start |
|
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