Settings
|
Sign in
|
Sign up
Bar
Post
Home
>
Bar AVR单片机
>
View post
Reply the post
|
View author only
There are currently
23
posts.
1
2
3
Next
Last
[使用方法]ATtiny13A芯片的使用方法
Floor 1
巨大八爪鱼
7/18/15 17:46
首先,祝贺我成功地点亮了LED灯!
Floor 2
巨大八爪鱼
7/18/15 17:51
电路:
第1脚接正常的AVR RESET电路,和ATMega16一样,电容10μF。
第3脚通过一个200欧姆的电阻接发光二极管的正极。
然后按照ATMega16的电路图接上ISP下载口。
Floor 3
巨大八爪鱼
7/18/15 17:55
如图,插好USBASP。图中的两个HC595和一个8x8LED不用管,我以前就焊好了。
Floor 4
巨大八爪鱼
7/18/15 17:58
然后编写一个C文件,文件名tiny.c:
#include <avr/io.h>
#include <avr/eeprom.h>
int main()
{
DDRB |= _BV(4); //把PB4设置为输出
PORTB |= _BV(4); //把PB4设置为高电平
eeprom_busy_wait();
eeprom_write_byte(0x00, 0xa5);
eeprom_busy_wait();
eeprom_write_byte(0x01, 0xb6);
eeprom_busy_wait();
eeprom_write_byte(0x02, 0xc7);
eeprom_busy_wait();
eeprom_write_byte(0x03, PORTB);
eeprom_busy_wait();
eeprom_write_byte(0x04, DDRB);
eeprom_busy_wait();
eeprom_write_byte(0x05, PINB);
eeprom_busy_wait();
while (1);
}
为了方便起见,笔者是在Linux下用的avrdude+gccavr进行编译的程序。在Windows平台上和WinAVR等价。用ICC AVR的话就得把头文件改了,还要把_BV改成BIT。
Floor 5
巨大八爪鱼
7/18/15 17:58
Makefile:
# make
tiny.hex: tiny.c
avr-gcc -mmcu=attiny13 -Wall -Os tiny.c -o tiny.o
avr-objcopy -j .text -j .data -O ihex tiny.o tiny.hex
# make run
run: tiny.hex
sudo avrdude -p t13 -c usbasp -e -U flash:w:tiny.hex
Floor 6
巨大八爪鱼
7/18/15 17:59
在终端中执行make run(也可以先make后make run),把程序下载到芯片中。程序的运行结果是:LED亮了!
Floor 7
巨大八爪鱼
7/18/15 18:02
同时,程序运行后获得的EEPROM内容如下:
这说明,
PORTB = 0x10 (00010000)
DDRB = 0X10 (00010000)
PINB = 0x18 (00011000)
Floor 8
巨大八爪鱼
7/18/15 18:04
PORTB = 0x10 (00010000)
左边第一位是PB7(当然ATtiny13根本没这个端口)
左边第4位就是PB4,PORTB中只有这一位为1
右边最后一位是PB0
Floor 9
巨大八爪鱼
7/18/15 18:07
现在删掉EEPROM部分的代码。
#include <avr/io.h>
int main()
{
DDRB |= _BV(4); //把PB4设置为输出
PORTB |= _BV(4); //把PB4设置为高电平
while (1);
}
程序运行结果:LED亮
#include <avr/io.h>
int main()
{
DDRB |= _BV(4); //把PB4设置为输出
PORTB &= ~_BV(4); //把PB4设置为低电平
while (1);
}
程序运行结果:LED灭
Floor 10
巨大八爪鱼
7/18/15 18:09
令我奇怪的是,之前不能运行的以下程序:
#include <avr/io.h>
int main()
{
DDRB = 0xff;
PORTB = 0xff;
while (1) {
PORTB = 0xff;
}
}
现在居然又能正常运行了。。。我靠!所以这个原因暂时还没找到。。。
1
2
3
Next
Last
Content converter:
No conversion
Mainland
Taiwan
Hong Kong
Singapore
Reply the post
Content:
User:
You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [
Desktop
]
Except where otherwise noted, content on
this site
is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported license
.