I have been busy with the CAN bus project recently, so I haven't updated the ATMEGA4809 related updates in time. Now I have updated some basic things in the forum, hoping that it will be of some help to everyone.
I believe that everyone has already mastered some basic operations by reading other great posts, so here I will directly post some of my tests here. Later, I will post some posts about the combination of CAN bus and ATMEGA4809, and I hope it will be helpful to everyone.
For serial port applications, the pins should be correctly configured, as shown in the following figure
You still have to choose PB0 and PB1 as the built-in serial ports. In addition, you can choose PF5 as the LED that works synchronously with the serial port to display the corresponding information to prove that your program is running normally.
In addition, relevant settings should be made in the pin option interface, as shown below
Since today we are only introducing the sending test, I will only check one item.
After the basic settings are completed, you can write the program in the main program:
#include "mcc_generated_files/mcc.h"
#include <stdio.h>
/*
Main application
*/
uint8_t volt[16]={10,14,18,22,26,30,34,38,40,38,34 ,30,26,22,18,14};
uint8_t displayvolt[20];
int main(void)
{
uint8_t a,b,c,d,e,f;
b=0;
//e=1;
c=1 ;
/* Initializes MCU, drivers and middleware */
SYSTEM_Initialize();
/* Replace with your application code */
while (1)
{
for(a=0;a<20;a++)
{ displayvolt[a]=volt;
b++;
if(b>=16)
b=0;
printf("displayvolt[%d]",a);
for(c=0;c<displayvolt[a];c++)
{ printf("*"); }
printf("\n");
}
//DELAY_milliseconds( 100);;
}
}
This is just a basic program that uses the serial port to print a sine string. The effect is as follows:
If you rotate the image counterclockwise, it will be a sine wave.
I hope this is helpful to beginners. If you are an expert, please skip this article.
This content was originally created by desk1983 , a user on the EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.