01
02
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
03
AVR单片机中对IO口进行操作之前需要进行相应的初始化设置,其设置步骤如下:
1 通过方向寄存器DDRx设置相应的端口为输入或者输出。
2 如果设置为输出的话,把需要输出的数据送往数据寄存器PORTx。如果设置为输入的话,从输入寄存器PINx中读取外部的输入值,同时可以通过设置PORTx来设置相应的引脚是否需要上拉电阻。
04
使用Atmel Studio点灯
/*
* GccApplication1.c
*
* Created: 2023/5/18/星期三 14:48:19
* Author : LiuYao
* Board : Arduino Nano
*/
#ifndef F_CPU
#define F_CPU 10000000UL
#endif
#include
#include
int main(void)
{
DDRB =(1</* Replace with your application code */
while (1)
{
PORTB |=(1<_delay_ms(1000);
PORTB &= !(1<_delay_ms(1000);
}
return 0;
}
Use Output window
。-C "D:\Software\Arduino\hardware\tools\avr\etc\avrdude.conf" -v -p atmega328p -c arduino -P COM7 -b 115200 -D -U flash:w:"$(ProjectDir)Debug\$(TargetName).hex":i
Usage: avrdude.exe [options]
Options:
-pRequired. Specify AVR device.
-bOverride RS-232 baud rate.
-BSpecify JTAG/STK500v2 bit clock period (us).
-CSpecify location of configuration file.
-cSpecify programmer type.
-D Disable auto erase for flash memory
-iISP Clock Delay [in microseconds]
-PSpecify connection port.
-F Override invalid signature check.
-e Perform a chip erase.
-O Perform RC oscillator calibration (see AVR053).
-U:r|w|v: [:format]
Memory operation specification.
Multiple -U options are allowed, each request
is performed in the order specified.
-n Do not write anything to the device.
-V Do not verify.
-u Disable safemode, default when running from a script.
-s Silent safemode operation, will not ask you if
fuses should be changed back.
-t Enter terminal mode.
-E[, ] List programmer exit specifications.
-xPass to programmer.
-y Count # erase cycles in EEPROM.
-YInitialize erase cycle # in EEPROM.
-v Verbose output. -v -v for more.
-q Quell progress output. -q -q for less.
-l logfile Use logfile rather than stderr for diagnostics.
-? Display this usage.
Arduino UNO
。-END-
新手选 Arduino 还是 树莓派?
STM32和Arduino对比,谁更厉害?
各种Arduino外设的用法,生动形象,相当好看!