I'm currently taking a course in university for microcontrollers. We have been provided with the brief for the final project for the course. In short, we are required to use an Arduino Uno with ATmega328P to interface with a DHT11 temperature and humidity sensor. The information from the DHT11 sensor should be displayed on three seven segment displays. At this point in time, my program is able to accept any number between 0 and 99 and display it on two of the three seven segment displays.
My code works like this:
1. Assign a value between 0 and 99 to the R16 (this register will eventually receive the value from the DHT11 sensor. But for now I just enter a value)
2. Take the value in R16 and convert it to a binary coded decimal. Store this result in R0.
3. Take the upper nibble of R0 and use a lookup table to find the correct bit pattern to display the appropriate value on the seven segment display. Store this result in R2.
4. Perform the same operations as step three on the lower nibble in R0 and store the result in R3.
5. Use the values in R2 and R3 to turn on the seven segment displays.
Currently, I have three separate programs. The first program consists of steps 1 and 2. The second program consists of steps 3 and 4. The final program runs step 5.
If I feed in a number (say 49) into the first program. It returns the correct BCD value (in this example, its 0b01001001). If I take this result and feed it into program two, I also receive the correct bit patterns (again, for this example I would receive 0b11001100 in R2 and 0b11011110 in R3. The bit pattern in R2 corresponds to the pins on the mcu that display four and likewise the bit pattern in R3 would display nine.) If I take the results in R2 and R3 and feed them into my third program and load it onto the mcu, the seven segment displays show the correct result (49).
Until now, everything is functioning as desired.
Now for my issue:
I've merged programs two and three into one program. If I take a result from program one and feed it into this new program, my seven segment displays still show the correct answer. If I take this new program and combine it with program one and run this program in Atmel Studio, I still read the correct bit pattern in the port registers. However, if I load this program onto my mcu and provide it with a value (lets use 49 again), the seven segment displays simply show an unintelligible result.
Before I posted this question, I went through my code in the debugger and checked that all the registers were being modified appropriately and not unintentionally. At the end of the debug, the port registers have the correct value. However, the result I get on the seven segment display is not in agreement with the port registers.
I've also simulated my program on AVR Simulator IDE and it also provides the correct result.
I'm a bit lost. Could someone please point me in the correct direction.
P.S. I've tried to avoid adding code to my post as probably quite a few of my classmates are looking for answers here as well
EDIT (As per Jim's comment):
I forgot to mention that the seven segment displays are
charlieplexed multiplexed (apologies for the confusion. I still have lots to learn )