|
51單片機的編譯環(huán)境主要使用Keil,但是Keil是商業(yè)軟件,涉及到付費或者%的問題,由此產(chǎn)生了尋找開源解決方案的想法,經(jīng)過多方找尋和實驗驗證,我使用的是sdcc作為編譯工具,使用stcflash作為燒寫工具(在這里感謝開源大神的無私奉獻)。
sdcc的官網(wǎng)是:sdcc.sourceforge.net
這里不對sdcc做過多介紹,感興趣的可以自己閱讀(百度有許多介紹文檔),其下載地址為:sourceforge.net/projects/sdcc/files
也可直接安裝Linux發(fā)行版編譯發(fā)布的軟件包,我使用的是debian系統(tǒng),可直接使用apt install sdcc命令進行安裝,安裝完成后可直接使用sdcc命令調(diào)用sdcc工具。
燒寫工具stcflash位于:github/laborer/stcflash
可通過git clone github/laborer/stcflash.git命令下載,具體的功能也不在這里做過多介紹,感興趣的可以自己閱讀其自帶的README.md文件(百度有許多介紹文檔)。這里需要注意的是該工具需要python2.7以上的python版本才能正常運行,還需要安裝python-serial軟件包(可通過apt install python-serial命令安裝)才能正常下載,另一個就是要注意其支持的芯片型號(可在其readme文件中獲得其能支持的所有型號),實測使用STC89C52RC芯片可以正常燒寫。最初使用STC89C516芯片死活燒寫不成功,但是所有的資料都顯示這兩款芯片除了STC89C516更強大一點外其它的都一樣,差點被搞得懷疑人生,后來不死心,買了一塊STC89C52RC回來,一把成功?磥磉@兩款芯片可能還是有差別的,所以還是要注意該工具列出的適配過的芯片,一定要匹配。
鑒于使用sdcc需要使用Makefile才方便進行多文件編譯,我自己實現(xiàn)了一個編譯多文件的Makefile編譯工程。該工程支持多文件構(gòu)成的多模塊源碼,多可執(zhí)行文件的編譯。原理為先進行模塊編譯,最終將所有模塊鏈接成可執(zhí)行文件。方便支持模塊拓展,支持多人合作開發(fā)等。其工程位于:github/jiangxianxu/sdcc-multi-file-compile-frame
可通過git clone :github/jiangxianxu/sdcc-multi-file-compile-frame.git命令下載,具體使用方法和特性詳見README文檔。
編譯及下載演示(stcflash.py的路徑已經(jīng)寫到PATH環(huán)境變量中):
jiangxianxu@debian:/workspace/c51/sdcc-multi-file-compile-frame$ make
== Build-object module-delay
DEP delay_msec.rel
DEP delay_sec.rel
CC delay_sec.rel
CC delay_msec.rel
GEN delay.lib
== Build-object module-isr
DEP isr.rel
CC isr.rel
GEN isr.lib
== Build-object app-timer
DEP main.rel
CC main.rel
GEN main.ihx for app-timer
GEN app-timer.hex
packihx: read 17 lines, wrote 21: OK.
GEN app-timer.bin
== Build-object app-loop
DEP main_delay.rel
DEP main.rel
CC main.rel
CC main_delay.rel
GEN main.ihx for app-loop
GEN app-loop.hex
packihx: read 15 lines, wrote 17: OK.
GEN app-loop.bin
jiangxianxu@debian:/workspace/c51/sdcc-multi-file-compile-frame$
jiangxianxu@debian:/workspace/c51/sdcc-multi-file-compile-frame$
jiangxianxu@debian:/workspace/c51/sdcc-multi-file-compile-frame$ stcflash.py build/timer.bin
Connect to /dev/ttyUSB0 at baudrate 2400
Detecting target... done
FOSC: 12.058MHz
Model: STC89C52RC (ver6.6C)
ROM: 8KB
[X] Reset stops watchdog
[X] Internal XRAM
[X] Normal ALE pin
[X] Full gain oscillator
[X] Not erase data EEPROM
[X] Download regardless of P1
[X] 12T mode
Baudrate: 38400
Erasing target... done
Size of the binary: 243
Programming: #################### done
Setting options... done
jiangxianxu@debian:/workspace/c51/sdcc-multi-file-compile-frame$
|
評分
-
查看全部評分
|