各位大虾,我用PIC单片机编了个简单的测试程序,通过I/O口的电平变化控制电磁阀吸合断开,上电时间约1秒,断开时间约9秒,但测试时电磁阀吸断几次后就不动作了,隔很长一段时间又吸断几次,然后又没反应,请问是程序问题吗(后来用555电路控制了)
#include "pic.h"
#define uchar unsigned char
#define uint unsigned int
uint n;
void initTMR1()
{
GIE=1;
PEIE=1;
TMR1IE=1;
TMR1L=(65536-20000)%256;
TMR1H=(65536-20000)/256;
T1CON=0x01;
}
void main()
{
initTMR1();
TRISC=0x00;
RC5=0;
while(1)
{
}
}
void interrupt time1()
{
TMR1IF=0;
TMR1L=(65536-20000)%256;
TMR1H=(65536-20000)/256;
n++;
if(n==100)
{
RC5=0;
}
if(n==700)
{
RC5=1;
n=0;
}
} |