Assembly procedure that represents binary using the LEDs on the mbed.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jp
Date:
Thu Jan 27 06:24:28 2011 +0000
Child:
1:7490aeb7d770
Commit message:

Changed in this revision

binasm.s Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/binasm.s	Thu Jan 27 06:24:28 2011 +0000
@@ -0,0 +1,50 @@
+ AREA    |.text|, CODE, READONLY
+ EXPORT  binasm
+
+binasm PROC
+    PUSH {R4, LR}
+    
+    MOV R1, #0
+    MOV R2, #0
+    MOV R3, #0
+
+    ; Load GPIO Port 1 base address in register R1 
+    LDR     R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address
+    LDR     R4, =leds
+
+    ;CLEAR LEDS
+    MOV.W   R2, #0xB40000
+    STR   R2, [R1,#0x1C]
+    
+    ADD R3, R3, #12 ; COUNTER FOR LOOP
+    ADD R0, R0, #1  ; INCREMENT PARAMETER BY 1
+    
+loop
+    ; CLEAR THE CARRY FLAG
+    ADC R0, R0, #0
+
+    LDR.W   R2, [R4, R3]
+    LSRS R0, R0, #1  
+
+    STRCC   R2, [R1,#0x1C]  ; if==0, clear LED bit
+    STRCS   R2, [R1,#0x18]  ; if==1, set LED bit    
+
+    CMP R3, #0
+    SUB R3, R3, #4
+    BNE loop
+    
+    POP {R4, PC}
+    ENDP
+
+ AREA |.data|, DATA, READWRITE
+ EXPORT leds
+         
+;BIT MASK FOR LED1...LED4
+
+leds DCD 0x040000 
+     DCD 0x100000
+     DCD 0x200000
+     DCD 0x800000
+    
+    ALIGN
+    END
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 27 06:24:28 2011 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+// This program will blink LED1 and LED4
+// using assembly language for LED1 and
+// API functions for LED4
+// declare external assembly language function (in a *.s file)
+extern "C" int binasm(int value);
+// declare LED outputs � let C set them up as output bits
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
+Timer t;
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main() {
+       
+     int i = 1; 
+     
+     while (true) {
+         binasm(i % 16);
+         wait(0.1);
+         i++;
+     }
+     
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jan 27 06:24:28 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1