Can someone please help me with this? I have been researching and trying to get this working, but I'm out of luck. All the codes I found online were not working... The output, for now, is 00, 11, 22, 33, ... FF and lop back to 00. How do I separate the first and second digit displays? Like I want it to display from 0 to 255 (00, 01, 02...FF)?
Requirements:
When the circuit is first energized, the seven-segment LEDs will start counting at 0x00.
The duel segment LEDs will count up to 0xFF, increasing by 1 each time. The count MUST BE sequential. It is unacceptable to count 0 to F to 0 on digit 2, then increase digit 1 by 1. The count shall perform like a counter (0x00 to 0x0F then 0x10 etc.).
Once the count reaches 0xFF, the count will start over at 0x00.
The code will contain sufficient delay between incrementing the count so that the count can be visually confirmed that the circuit/code is operating as designed.
The above will occur infinitely, another word, in an endless loop until the device is powered down.
Source code:
#include
void PORTA_init(void)
{
PORTA = 0; // All PORTA Pins are low
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
//TRISA = 0b001111; // RA4 and 5 are outputs; RA0,1,2, and 3 are input
return;
}
/******** END OF PORTA_init ****************************/
/********************************************************
* Notes:
*
* Delay was determined through trial and error
*
* Returns: None
* ********************************************************/
/** Function: main *************************************
*
* Notes:
*
* RA4 - Positive LED Connection for D0
* RA5 - Negative LED Connection for D0
*
* Returns: None -- This routine contains an infinite loop
*
*/
// CONFIG --- Configuration Word --- START
#pragma config FOSC = INTOSCIO
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = OFF
#pragma config CP = OFF
#pragma config CPD = OFF
#pragma config BOREN = OFF
#pragma config IESO = OFF
#pragma config FCMEN = OFF
// CONFIG --- Configuration Word --- END
int i, j;
int DisplayValue, DisplayLED;
//PLACE LEDDigit ARRAY HERE
const char LEDDigit[] = {
0b0000001, // "0"
0b1001111, // "1"
0b0010010, // "2"
0b0000110, // "3"
0b1001100, // "4"
0b0100100, // "5"
0b0100000, // "6"
0b0001111, // "7"
0b0000000, // "8"
0b0000100, // "9"
0b0001000, // "A"
0b1100000, // "b"
0b0110001, // "C"
0b1000010, // "d"
0b0110000, // "E"
0b0111000}; // "F"
main()
{
PORTA = 0;
PORTC = 0;
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
TRISA = 0b011100;
TRISC = 0b000000;
DisplayValue = 0; // Start Displaying at 0x00
DisplayLED = 0; // Display the 1s first
while(1 == 1) // Loop Forever
{
if (0 == DisplayLED) // True, then display right digit
{
RA5 = LEDDigit[DisplayValue & 0x0F] >> 6;
// Clears display bits 4 - 7 of DisplayValue,
// then selects bit 7 of LEDDigit
PORTC = LEDDigit[DisplayValue & 0x0F] & 0x03F;
// clears display bits 4 - 7 of DisplayValue,
// then selects bits 0 - 6 of LEDDigit
}
else
{
RA5 = LEDDigit[(DisplayValue >> 4) & 0x0F] >> 6;
PORTC = LEDDigit[(DisplayValue >> 4) & 0x0F] & 0x03F;
} //
TRISA = TRISA ^ 0b011111; // Swap Left/Right
PORTA = PORTA & 0b111100; // Make Sure Bits are Low
DisplayLED = DisplayLED ^ 1; // Other Digit Next
NOP(); // Used for 10 ms Timing
for (i = 0; i < 660; i++); // 10 ms Delay Loop
NOP(); // Used for 10 ms Timing
j = j + 1; // Increment the Counter?
if (25 == j) // 1/4 Second Passed?
{
DisplayValue++; // Increment the Counter
j = 0; // Reset for another 1/4 Second
} //
} //
} //