George Hadley
/
Counter
A simple binary counter program that uses the onboard mbed leds to represent bits
main.cpp@0:824a95146598, 2010-03-19 (annotated)
- Committer:
- nbitwonder
- Date:
- Fri Mar 19 17:08:07 2010 +0000
- Revision:
- 0:824a95146598
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nbitwonder | 0:824a95146598 | 1 | /**************************************************************************************** |
nbitwonder | 0:824a95146598 | 2 | * Date Created: 2/26/2010 |
nbitwonder | 0:824a95146598 | 3 | * Title: NBitWonder Binary Counter Code Example |
nbitwonder | 0:824a95146598 | 4 | * Description: A binary adder implemented using the mbed embedded development platform. |
nbitwonder | 0:824a95146598 | 5 | * This program utilizes the mbed's 4 onboard leds to represent the value of a 4-bit |
nbitwonder | 0:824a95146598 | 6 | * binary variable. The variable begins at 0 and is incremented once every second. |
nbitwonder | 0:824a95146598 | 7 | * Author: George Hadley |
nbitwonder | 0:824a95146598 | 8 | * Website: http://nbitwonder.com |
nbitwonder | 0:824a95146598 | 9 | ****************************************************************************************/ |
nbitwonder | 0:824a95146598 | 10 | #include "mbed.h" |
nbitwonder | 0:824a95146598 | 11 | |
nbitwonder | 0:824a95146598 | 12 | //LED Output initializations |
nbitwonder | 0:824a95146598 | 13 | BusOut Bits(LED1,LED2,LED3,LED4); //LED outputs for counter |
nbitwonder | 0:824a95146598 | 14 | |
nbitwonder | 0:824a95146598 | 15 | char bin_val = 0x00; |
nbitwonder | 0:824a95146598 | 16 | int main() { |
nbitwonder | 0:824a95146598 | 17 | while(1) { |
nbitwonder | 0:824a95146598 | 18 | //increment bin_val, resetting if 4-bit overflow condition occurs |
nbitwonder | 0:824a95146598 | 19 | bin_val++; |
nbitwonder | 0:824a95146598 | 20 | if(bin_val > 0x0F) |
nbitwonder | 0:824a95146598 | 21 | { |
nbitwonder | 0:824a95146598 | 22 | bin_val = 0; |
nbitwonder | 0:824a95146598 | 23 | } |
nbitwonder | 0:824a95146598 | 24 | //Assign bin_val to led output |
nbitwonder | 0:824a95146598 | 25 | Bits = bin_val; |
nbitwonder | 0:824a95146598 | 26 | //wait 1 second |
nbitwonder | 0:824a95146598 | 27 | wait(1); |
nbitwonder | 0:824a95146598 | 28 | } |
nbitwonder | 0:824a95146598 | 29 | } |