|
本帖最后由 eddiewwm 于 2020-4-28 19:11 编辑
LGT8F328 在 arduino 內使用 S檔案的做法:
1) 先把 S檔案寫好,在此以 blink.S 作範例: - #define __SFR_OFFSET 0
- #include <avr/io.h>
- .section .text
- .global setIO ; << This exports the function name
- .global blink ; << This exports the function name
- setIO: ; << This is the name of the function
- ldi r18, 0x20 ; loading 0x20 = 00100000 into register r18
- out DDRB, r18 ; making pin 5 of port B an output
- ret;
-
- blink: ldi r18, 0x00 ; loading 0x20 = 00100000 into register r18
- out PORTB, r18 ; pin 5 of port B output Low
- ldi r18, 0x20 ; loading 0x20 = 00100000 into register r18
- out PORTB, r18 ; pin 5 of port B output High
- ret;
-
复制代码
2) 在 arduino ino檔內宣告相關的副程序並呼叫使用 - extern "C" void setIO(); // << Add the "C" to tell it not to munge the name
- extern "C" void blink(); // << Add the "C" to tell it not to munge the name
- void setup() {
- // put your setup code here, to run once:
- setIO();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- blink();
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|