Microchip
直播中

李晓莉

7年用户 158经验值
私信 关注
[问答]

XC8循环问题

长时间汇编程序。现在在CIC PIC12F615 XC8中进行一次PIC和模拟器中的while循环循环,然后在第二个循环的末尾通过跳转到主()来结束,并从头开始。有人知道为什么吗?杰夫

以上来自于百度翻译


      以下为原文

    Long time assembler programmer. Now having a go at C.
PIC12F615 XC8

// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config IOSCFS = 4MHZ // Internal Oscillator Frequency Select (4 MHz)
#pragma config BOREN = OFF // Brown-out Reset Selection bits (BOR disabled)

//*******************************************************************************

#define green_led_on GP2 = 1
#define green_led_off GP2 = 0

#define _XTAL_FREQ 4000000

//*******************************************************************************

#include
#include
#include
#include

///*******************************************************************************
//*******************************************************************************

void main(void) {
     di(); /* disable all interrupts */

     // Wait long enough for PICKIT3 to initialise when debugging

     __delay_ms(200);

     // I/O initialisation.

     GPIO = 0;
     ANSEL = 0b00001000;
     TRISIO = 0b00011000;

     // Comparator

     // CMCON0
     CMON = 0; // Disable
     CMOE = 0; // COUT internal
     CMPOL = 0; // Output not inverted
     CMR = 1; // + connects to Vref
     CMCH = 1; // - Input on GP4

     // CMCON1
     CMHYS = 1; // Hysteresis enabled

     // Comparator Voltage Reference

     // VRCON
     CMVREN = 0; // Disable
     VRR = 0; // High range
     FVREN = 0; // 0.6V Disabled

     // OPTION_REG - Watchdog Timer
     PSA = 1;
     PS2 = 1;
     PS1 = 1;
     PS0 = 1;
   
     //**************************************

     while (true) {
        green_led_on;
        __delay_ms(500);
        green_led_off;
        __delay_ms(500);
        NOP();
     }
} // main



Both in a pic and in the simulator the while loop loops correctly once then terminates at the end of the second loop by jumping to main() and starting all over. Does anyone have an idea why?
Geoff

回帖(2)

张丽

2019-3-29 10:47:01
监视器定时器启用。

以上来自于百度翻译


      以下为原文

    The watchdog timer is enabled.
举报

陈存楼

2019-3-29 11:03:28
啊!!!!谢谢

以上来自于百度翻译


      以下为原文

    Duh!!! Thanks
举报

更多回帖

发帖
×
20
完善资料,
赚取积分