The most traditional lighting step has arrived. According to the logo on the board, the built-in light on the board corresponds to the PF5 pin.
According to the programming specification of XC8, it can be concluded that:
PORTF = Input and output registers of PF series pins
OUTTGL=Output Value Toggle, which means IO flip
AVR microcontroller comes with a delay function library, which is referenced.
\note As an alternative method, it is possible to pass the
F_CPU macro down to the compiler from the Makefile.
Obviously, in that case, no \c \#define statement should be
used.
Delay.h tells us that we need to configure the clock, that is, F_CPU, before using the delay function. After configuration, find the corresponding delay function template in delay.h and apply it in our program.
This content is originally created by EEWORLD forum user yang8555u . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
/*
* File: avr-main.c
* Author: 11618
*
* Created on 2019?10?31?, ??1:27
*/
#define F_CPU 2000000/6
#include <xc.h>
#include <util/delay.h>
int main(void) {
PORTF.DIR |=(1<<5);/* Replace with your application code */
while (1) {
PORTF.OUTTGL|= (1<<5);
_delay_ms(500) ;
}
return 0;
}