| #include <pic.h> //调用头文件,可以去PICC软件下去查找PIC16F87XA单片机的头文件
//__CONFIG(XT&WDTDIS&LVPDIS); //定义配置字,晶振类型:XT,关闭开门狗,禁止低电压编程
#define relay RD0
#define relayr RD1
#define relayy RD2
#define relayg RD3 //继电器
int ycon;
unsigned char key2;
unsigned char key1;
void timer1init(void)
{
T1CON=0X01;
TMR1IF=0; //清除TMR1中断标志
TMR1IE=1; //TMR1中断允许
TMR1H=0x13; //赋初值,以便TMR1每250US中断一次
TMR1L=0x13;
PIR1=0;
PEIE=1;
GIE=1;
}
void interrupt T1(void)
{
if(TMR1IF==1) //250us
{
TMR1H=0X13;
TMR1L=0x13;
TMR1IF=0;
if(++ycon>10) //计数18次后,为1秒
{
++key1;
++key2;
ycon=0;
if(key1==1)
{
relay=0;
}
if(key1==2)
{
key1=0;
relay=1;
}
if(key2==1)
{
relayr=1;
relayy=0;
relayg=0;
}
if(key2==2)
{
relayr=0;
relayy=1;
relayg=0;
}
if(key2==3)
{
relayr=0;
relayy=0;
relayg=1;
key2=0;
}
}
}
}
void main(void)
{
key1=0;
key2=0;
// TRISD=0B11110000; //RD0设置为输入出
TRISD=0B11110000; //RD0-3设置为输出,
//relay=0;
// relayr=0;
// relayy=0;
// relayg=0;
timer1init();
while(1)
{
}
}
我想RD0口一个计数周期输出高电平一次,RD1,RD2,RD3一个计数周期换一个脚输出高电平一次
结果我的程序烧进去RD0跟着RD2变化,求指教那里程序不行了
|
| #include <pic.h> //调用头文件,可以去PICC软件下去查找PIC16F87XA单片机的头文件
//__CONFIG(XT&WDTDIS&LVPDIS); //定义配置字,晶振类型:XT,关闭开门狗,禁止低电压编程
#define relay RD0
#define relayr RD1
#define relayy RD2
#define relayg RD3 //继电器
int ycon;
unsigned char key2;
unsigned char key1;
void timer1init(void)
{
T1CON=0X01;
TMR1IF=0; //清除TMR1中断标志
TMR1IE=1; //TMR1中断允许
TMR1H=0x13; //赋初值,以便TMR1每250US中断一次
TMR1L=0x13;
PIR1=0;
PEIE=1;
GIE=1;
}
void interrupt T1(void)
{
if(TMR1IF==1) //250us
{
TMR1H=0X13;
TMR1L=0x13;
TMR1IF=0;
if(++ycon>10) //计数18次后,为1秒
{
++key1;
++key2;
ycon=0;
if(key1==1)
{
relay=0;
}
if(key1==2)
{
key1=0;
relay=1;
}
if(key2==1)
{
relayr=1;
relayy=0;
relayg=0;
}
if(key2==2)
{
relayr=0;
relayy=1;
relayg=0;
}
if(key2==3)
{
relayr=0;
relayy=0;
relayg=1;
key2=0;
}
}
}
}
void main(void)
{
key1=0;
key2=0;
// TRISD=0B11110000; //RD0设置为输入出
TRISD=0B11110000; //RD0-3设置为输出,
relay=0;
relayr=0;
relayy=0;
relayg=0;
timer1init();
while(1)
{
}
}
我想RD0口一个计数周期输出高电平一次,RD1,RD2,RD3一个计数周期换一个脚输出高电平一次
结果我的程序烧进去RD0跟着RD2变化,求指教那里程序不行了
|
|