Radu Mihai Rotariu
Published © GPL3+

8-bit LED Counter XMC4800

Visual representation of an 8-bit counter with multiple basic functionalities.

BeginnerFull instructions provided4 hours168
8-bit LED Counter XMC4800

Things used in this project

Hardware components

Resistor 330 ohm
Resistor 330 ohm
×8
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×6
LED (generic)
LED (generic)
×8
Breadboard (generic)
Breadboard (generic)
×1
Infineon XMC4800 Relax Kit
×1

Software apps and online services

Infineon DAVE 4.4.2

Story

Read more

Schematics

Schematic

Schematic of the project

Code

main.c

C/C++
Main C program
#include <DAVE.h>

int main(void)
{
	DAVE_STATUS_t status;
	uint32_t i;	//contor delay
	uint16_t data = 0; //numar de afisat
	uint8_t isAutoIncrementOn = 1;

	status = DAVE_Init();

	if(status == DAVE_STATUS_FAILURE)
	{
		/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
		XMC_DEBUG("DAVE APPs initialization failed\n");

		while(1U) { }
	}

	/* Placeholder for user application code. The while loop below can be replaced with user application code. */
	while(1U)
	{
		while(data < 256)
		{
			if(DIGITAL_IO_GetInput(&AUTOINCREMENT_ON_OFF_BUTTON) == 0)
			{
				while(DIGITAL_IO_GetInput(&AUTOINCREMENT_ON_OFF_BUTTON) == 0);
				for(i = 0; i < 0x000fffff; ++i);
				if(isAutoIncrementOn == 1)
					isAutoIncrementOn = 0;
				else
					isAutoIncrementOn = 1;
				if(isAutoIncrementOn == 1)
				{
					data = 0;
				}
			}
			if(isAutoIncrementOn)
			{
				BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				for(i = 0; i < 0x000fffff; ++i);
				data += 1;
			}
			else
			{
				if(DIGITAL_IO_GetInput(&SHIFT_LEFT_BUTTON) == 0)
				{
					while(DIGITAL_IO_GetInput(&SHIFT_LEFT_BUTTON) == 0);
					data *= 2;
					if(data >= 256)
						data -= 256;
					BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				}
				if(DIGITAL_IO_GetInput(&SHIFT_RIGHT_BUTTON) == 0)
				{
					while(DIGITAL_IO_GetInput(&SHIFT_RIGHT_BUTTON) == 0);
					data /= 2;
					BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				}
				if(DIGITAL_IO_GetInput(&INCREMENT_BUTTON) == 0)
				{
					while(DIGITAL_IO_GetInput(&INCREMENT_BUTTON) == 0);
					data += 1;
					if(data == 256)
						data = 0;
					BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				}
				if(DIGITAL_IO_GetInput(&DECREMENT_BUTTON) == 0)
				{
					while(DIGITAL_IO_GetInput(&DECREMENT_BUTTON) == 0);
					if(data == 0)
						data = 255;
					else
						data -= 1;

					BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				}
				if(DIGITAL_IO_GetInput(&CLEAR_COUNTER_BUTTON) == 0)
				{
					while(DIGITAL_IO_GetInput(&CLEAR_COUNTER_BUTTON) == 0);
					data = 0;
					BUS_IO_Write(&LED_COUNTER_8_BITS, data);
				}
			}
		}
		data = 0;
	}

	return 1;
}

Credits

Radu Mihai Rotariu
2 projects • 0 followers
household engineer

Comments