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.
main.cpp@1:158078765a61, 2015-01-07 (annotated)
- Committer:
- edumana
- Date:
- Wed Jan 07 16:52:00 2015 +0000
- Revision:
- 1:158078765a61
- Parent:
- 0:9a1865214ee0
This program toggles the green and red LEDs of the FRDM K22F at the register level.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| edumana | 1:158078765a61 | 1 | /* |
| edumana | 1:158078765a61 | 2 | * This program toggles the green and red LEDs of the FRDM K22F Board |
| edumana | 1:158078765a61 | 3 | * at the register level. Refer to the MK22FN512VLH12 datasheet |
| edumana | 1:158078765a61 | 4 | * to understand the registers. |
| edumana | 1:158078765a61 | 5 | * |
| edumana | 1:158078765a61 | 6 | * At the general level: |
| edumana | 1:158078765a61 | 7 | * Sets PTA1 and PTA2 which LEDs are connected to GPIO mode. |
| edumana | 1:158078765a61 | 8 | * Sets both pins to be digital output. |
| edumana | 1:158078765a61 | 9 | * Turns red LED off by writing a 1 and leaves green on. |
| edumana | 1:158078765a61 | 10 | * Enters a loop which uses the Toggle Output Register to turn |
| edumana | 1:158078765a61 | 11 | * LEDs on and off. |
| edumana | 1:158078765a61 | 12 | */ |
| edumana | 0:9a1865214ee0 | 13 | #include "mbed.h" |
| edumana | 0:9a1865214ee0 | 14 | Serial pc(USBTX, USBRX); |
| edumana | 0:9a1865214ee0 | 15 | void pr(volatile uint32_t *reg); |
| edumana | 0:9a1865214ee0 | 16 | |
| edumana | 0:9a1865214ee0 | 17 | int main(){ |
| edumana | 0:9a1865214ee0 | 18 | |
| edumana | 1:158078765a61 | 19 | PORTA_PCR1 = 0x143; //Sets pin to GPIO mode |
| edumana | 1:158078765a61 | 20 | PORTA_PCR2 = 0x143; //Sets pin to GPIO mode |
| edumana | 0:9a1865214ee0 | 21 | GPIOA_PDDR = 0x6; //Sets pin to output |
| edumana | 0:9a1865214ee0 | 22 | GPIOA_PSOR = 0x2; //Turns RED off, Leaves GREEN on |
| edumana | 0:9a1865214ee0 | 23 | |
| edumana | 0:9a1865214ee0 | 24 | while (1){ |
| edumana | 0:9a1865214ee0 | 25 | int volatile counter = 0; |
| edumana | 0:9a1865214ee0 | 26 | while(counter < 10000000){ |
| edumana | 0:9a1865214ee0 | 27 | counter++; |
| edumana | 0:9a1865214ee0 | 28 | } |
| edumana | 1:158078765a61 | 29 | GPIOA_PTOR = 0x6; //Toggles RED and GREEN LEDs |
| edumana | 0:9a1865214ee0 | 30 | } |
| edumana | 0:9a1865214ee0 | 31 | } |
| edumana | 1:158078765a61 | 32 | //Debuggin tool, it prints register [address]--> [contents] |
| edumana | 1:158078765a61 | 33 | //Pass the "address of" a register, i.e: pr(&PORTA_PCR1) |
| edumana | 0:9a1865214ee0 | 34 | void pr(volatile uint32_t *reg){ |
| edumana | 0:9a1865214ee0 | 35 | pc.printf("%x --> %x \n", reg, *reg); |
| edumana | 0:9a1865214ee0 | 36 | } |