Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:158078765a61, committed 2015-01-07
- Comitter:
- edumana
- Date:
- Wed Jan 07 16:52:00 2015 +0000
- Parent:
- 0:9a1865214ee0
- Commit message:
- This program toggles the green and red LEDs of the FRDM K22F at the register level.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file | 
--- a/main.cpp	Wed Jan 07 16:41:41 2015 +0000
+++ b/main.cpp	Wed Jan 07 16:52:00 2015 +0000
@@ -1,13 +1,23 @@
+/* 
+ * This program toggles the green and red LEDs of the FRDM K22F Board 
+ * at the register level. Refer to the MK22FN512VLH12 datasheet
+ * to understand the registers.
+ * 
+ * At the general level:
+ * Sets PTA1 and PTA2 which LEDs are connected to GPIO mode.
+ * Sets both pins to be digital output.
+ * Turns red LED off by writing a 1 and leaves green on.
+ * Enters a loop which uses the Toggle Output Register to turn 
+ * LEDs on and off.  
+*/
 #include "mbed.h"
-
 Serial pc(USBTX, USBRX);
-
 void pr(volatile uint32_t *reg);
 
 int main(){
 
-    PORTA_PCR1 = 0x143; //Sets pin to GPIO
-    PORTA_PCR2 = 0x143; //Sets pin to GPIO
+    PORTA_PCR1 = 0x143; //Sets pin to GPIO mode
+    PORTA_PCR2 = 0x143; //Sets pin to GPIO mode
     GPIOA_PDDR = 0x6; //Sets pin to output
     GPIOA_PSOR = 0x2; //Turns RED off, Leaves GREEN on
     
@@ -16,10 +26,11 @@
         while(counter < 10000000){
             counter++;
         }
-        GPIOA_PTOR = 0x6; //Toggles 0110, RED and GREEN LEDs   
+        GPIOA_PTOR = 0x6; //Toggles RED and GREEN LEDs 
     }
 }
-//Print Register: pr
+//Debuggin tool, it prints register [address]--> [contents]
+//Pass the "address of" a register, i.e: pr(&PORTA_PCR1)
 void pr(volatile uint32_t *reg){
     pc.printf("%x --> %x \n", reg, *reg);
 }