本帖最后由 南来之风 于 2023-8-1 16:43 编辑
参考开发板用户手册:
Microchip MPLAB ® X IDE requires specific information to support devices and tools. This information is contained in versioned packs.
For the PIC16F17146 Curiosity Nano board, MPLAB ® X version 6.00 or later with device family pack “PIC16F1xxxx_DFP” version 1.10.174 or later and tool pack “nEDBG_TP” version 1.10.488 or later or newer is required. For more information on packs and how to upgrade them, refer to the MPLAB ® X IDE User’s guide - Work with Device Packs.
当前IDE版本为v6.0.5,满足要求:
连接开发板后,MPLAB X ide准确识别出开发板型号,并显示了板卡相关的资料:
第一步:点击新建项目:
第二步:选择Device型号,板载开发工具
第三步:选择编译器。如果没有XC8编译器供选择,可以通过连接https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers?utm_source=MCHP_Web&utm_medium=21IC_forum&utm_campaign=PIC16F17146&utm_term=21IC_Metrics&utm_content=PIC16F17146 下载安装
之后输入项目名称即可创建一个空白项目。接下来继续使用MCC来通过图形化配置工具自动化生成代码。
选择进入MCC:
本文**实现基本的串口收发功能:
进入MCC后,在左侧的“设备资源”栏找到UART,点击+号,把该模块添加到项目中。
根据开发板硬件资源,RB5, RB7属于EUART1,在MCC中做好配置。
勾选“Redirect Printf to UART”,这样就能愉快的使用printf来打印调试信息了!
之后点击Generate来生成代码:
在返回代码编辑区域前,要仔细检查代码生成有没有错误:
15:29:48.337 INFO: Fetching list of available libraries.
15:29:50.284 INFO: Download Complete: C:\Users\yshu\.mcc\mcc_libraries.xml
15:29:50.709 WARNING: Some MCC Classic GUIs may not display correctly in MPLAB X 6.05/MCC 5.2.x. The following link details options for dealing with this issue:
https://onlinedocs.microchip.com/pr/GUID-BD1BECBF-14DB-4FBB-82D3-A4219CF22F9F-en-US-1/index.html?GUID-67D73C1F-567E-4BDF-B437-3F3CB8251844
15:29:51.324 INFO: Start MCC
15:29:51.331 INFO: Core v5.4.14 loaded.
15:41:51.599 INFO: *****************************************************
15:41:51.599 INFO: Generation Results
15:41:51.599 INFO: *****************************************************
15:41:51.602 INFO: main.c Success. New file.
15:41:51.602 INFO: mcc_generated_files\system\clock.h Success. New file.
15:41:51.602 INFO: mcc_generated_files\system\config_bits.h Success. New file.
15:41:51.602 INFO: mcc_generated_files\system\interrupt.h Success. New file.
15:41:51.602 INFO: mcc_generated_files\system\pins.h Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\src\clock.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\src\config_bits.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\src\interrupt.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\src\pins.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\src\system.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\system\system.h Success. New file.
15:41:51.603 INFO: mcc_generated_files\uart\eusart1.h Success. New file.
15:41:51.603 INFO: mcc_generated_files\uart\src\eusart1.c Success. New file.
15:41:51.603 INFO: mcc_generated_files\uart\uart_drv_interface.h Success. New file.
15:41:51.603 INFO: mcc_generated_files\uart\uart_types.h Success. New file.
15:41:51.629 INFO: *****************************************************
15:41:51.630 INFO: Generation complete (total time: 688 milliseconds)
15:41:51.630 INFO: *****************************************************
15:41:51.630 INFO: Generation complete.
15:42:33.275 INFO: Stop MCC
15:42:33.289 INFO: Core v5.4.14 unloaded.
利用MPLABX提供的函数调用关系,可以看到EUART1硬件模块已经被初始化:
MCC自动代码生成工具,可以在任意时刻重复进入,增加或是减少相应的模块,比如我们再次进入MCC,增加一个延迟模块:
然后再次点击Generate:
15:47:30.229 INFO: Start MCC
15:47:30.233 INFO: Core v5.4.14 loaded.
15:48:14.101 INFO: Loaded configuration from file M:\Microchip\2023-08-01 PIC16F17146\SouthWind\HelloPIC.X\HelloPIC.mc3
15:49:00.731 INFO: *****************************************************
15:49:00.731 INFO: Generation Results
15:49:00.731 INFO: *****************************************************
15:49:00.732 INFO: main.c Success.
15:49:00.733 INFO: mcc_generated_files\docs\delay.dox Success. New file.
15:49:00.733 INFO: mcc_generated_files\system\clock.h Success.
15:49:00.733 INFO: mcc_generated_files\system\config_bits.h Success.
15:49:00.733 INFO: mcc_generated_files\system\interrupt.h Success.
15:49:00.733 INFO: mcc_generated_files\system\pins.h Success.
15:49:00.733 INFO: mcc_generated_files\system\src\clock.c Success.
15:49:00.733 INFO: mcc_generated_files\system\src\config_bits.c Success.
15:49:00.733 INFO: mcc_generated_files\system\src\interrupt.c Success.
15:49:00.733 INFO: mcc_generated_files\system\src\pins.c Success.
15:49:00.733 INFO: mcc_generated_files\system\src\system.c Success.
15:49:00.733 INFO: mcc_generated_files\system\system.h Success.
15:49:00.733 INFO: mcc_generated_files\timer\delay.h Success. New file.
15:49:00.734 INFO: mcc_generated_files\timer\src\delay.c Success. New file.
15:49:00.734 INFO: mcc_generated_files\uart\eusart1.h Success.
15:49:00.734 INFO: mcc_generated_files\uart\src\eusart1.c Success.
15:49:00.734 INFO: mcc_generated_files\uart\uart_drv_interface.h Success.
15:49:00.734 INFO: mcc_generated_files\uart\uart_types.h Success.
15:49:00.755 INFO: *****************************************************
15:49:00.755 INFO: Generation complete (total time: 469 milliseconds)
15:49:00.755 INFO: *****************************************************
15:49:00.755 INFO: Generation complete.
15:49:05.822 INFO: Stop MCC
15:49:05.831 INFO: Core v5.4.14 unloaded.
可以看到这次新增加的模块,自动生成的代码比如 delay.h和delay.c会显示“New file”.
接着回到main.c,来编写一个简单的串口打印的代码,并延迟1s后,再次打印。
int main(void)
{
SYSTEM_Initialize();
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
while(1)
{
printf("Hello PIC16F17146\r\n");
DELAY_milliseconds(1000);
}
}
编译遇到了一个错误:
mcc_generated_files/system/src/config_bits.c:54:: error: (1363) unknown configuration setting/register (DEBUG = OFF) used
mcc_generated_files/timer/src/delay.c:37:: error: (1098) conflicting declarations for variable "_DELAY_milliseconds" (main.c:63)
针对第一个错误,更新一下固件库:
针对第二个错误,在main.c中包含延迟的头文件:
#include "mcc_generated_files/timer/delay.h"
配置使用最新的固件库:
重新编译,问题解决!
CLEAN SUCCESSFUL (total time: 14ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'M:/Microchip/2023-08-01 PIC16F17146/SouthWind/HelloPIC.X'
make -f nbproject/Makefile-default.mk dist/default/production/HelloPIC.X.production.hex
make[2]: Entering directory 'M:/Microchip/2023-08-01 PIC16F17146/SouthWind/HelloPIC.X'
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/system/src/clock.p1 mcc_generated_files/system/src/clock.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/system/src/system.p1 mcc_generated_files/system/src/system.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/system/src/config_bits.p1 mcc_generated_files/system/src/config_bits.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/system/src/pins.p1 mcc_generated_files/system/src/pins.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/system/src/interrupt.p1 mcc_generated_files/system/src/interrupt.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/timer/src/delay.p1 mcc_generated_files/timer/src/delay.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/mcc_generated_files/uart/src/eusart1.p1 mcc_generated_files/uart/src/eusart1.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -c -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/main.p1 main.c
"D:\Program Files\Microchip\xc8\v2.41\bin\xc8-cc.exe" -mcpu=16F17146 -Wl,-Map=dist/default/production/HelloPIC.X.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="C:/Users/yshu/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.19.363/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/HelloPIC.X.production.elf build/default/production/mcc_generated_files/system/src/system.p1 build/default/production/mcc_generated_files/system/src/config_bits.p1 build/default/production/mcc_generated_files/system/src/clock.p1 build/default/production/mcc_generated_files/system/src/pins.p1 build/default/production/mcc_generated_files/system/src/interrupt.p1 build/default/production/mcc_generated_files/timer/src/delay.p1 build/default/production/mcc_generated_files/uart/src/eusart1.p1 build/default/production/main.p1
mcc_generated_files/system/src/interrupt.c:72:: warning: (520) function "_INT_ISR" is never called
mcc_generated_files/system/src/interrupt.c:81:: warning: (520) function "_INT_CallBack" is never called
mcc_generated_files/timer/src/delay.c:43:: warning: (520) function "_DELAY_microseconds" is never called
mcc_generated_files/uart/src/eusart1.c:115:: warning: (520) function "_EUSART1_Deinitialize" is never called
mcc_generated_files/uart/src/eusart1.c:124:: warning: (2053) function "_EUSART1_Enable" is never called
mcc_generated_files/uart/src/eusart1.c:130:: warning: (2053) function "_EUSART1_Disable" is never called
mcc_generated_files/uart/src/eusart1.c:136:: warning: (2053) function "_EUSART1_TransmitEnable" is never called
mcc_generated_files/uart/src/eusart1.c:141:: warning: (2053) function "_EUSART1_TransmitDisable" is never called
mcc_generated_files/uart/src/eusart1.c:146:: warning: (2053) function "_EUSART1_ReceiveEnable" is never called
mcc_generated_files/uart/src/eusart1.c:151:: warning: (2053) function "_EUSART1_ReceiveDisable" is never called
mcc_generated_files/uart/src/eusart1.c:156:: warning: (2053) function "_EUSART1_SendBreakControlEnable" is never called
mcc_generated_files/uart/src/eusart1.c:161:: warning: (2053) function "_EUSART1_SendBreakControlDisable" is never called
mcc_generated_files/uart/src/eusart1.c:166:: warning: (2053) function "_EUSART1_AutoBaudSet" is never called
mcc_generated_files/uart/src/eusart1.c:178:: warning: (2053) function "_EUSART1_AutoBaudQuery" is never called
mcc_generated_files/uart/src/eusart1.c:183:: warning: (2053) function "_EUSART1_IsAutoBaudDetectOverflow" is never called
mcc_generated_files/uart/src/eusart1.c:188:: warning: (2053) function "_EUSART1_AutoBaudDetectOverflowReset" is never called
mcc_generated_files/uart/src/eusart1.c:193:: warning: (520) function "_EUSART1_IsRxReady" is never called
mcc_generated_files/uart/src/eusart1.c:203:: warning: (520) function "_EUSART1_IsTxDone" is never called
mcc_generated_files/uart/src/eusart1.c:208:: warning: (520) function "_EUSART1_ErrorGet" is never called
mcc_generated_files/uart/src/eusart1.c:213:: warning: (520) function "_EUSART1_Read" is never called
mcc_generated_files/uart/src/eusart1.c:240:: warning: (520) function "_getch" is never called
Memory Summary:
Program space used 21Bh ( 539) of 4000h words ( 3.3%)
Data space used 4Dh ( 77) of 800h bytes ( 3.8%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Configuration bits used 5h ( 5) of 5h words (100.0%)
ID Location space used 4h ( 4) of 4h bytes (100.0%)
make[2]: Leaving directory 'M:/Microchip/2023-08-01 PIC16F17146/SouthWind/HelloPIC.X'
make[1]: Leaving directory 'M:/Microchip/2023-08-01 PIC16F17146/SouthWind/HelloPIC.X'
BUILD SUCCESSFUL (total time: 20s)
Loading code from M:/Microchip/2023-08-01 PIC16F17146/SouthWind/HelloPIC.X/dist/default/production/HelloPIC.X.production.hex...
Program loaded with pack,PIC16F1xxxx_DFP,1.19.363,Microchip
Loading completed
烧录的时候遇到了错误:
八月 01 2023--- 16:35:03
Loading script file C:\Users\yshu\.mchp_packs\Microchip\PIC16F1xxxx_DFP\1.19.363\scripts\pic16f17146\nedbg_pic16f17146.py
javax.script.ScriptException: ImportError: cannot import name VoltageException in C:\Users\yshu\.mchp_packs\Microchip\PIC16F1xxxx_DFP\1.19.363\scripts\pic16f17146\nedbg_pic16f17146.py at line number 13
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:203)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:42)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:47)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
at com.microchip.mplab.libs.scripting.runner.BasicScriptRunner$LoadModuleCall.call(BasicScriptRunner.java:788)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Caused by: Traceback (most recent call last):
File "C:\Users\yshu\.mchp_packs\Microchip\PIC16F1xxxx_DFP\1.19.363\scripts\pic16f17146\nedbg_pic16f17146.py", line 13, in <module>
from common.scriptinginterface import VoltageException
ImportError: cannot import name VoltageException
at org.python.core.Py.ImportError(Py.java:328)
at org.python.core.imp.importFromAs(imp.java:1168)
at org.python.core.imp.importFrom(imp.java:1132)
at org.python.pycode._pyx6.f$0(C:\Users\yshu\.mchp_packs\Microchip\PIC16F1xxxx_DFP\1.19.363\scripts\pic16f17146\nedbg_pic16f17146.py:509)
at org.python.pycode._pyx6.call_function(C:\Users\yshu\.mchp_packs\Microchip\PIC16F1xxxx_DFP\1.19.363\scripts\pic16f17146\nedbg_pic16f17146.py)
at org.python.core.PyTableCode.call(PyTableCode.java:167)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1386)
at org.python.core.__builtin__.eval(__builtin__.java:497)
at org.python.core.__builtin__.eval(__builtin__.java:501)
at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
... 7 more
In addition to the stack trace above, a log of the error was created at M:\Microchip\2023-08-01 PIC16F17146\SouthWind\HelloPIC.X\debug\default\queuelogs\debugtool
IDE烧录虽然失败,但是还有另外一种方法就是拖拽HEX文件到虚拟U盘:
可以看到串口打印出来我们printf输出的内容,间隔1s打印一次!
动态图:
|