Created
July 4, 2011 16:23
-
-
Save biomood/1063573 to your computer and use it in GitHub Desktop.
Displays the binary representation of an unsigned char using an MSP430
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.c | |
// BlinkingLEDs | |
// | |
// Created by David Roberts on 30/06/2011. | |
// Copyright 2011 __MyCompanyName__. All rights reserved. | |
// | |
#include <io.h> | |
int main (void) | |
{ | |
// disable the watchdog timer | |
WDTCTL = WDTPW + WDTHOLD; | |
unsigned char value = 5; | |
unsigned char mask = 128; | |
// all pins in off state | |
P1OUT = 0; | |
// set pins 0, 5, 6 as outputs | |
P1DIR |= BIT0; | |
P1DIR |= BIT6; | |
P1DIR |= BIT5; | |
// display starting LED | |
P1OUT = 32; | |
volatile unsigned int i; | |
for (i=0; i<60000; i++); | |
// flash off | |
P1OUT = 0; | |
for (i=0; i<60000; i++); | |
// iterate through each bit in value, comparing to mask | |
for (i=0; i<8; i++) { | |
// set red/white to display if 1/0 | |
if ((value & mask) == mask){ | |
P1OUT |= 1; | |
} | |
else { | |
P1OUT |= 64; | |
} | |
// shift mask along to compare next bit | |
mask = mask >> 1; | |
// display bit LED | |
volatile unsigned int j; | |
for(j=0; j<60000; j++); | |
// flash off | |
P1OUT = 0; | |
for (j=0; j<60000; j++); | |
} | |
// display ending LED | |
P1OUT = 32; | |
for (i=0; i<60000; i++); | |
P1OUT = 0; | |
while(1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment