Please help me write the code (ATmega16)

Hello, please help me write the code.The teacher gave the assignment, but after a long time searching for information on the Internet and trying to understand, I could not do anything. I don't need to flash anything, I just need the code to match the task.

Assignment: Create a schematic diagram and annotated C ++ program for an Atmel AVR ATmega16 8-bit microcontroller that implements the following algorithm:

  1. MCU is clocked from the built-in generator, the clock frequency is 4 MHz.
  2. The 10 kΩ potentiometer is connected to the ADC input (ADC3), operating in 8-bit mode, powered by the microcontroller voltage Vcc (5 V).
  3. When the timer T0 interrupts with the same time period, the ADC conversion result is read and displayed on a strip of 8 LEDs connected to the C ports (time period 0.2 seconds).
  4. When the button is pressed once (connected to PD3), the last measured value in the USART is displayed at 9600 baud without parity.

That is, the number of LEDs illuminated depends on the voltage, the higher the voltage, the more LEDs light up, if the voltage is 0, then the LEDs are off, if 5 - all the LEDs are on. It should look like an equalizer.

I made a diagram (I will attach it below), it seems to be correct, but I don’t know how to write the code, please help (preferably with comments).

A small clarification, maybe this is important, I am writing a project "GCC C ++ Executable Project" in Atmel studio.

Thanks

what have you tried?

The teacher gave the assignment to you, not us. Presumably you have had some lessons as preparation for this so where are you stuck ?

This is important to ensure that the student uses the raw commands to configure the device and not the more comfortable Atmel Start or Arduino or other development tools.

Start with your item 1. Go to the datasheet for the ATMega16 and look for "Calibrated Internal RC Oscillator". There you see how to set up the clock selection register for the required clock frequency.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.