打印

CuriosityNano测评体验

[复制链接]
939|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 电子极客迷 于 2020-11-8 14:59 编辑

首先感谢Microchip给我这次体验的机会,手上一直没有pic系列的开发板。之前也只是用过pic16系列的做项目。话不多说开始测试,先来一个点灯程序。哈哈哈哈!

实物图如下:(我已经焊接好排针了)



开始用MPLAB X IDE创建工程

选择芯片型号(开发板选用PIC18F57Q43)





选择调试工具(开发板板载了调试器,IDE会识别到调试器,选择如下这个)
选择编译器(XC8,这里老版本不支持这个芯片,我特意安装了最新版的XC8)


设置工程目录,工程名称然后点击完成

新建工程完成后页面如下


新建一个main.c文件,新工程是没有文件的,我这里是打算直接采用寄存器开发,没有用官方的MCC代码配置工具,新建的文件只有main函数。

直接用X IDE里面的配置字工具进行配置配置字节的位,配置时钟直接在这里配置,我们开发板没有外置时钟。所以关闭外部振荡器,选择内置的64MHZ时钟做为系统时钟源。选择好后点击创建就会生成代码。

点击创建后可以到out输出选项下看到生成的配置字代码,将其复制到工程中。
完成以上步骤后,开始点灯。写点灯代码。首先打开原理图,查看我们LED灯使用的io口是RF3,那么需要先对RF3进行配置输出模式。


开始编译代码,点击这个锤子图标,可以看到编译成功,无错误。S我们下载进去,可以看到输出信息显示编程完成,然后看现象。



小灯成功点亮,然后我们测试让小灯闪烁。加入延时。


小灯开始闪烁。点灯测试完成,下面测试一下串口通讯。

源码:

// PIC18F57Q43 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FEXTOSC = OFF    // External Oscillator Selection (Oscillator not enabled)
#pragma config RSTOSC = HFINTOSC_64MHZ// Reset Oscillator Selection (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1)

// CONFIG2
#pragma config CLKOUTEN = OFF   // Clock out Enable bit (CLKOUT function is disabled)
#pragma config PR1WAY = ON      // PRLOCKED One-Way Set Enable bit (PRLOCKED bit can be cleared and set only once)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)

// CONFIG3
#pragma config MCLRE = EXTMCLR  // MCLR Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR )
#pragma config PWRTS = PWRT_OFF // Power-up timer selection bits (PWRT is disabled)
#pragma config MVECEN = ON      // Multi-vector enable bit (Multi-vector enabled, Vector table used for interrupts)
#pragma config IVT1WAY = ON     // IVTLOCK bit One-way set enable bit (IVTLOCKED bit can be cleared and set only once)
#pragma config LPBOREN = OFF    // Low Power BOR Enable bit (Low-Power BOR disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled , SBOREN bit is ignored)

// CONFIG4
#pragma config BORV = VBOR_1P9  // Brown-out Reset Voltage Selection bits (Brown-out Reset Voltage (VBOR) set to 1.9V)
#pragma config ZCD = OFF        // ZCD Disable bit (ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
#pragma config PPS1WAY = ON     // PPSLOCK bit One-Way Set Enable bit (PPSLOCKED bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)

// CONFIG5
#pragma config WDTCPS = WDTCPS_31// WDT Period selection bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = ON        // WDT operating mode (WDT enabled regardless of sleep; SWDTEN is ignored)

// CONFIG6
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC      // WDT input clock selector (Software Control)

// CONFIG7
#pragma config BBSIZE = BBSIZE_512// Boot Block Size selection bits (Boot Block size is 512 words)
#pragma config BBEN = OFF       // Boot Block enable bit (Boot block disabled)
#pragma config SAFEN = OFF      // Storage Area Flash enable bit (SAF disabled)
#pragma config DEBUG = OFF      // Background Debugger (Background Debugger disabled)

// CONFIG8
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block not Write protected)
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers not Write protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not Write protected)
#pragma config WRTSAF = OFF     // SAF Write protection bit (SAF not Write Protected)
#pragma config WRTAPP = OFF     // Application Block write protection bit (Application Block not write protected)

// CONFIG10
#pragma config CP = OFF         // PFM and Data EEPROM Code Protection bit (PFM and Data EEPROM code protection disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>


#include <stdio.h>
#include <stdlib.h>

/*
*
*/
int main(int argc, char** argv) {
   ANSELFbits.ANSELF3 = 0x0; // 设置RF3为数字io
   TRISFbits.TRISF3=0;//设置为输出RF3
   PORTFbits.RF3=0; //输出低电平。
   while(1)
    {
        for(long i=0;i<100000;i++)//延时
         _delay(64);//延时64个指令周期
        PORTFbits.RF3^=1;
    }
    return (EXIT_SUCCESS);
}







700585fa791b3236d2.png (56.15 KB )

700585fa791b3236d2.png

LED_DEMO.X.zip

126.82 KB

使用特权

评论回复
沙发
捉虫天师| | 2020-11-8 16:19 | 只看该作者
点灯,给力。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

17

帖子

0

粉丝