您好,您知道PIC12F509的代码为什么不能编译吗?它是用MPLAB X IDE编写的,使用XC8C编译器编写的。所有的代码都是在端口GP4上选择一个低到高的过渡,然后等待3毫秒,然后取端口GP2高。我现在被建筑错误弄得眼花缭乱。
以上来自于百度翻译
以下为原文
Hello,
Do you know why this code for PIC12F509 will not compile?
It is written in MPLAB X IDE and using XC8 C compiler.
All the code does is pick out a low to high transi
tion on PORT GP4 and then wait 3 ms, then take PORT GP2 high.
I am festooned with build errors at the moment.
/*
* File: zapper.c
* Author:
*
* Created on 03 June 2017, 23:55
*/
//This code turns the product ON at the mains peak voltage
//It does this by using the zero crossing detector input.
//This uses PIC12F509
//MPLAB X IDE
//XC8 C compiler (free)
#define _XTAL_FREQ 4000000
#include
#include
#pragma config OSC = ExtRC // 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 = ON // 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.
//Define output
#define FETS LATBbits.RB2;
//Define input
#define zero_x PORTBbits.RB4;
//Define actions
#define ON LATBbits.RB2 = 1 /*Turn ON FETs*/
//Declare functions which set up the microcontroller
void disable_interrupts(void); //How do this?
void disable_pullups(void); //How do this?
void setup_ports(void);
void setup_ports(void) {
TRISB = 0b00011000;
return;
}
//Declare variables
uint8_t count;
void main(void) {
setup_ports();
//10 second delay
for (count=1;count<=100;count++) {
__delayms(100);
}
here:
if {zero_x = 1} {goto here;}
here1:
if {zero_x = 0} {goto here1;}
//When it gets to this point, the zero crossing input has just gone high
__delayms(3); //delay to get to the mains peak
ON; //Turn ON FETs...at the mains peak
while(1){;}
return ();
}