最近在玩PIC12F629,哎,被这玩意儿的寄存器弄得实在郁闷!
我的GPIO0、GPIO1、GPIO2都能正常使用,就是GPIO4、GPIO5死活不能用!
初始化我检查了N遍,结果还是一样!
__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTEN & INTIO);
/**************************************************************************
* 函数原型: void ParaInit(void)
* 功 能: 参数初始化
**************************************************************************/
void ParaInit(void){
TMR0 = TMR0_Value;
time_10mS = vTime_10mS;
time_100mS =vTime_100mS;
time_1S = vTime_1S;
time_1Min = vTime_1Min;
time_1Hour= vTime_1Hour;
time_10Hour = vTime_10Hour;
}
/**************************************************************************
* 函数原型: void InitSys(void)
* 功 能: 系统初始化
**************************************************************************/
void InitSys(void){
INTCON = 0xd0; //使能GP2/INT 外部中断,使能TMR0 溢出中断
OPTION = 0x8f;
CMCON = 0x07;
WPU = 0x00;
TRISIO = 0x00;
GPIO = 0xff;
T1CON = 0x08;
TMR1IE = 1; //允许Timer1中断
ParaInit();
}
/**************************************************************************
* 函数原型: void main(void)
* 功 能: 主程序
**************************************************************************/
void main(void){
InitSys();
while(1){
CLRWDT();
GPIO=0xff;
Delay_mS(100);
GPIO=0x00;
Delay_mS(100);
// CommandDeal();
}
}
就是上面这样直接置1或0,再延时也是毫无用处。
搞了2、3天了,还是一样!
期待大虾们的回复!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
(原文件名:PIC12F629.jpg)
(原文件名:PIC16F29-1.jpg)
你设置的配置的参数是???
#include <pic12f6x.h>
#define uchar unsigned char
#define uint unsigned int
#define UV GPIO0
#define L1 GPIO1
#define REM GPIO2
#define RET GPIO3
#define FAN GPIO4
#define L2 GPIO5
#define Com_Addr 0x00
#define TMR0_Value 0x00 //195*256/100000=0.05s
#define vTime_10mS 40//#define vTime_1mS 10
#define vTime_100mS 10
#define vTime_1S 10
#define vTime_1Min 60
#define vTime_1Hour 60
#define vTime_10Hour 10
uint RCV_Command[2]; //接收到的命令字
uchar time_10mS;
uchar time_100mS;
uchar time_1S;
uchar time_1Min;
uchar time_1Hour;
uchar time_10Hour;
bit RCV_End_Flag; //接收结束标志
bit Error_Flag; //接收错误标志
__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTEN & INTIO);
/**************************************************************************
* 函数原型: void delay(uint time)
* 功 能: 延时n mS
**************************************************************************/
void Delay_mS(uint time){
uint i;
for(;time > 0;time--){
CLRWDT();
i=196;
while(i--);
}
}
/**************************************************************************
* 函数原型: void DATA_WRITE(uchar ADDR, uchar DATA)
* 功 能: 写EEPROM
**************************************************************************/
void DATA_WRITE(uchar ADDR, uchar DATA){
WREN = 1;
EEADR = ADDR;
EEDATA = DATA;
EECON2 = 0x55;
EECON2 = 0xaa;
WR = 1;
Delay_mS(10);
}
/**************************************************************************
* 函数原型: uchar DATA_READ(uchar ADDR)
* 功 能: 读EEPROM
**************************************************************************/
/*
uchar DATA_READ(uchar ADDR){
EEADR = ADDR;
RD = 1;
DelayXms(10);
return(EEDATA);
}
/**************************************************************************
* 函数原型: void CommandDeal(void)
* 功 能: 遥控处理
**************************************************************************/
void CommandDeal(void){
RCV_Command[0] &= 0x0FFF;
RCV_Command[1] &= 0x0FFF;
if((RCV_End_Flag == 1)&&(RCV_Command[0] == RCV_Command[1])){
UV = !UV;
RCV_End_Flag = 0;
switch(RCV_Command[0]){
case 0x8A0: //电源键
break;
case 0x890: //时间设置键
break;
case 0x888: //时间调节,向上键
break;
case 0x884: //时间调节,向下键
break;
case 0x860: //风力调节键
break;
case 0x850: //定时设置键
break;
case 0x848: //显示键
break;
case 0x844: //保存键
break;
default:
// Delay_mS(100);
// Error_Flag = 1;
break;
}
}
}
/**************************************************************************
* 函数原型: void ParaInit(void)
* 功 能: 系统初始化
**************************************************************************/
void ParaInit(void){
TMR0 = TMR0_Value;
time_10mS = vTime_10mS;
time_100mS =vTime_100mS;
time_1S = vTime_1S;
time_1Min = vTime_1Min;
time_1Hour= vTime_1Hour;
time_10Hour = vTime_10Hour;
}
/**************************************************************************
* 函数原型: void InitSys(void)
* 功 能: 系统初始化
**************************************************************************/
void InitSys(void){
INTCON = 0xd0; //使能GP2/INT 外部中断,使能TMR0 溢出中断
OPTION = 0x8f;
CMCON = 0x07;
WPU = 0x00;
TRISIO = 0x00;
GPIO = 0xff;
T1CON = 0x08;
TMR1IE = 1; //允许Timer1中断
ParaInit();
}
/**************************************************************************
* 函数原型: void main(void)
* 功 能: 主程序
**************************************************************************/
void main(void){
InitSys();
while(1){
CLRWDT();
GPIO=0xff;
Delay_mS(100);
GPIO=0x00;
Delay_mS(100);
// CommandDeal();
}
}
/**************************************************************************
* 函数原型: void interrupt INTServe(void)
* 功 能: 中断处理
**************************************************************************/
/*
void interrupt INTServe(void){
static uchar Bit_Cnt; //接收位计数
static uchar k; //接收字计数
if(Error_Flag == 1){
Error_Flag = 0;
Bit_Cnt = 0;
k = 0;
}
if(INTF == 1){
INTF = 0;
TMR1H = 0xFc; //420*2us = 2a
TMR1L = 0xB8;
TMR1ON = 1;
}
if(TMR1IF == 1){
TMR1IF = 0;
TMR1ON = 0;
if(REM == 0){
RCV_Command[k] += 0x01;
}
RCV_Command[k] <<= 1;
if(Bit_Cnt++ > 11){ //已接收到12位数据
Bit_Cnt = 0;
if(k++ > 1){ // 2个字接收结束
k = 0;
RCV_End_Flag = 1;
}
}
}
if(T0IF){ //定时器0是否溢出
T0IF = 0;
TMR0 = TMR0_Value;
if(--time_10mS == 0x00){
time_10mS = vTime_10mS;
if(--time_100mS == 0x00){
time_100mS =vTime_100mS;
if(--time_1S == 0x00){
time_1S = vTime_1S;
//UV = !UV;
//L1 = !L1;
FAN=!FAN;
L2=!L2;
if(--time_1Min== 0x00){
time_1Min = vTime_1Min;
if(--time_1Hour== 0x00){
time_1Hour= vTime_1Hour;
if(--time_10Hour== 0x00){
time_10Hour = vTime_10Hour;
}
}
}
}
}
}
}
}
/**************************************************************************
* 函数原型: END
* 功 能: END
**************************************************************************/
一周热门 更多>