PIC16F18326时程序不能正常运行

[复制链接]
526|12
手机看帖
扫描二维码
随时随地手机跟帖
llljh|  楼主 | 2021-5-5 19:34 | 显示全部楼层 |阅读模式
PIC16F18326时程序不能正常运行

使用特权

评论回复
gongche| | 2021-5-5 19:35 | 显示全部楼层
什么意思?不是很明白你说的什么,能再解释一下这个现象吗

使用特权

评论回复
llljh|  楼主 | 2021-5-5 19:37 | 显示全部楼层
想在PIC16F18326中写一个简单的IO控制测试程序,编译和烧写都正常,但是用万能表检测IO电平时无论怎么写代码都不能出正常的效果

使用特权

评论回复
gongche| | 2021-5-5 19:39 | 显示全部楼层
还有什么现象?能再详细描述下吗?

使用特权

评论回复
llljh|  楼主 | 2021-5-5 19:40 | 显示全部楼层
同样的代码在PIC16f1829中正常运行

使用特权

评论回复
chenho| | 2021-5-5 19:42 | 显示全部楼层
一模一样?

使用特权

评论回复
llljh|  楼主 | 2021-5-5 19:45 | 显示全部楼层
除了一些配置位不同

使用特权

评论回复
gongche| | 2021-5-5 19:47 | 显示全部楼层
楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

使用特权

评论回复
llljh|  楼主 | 2021-5-5 19:49 | 显示全部楼层

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

// PIC16F18326 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FEXTOSC = XT     // FEXTOSC External Oscillator mode Selection bits (XT (crystal oscillator) from 100 kHz to 4 MHz)
#pragma config RSTOSC = HFINT1  // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; I/O or oscillator function on OSC2)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config MCLRE = ON       // Master Clear Enable bit (MCLR/VPP pin function is MCLR; Weak pull-up enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config WDTE = ON        // Watchdog Timer Enable bits (WDT enabled, SWDTEN is ignored)
#pragma config LPBOREN = OFF    // Low-power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit ignored)
#pragma config BORV = LOW       // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V)
#pragma config PPS1WAY = ON     // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a Reset)
#pragma config DEBUG = OFF      // Debugger enable bit (Background debugger disabled)

// CONFIG3
#pragma config WRT = OFF        // User NVM self-write protection bits (Write protection off)
#pragma config LVP = ON         // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.)

// CONFIG4
#pragma config CP = OFF         // User NVM Program Memory Code Protection bit (User NVM code protection disabled)
#pragma config CPD = OFF        // Data NVM Memory Code Protection bit (Data NVM code protection disabled)

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

#include <xc.h>
/*
*
*/
int main(int argc, char** argv) {

    TRISCbits.TRISC2 = 0;
    LATC2 = 1;

    while(1){
    }

    return (EXIT_SUCCESS);
}


PS:其他配置位也尝试过了
// CONFIG1
#pragma config FEXTOSC = HS     // FEXTOSC External Oscillator mode Selection bits (HS (crystal oscillator) above 4 MHz)
#pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (HFINTOSC with 2x PLL (32MHz))
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; I/O or oscillator function on OSC2)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config MCLRE = OFF      // Master Clear Enable bit (MCLR/VPP pin function is digital input; MCLR internally disabled; Weak pull-up under control of port pin's WPU control bit.)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config WDTE = OFF       // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored)
#pragma config LPBOREN = OFF    // Low-power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit ignored)
#pragma config BORV = LOW       // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V)
#pragma config PPS1WAY = ON     // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a Reset)
#pragma config DEBUG = ON      // Debugger enable bit (Background debugger disabled)

// CONFIG3
#pragma config WRT = OFF        // User NVM self-write protection bits (Write protection off)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (High Voltage on MCLR/VPP must be used for programming.)

// CONFIG4
#pragma config CP = OFF          // User NVM Program Memory Code Protection bit (User NVM code protection enabled)
#pragma config CPD = OFF         // Data NVM Memory Code Protection bit (Data NVM code protection enabled)

使用特权

评论回复
huwr| | 2021-5-5 19:52 | 显示全部楼层
这个跟你的外围电路应该也有关系吧,用的内部时钟还是外部的?

使用特权

评论回复
huwr| | 2021-5-5 19:53 | 显示全部楼层
这个跟你的电路应该也有关系吧,用的内部时钟还是外部的?

使用特权

评论回复
llljh|  楼主 | 2021-5-5 20:02 | 显示全部楼层
搞定了,呵呵,犯了低级错误……

使用特权

评论回复
hjl2832| | 2021-5-7 08:46 | 显示全部楼层
这种问题,如果用MCC配置初始化函数基本不会存在。何必浪费时间做不必要的事情。看你的定义位配置,你把时钟定义成了外部晶振,实际上你的板子上是没有晶振的吧,呵呵。

使用特权

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

本版积分规则

855

主题

11301

帖子

6

粉丝