用C51编程,当高电平输入到单片机中单片机中的一个口发出信号小灯会亮,当输入单片机低电平是小灯会灭,当连续出现8个低电平输入单片机时,单片机会发出一个信号到喇叭,发出响声!
谢谢!
最好是用汇编语言,谢谢!!!!!!
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit high_key=P1^0;
sbit low_key=P1^1;
sbit led=P2^0;
sbit speak=P2^1;
uint count;
void delay(uint x)
{
uchar j;
while(x--)
{
for(j=0;j<125;j++)
{;}
}
}
void main(void)
{
high_key=0;
low_key=1;
led=speak=0;
while(1)
{
if(high_key==1)
{
delay(10);
if(high_key==1)
led=1;
}
if(low_key==0)
{
delay(10);
if(low_key==0)
{
led=0;
count++;
if(count==8)
{
count=0;
speak=1;
delay(100);
speak=0;
delay(100);
speak=1;
delay(100);
speak=0;
delay(100);
}
}
}
}
}