单片机按下K1键产生50个脉冲程序的问题
时间:10-02
整理:3721RD
点击:
#include<regx51.h>
bit temp=0;
int i=0;
sbit JU=P1^4;
sbit K1=P1^7;
void main()
{
P1=0xff;
JU=0;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(K1==0)
{
JU=temp;
}
if(i==100)
EA=0;
while(1);
}
}
void DS0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
temp=~temp;
i++;
}
bit temp=0;
int i=0;
sbit JU=P1^4;
sbit K1=P1^7;
void main()
{
P1=0xff;
JU=0;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(K1==0)
{
JU=temp;
}
if(i==100)
EA=0;
while(1);
}
}
void DS0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
temp=~temp;
i++;
}
是一个计数器实验
电路图 在这,

#include<regx51.h>
bit temp=1;
int i=0;
sbit K1=P1^7;
void main()
{
P1=0xff;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(K1==0)
{
P1_4=temp;
}
if(i==100)
while(1);
}
}
void DS0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
temp=~temp;
if(K1!=0)
i=0;
i++;
}
哈哈我把程序调好了 大仙们看看有不有可以改进的啊
