我正在为一个项目使用PIC12F675,除一件事情外,其他所有东西都工作正常。GP4不能用作数字IO。我已经看了很多配置和代码,但是找不到任何东西。
配置:
#pragma config FOSC = INTRCCLK
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = OFF
#pragma config BOREN = ON
#pragma config CP = OFF
#pragma config CPD = OFF
码:
#include <xc.h>
#include <math.h>
#include "config.h"
#define _XTAL_FREQ 4000000
void delay(unsigned int freq){
for(int i = 0; i < (int)freq; i++){
__delay_ms(1);
}
}
void dClock(unsigned int freq){
GPIO1 = 1;
delay(freq);
GPIO1 = 0;
delay(freq);
}
void InitADC(){
ANSEL = 0x11;
ADCON0 = 0b10000001;
CMCON = 0x7;
VRCON = 0;
}
unsigned int GetADCValue(){
ADCON0 = 0b10000011;
while(GO_nDONE);
return (ADRESH << 8) + ADRESL;
}
void main(void) {
TRISIO0 = 1; //analog input
TRISIO1 = 0; //output
TRISIO2 = 0; //indication
TRISIO3 = 1; //mode
TRISIO4 = 0; //halt
TRISIO5 = 1; //pulse_button
char pressed = 0;
GPIO1 = 0;
InitADC();
while(1){
if(GPIO4 == 0){
if(GPIO3 == 0){
GPIO2 = 1;
unsigned int freq = GetADCValue();
dClock(freq);
}
else{
GPIO2 = 0;
if(GPIO5 == 1 && pressed == 0){
GPIO1 = 1;
__delay_ms(50);
GPIO1 = 0;
pressed = 1;
}
else if(GPIO5 == 0 && pressed == 1){
pressed = 0;
}
}
}
}
return;
}
@brhans是的,我现在注意到了!INTRCCLK使微控制器使用其内部时钟,并将其连接到GP4。但是,INTRCIO所做的相同,只是将GP4配置为用作IO。谢谢您通知我!
—
Ali Abo Shady
#pragma config FOSC = INTRCCLK
告诉PIC在GP4上输出时钟吗?FOSC
您应该使用其他选项吗?