Microchip
直播中

杜云

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

C版本中的简单PIC12F509代码但不起作用

你好,请问你知道为什么我的PIC12F509的C代码(XC8)不工作吗?它所要做的是读取GP5上的方波电压输入,然后将GP4从高变为低,反之亦然,每秒GP5低。然而,GP4总是保持低位。你知道为什么吗?它建立成功但不工作

以上来自于百度翻译


      以下为原文

    Hello,
Please do you know why my C code (XC8) for PIC12F509 doesnt work?
All its supposed to do is read a square wave voltage input on GP5, and then change GP4 from high to low and vice versa, every second low-going of GP5.
However, GP4 is always just staying low. Do you kow why?
It builds successfully but doesn’t work
/*
* File: jitter.c
* Author:
*
* Created on 8 sept 2017, 23:55
*/

//this code jitters

//This uses PIC12F509
//MPLAB X IDE
//XC8 C compiler (free)

#define _XTAL_FREQ 4000000

#include
#include


//
#pragma config OSC = IntRC // Oscillator Selection bits (external RC oscillator)
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config CP = OFF // Code Protection bit (Code protection off)
#pragma config MCLRE = OFF // GP3/MCLR Pin Function Select bit (GP3/MCLR pin function is MCLR)

//I have not set the MCLR pin as an input because it will be noise susceptible.
//Therefore i set MCLR up as reset, but i will never use it as reset..but will
//simply tie the pin top Vdd on the PCB.

   
//Declare functions which set up the microcontroller
//void disable_interrupts(void); //How do this?
//void disable_pullups(void); //How do this?

// TRIS = 0x18;
   
//Declare variables
    uint8_t count;

void main(void) {
    GP0 = 0;
    GP1 = 0;
    GP2 = 0;
    GP4 = 0;
    GP5 = 0;
    OPTION = 0xD7;
    TRISGPIO = 0x20;
   
    GP4 = 0;
   
    //5 second delay
    for (count=1;count<=50;count++) {
    __delay_ms(100);
    }


    while(GP5 == 0) ;
    while(GP5 == 1) ;
    //STATUS LOW FIRST
    //When it gets to this point, the STATUS input has just gone low

    __delay_us(500);
    GP4 = 0; //FET OFF
   
    while(1){
    while(GP5 == 0) ; //See out the rest of low STATUS
    while(GP5 == 1) ; //See out the high STATUS
    while(GP5 == 0) ; //See out the low STATUS
    while(GP5 == 1) ; //See out the high STATUS
    //STATUS LOW SECOND
    __delay_us(500);
    GP4 = 1; //FET ON
    while(GP5 == 0) ; //See out the rest of low STATUS
    while(GP5 == 1) ; //See out the high STATUS
    while(GP5 == 0) ; //See out the low STATUS
    while(GP5 == 1) ; //See out the high STATUS
    __delay_us(500);
    GP4 = 0;
    }
   
   

    while(1){;}

    return;
}

回帖(2)

王焕树

2019-1-16 12:10:10
不要试图同时解决两个问题,你能简单地让GP4在没有GP5测试的情况下闪现吗?

以上来自于百度翻译


      以下为原文

    Don't try to solve two problems at once.
Can you simply get GP4 to flash without the GP5 tests?
 
举报

李涛

2019-1-16 12:15:28
选项=0xD7;假设哪些位被设置而不是一些随机数。

以上来自于百度翻译


      以下为原文

    OPTION = 0xD7;

Say what bits are set rather than some random number.
举报

更多回帖

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