PIC18单片机配置位设置

博客提及了单片机,但内容仅给出一张图,未包含更多信息技术相关关键信息。

如图:

PIC18单片机配置位设置

PIC16F193X单片机配置位是用于设置芯片的一些关键特性和启动选项的特殊寄存器,配置位通常在代码的开头部分进行设置,并且需要特定的编译器指令来完成。以下是一般的设置步骤和示例代码: ### 1. 确定配置位的功能 PIC16F193X单片机配置位有多个,每个配置位都有不同的功能,例如看门狗定时器(WDT)、振荡器选择、代码保护等。需要根据实际应用需求确定每个配置位的值。 ### 2. 使用编译器指令设置配置位 在MPLAB X IDE中使用XC8编译器为例,通过`__CONFIG`指令来设置配置位。以下是一个示例代码: ```c // PIC16F193X Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) #include <xc.h> void main(void) { // 主程序代码 while(1) { // 循环执行的代码 } return; } ``` ### 代码解释 - `#pragma config`:这是编译器指令,用于设置配置位。 - `FOSC = INTOSC`:选择内部振荡器。 - `WDTE = OFF`:禁用看门狗定时器。 - 其他配置位的设置根据实际需求进行调整。 ### 3. 编译和下载代码 设置好配置位后,编译代码并下载到PIC16F193X单片机中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值