eddiewwm 发表于 2020-4-28 18:57:05

LGT8F328 在 arduino 內使用 S檔案範例

本帖最后由 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();
}

microplc 发表于 2020-5-3 21:04:19

什么叫S档案?

eddiewwm 发表于 2020-5-6 12:14:18

microplc 发表于 2020-5-3 21:04
什么叫S档案?

簡單說,即是匯編源碼檔。

microplc 发表于 2020-5-17 09:18:18

敢问先生LGT8F328P有没有操作FLASH的库?

eddiewwm 发表于 2020-5-17 15:17:02

microplc 发表于 2020-5-17 09:18
敢问先生LGT8F328P有没有操作FLASH的库?

沒看到 LGT 有提供操作 FLASH 的庫。
在 LGT 交流群中有以下一個範例,你可參考看看是否用得著。
页: [1]
查看完整版本: LGT8F328 在 arduino 內使用 S檔案範例