

Int ledpatt = (msnib << 4) + lsnib // recombine as BCD Int lsnib = num % 10 // decimal value of each nibble Then you split the value into BCD nibbles, and combine them for output. The actual value is kept in the range 0.99 (note how the modulus is done when I decrement). I don't have a strip of LEDs handy right now, but this shows how to work within a decimal range, but only convert at the point of output. But whatevenr you need, you need to write it yourself: C language does not provide it. In your code, limit the range to 0-99, you have the choice of either wrap-around (99+1=0, and 0-1=99)or saturation (99+1=99, 0-1=0). Return (tens + ones) // so the result is A0 unsigned int dec2bcd(unsigned int num) // say num is now 100 Same problem, because your input is greater than 99. Return (tens + ones) // so the result is 95 Tens = temp<<4 // what's displayed is by tens is actually the lower When you do count = 0u -1, count acutally wraps to 65535 unsigned int dec2bcd(unsigned int num) // num is now 65535 WDTCTL = WDTPW | WDTHOLD // Stop watchdog timerĪs mentioned by msp430 uses 16bit integer. Pretty much any modification I did to my code prevents it from working properly.

I tried using an if statement to make a condition for MSB to stop if greater than ten but the code doesn't run. Problem number two: starting from zero if I decrement the value, the counter displays 95 rather than 99.Įx: starting from 0000 0000 decrement displays 1001 0101.

The first four bits are the ones(right) and the second four bits, tens(left) ex: 1010 0001 but the max value is 1001 1001. Problem number one: My counter on the "Tens" section(MSB) does not stop at 9 but rather begins to display binary 10-15. My code on the other hand has some glitches that I cannot fix with only an intro to C class under my belt. I have my wiring and configuration complete. I have to use three push buttons: one to increment, one to decrement, and the last to reset. I'm working on an assignment currently that uses a microcontroller and a circuit to display a decimal in binary, through LED's.
