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.