[AVR] Please help me write the code (ATmega16)

Status
Not open for further replies.

Deadloop

Newbie
Joined
May 18, 2021
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
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
 

step 4 makes no sense.
Do you mean the last measured voltage should be transmitted from the UART when the button is pressed?
If you really mean to read the USART you need some circuitry to feed data to it.
You probably also need a resistor from PD3 to VCC or it will not be logic '1' when the button isn't pressed.

Brian.
 

Hi,

first draw a flow chart.
... here you should search the internet for other good flowcharts, just to see how they did

divide your progarm in smaller tasks - maybe with the help of the flow chart.
then divide each task to even smaller tasks.

then start with the mos basic task and try to write code.
again here: do an internet search, just to see how others did it.

***
Don´t try to write the whole code at once. Do it piece by piece.
Also don´t ask very global questions here in this forum - please ask detailed questions. Show what you have read (links), show how you tried to solve it on your own.
Then we will help you to rectify mistakes.

Again: step by step.
Maybe start with the task that sounds to be the simplest. Focus on it.
Go to the next task not before the other is solved.

Klaus

added:
Please clarify:
* 3) sounds as if you should show the binary value of the ADCon the LEDs
* but your description more sonds as if you want to build a bar graph
 

A breakdown of tasks -

1) Declare a byte variable and write it to a port, the LED port.
2) Setup and start A/D and read its value into a variable.
3) Setup a timer and learn how to do an interrupt triggered from its
output. When you put code together this will be used to trigger the
A/D and get its value when it finishes its conversion.
4) Button should be de-bounced, google this on internet for ideas on
debounce.




Internet, and IDE tool you are using probably has basic examples you can'
inspect, learn from, for these individual tasks.

One basic step at a time as Klaus has indicated.

Regards, Dana.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…