我玩Arduino,但我使用寄存器开发
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点灯
4.1 新建工程
/*
* GccApplication1.c
*
* Created: 2023/5/18/星期三 14:48:19
* Author : LiuYao
* Board : Arduino Nano
*/
#ifndef F_CPU
#define F_CPU 10000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB =(1<<DDB5);
/* Replace with your application code */
while (1)
{
PORTB |=(1<<PORTB5);
_delay_ms(1000);
PORTB &= !(1<<PORTB5);
_delay_ms(1000);
}
return 0;
}
4.2 工具配置
Use Output window
。Title:Arduino UNO(随意填写) Command:D:\Software\Arduino\hardware\tools\avr\bin\avrdude.exe,这个路径为ArduinoIDE中avrdude.exe的路径,根据自己的路径填写。 Arguments:这里填写要注意串口号,我这里是COM7,根据自己板子识别填写正确的COM号。
-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:
-p <partno> Required. Specify AVR device.
-b <baudrate> Override RS-232 baud rate.
-B <bitclock> Specify JTAG/STK500v2 bit clock period (us).
-C <config-file> Specify location of configuration file.
-c <programmer> Specify programmer type.
-D Disable auto erase for flash memory
-i <delay> ISP Clock Delay [in microseconds]
-P <port> Specify connection port.
-F Override invalid signature check.
-e Perform a chip erase.
-O Perform RC oscillator calibration (see AVR053).
-U <memtype>:r|w|v:<filename>[: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 <exitspec>[,<exitspec>] List programmer exit specifications.
-x <extended_param> Pass <extended_param> to programmer.
-y Count # erase cycles in EEPROM.
-Y <number> Initialize 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.
4.3 编译和烧写程序
Arduino UNO
。试验现象
-END-
微信扫码关注该文公众号作者
戳这里提交新闻线索和高质量文章给我们。
来源: qq
点击查看作者最近其他文章