1.电路是外接8个按键
2.SCD接外部中断0
以下程序
#include "reg51.h"
#include "intrins.h"
unsigned char key;
sbit SCD=P3^2;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
///////////////////////////////////////////////////////////////////////////////////////////////////////
void Delay50us() //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 1;
j = 134;
do
{
while (--j);
} while (--i);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Delay3000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 127;
j = 18;
k = 107;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
void Delay10us() //@11.0592MHz
{
unsigned char i;
_nop_();
i = 25;
while (--i);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
void zd0()
{
EA=1;IT0=1;EX0=1;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void cmfs ()
{
unsigned char z;
SCD=0;
Delay50us(); Delay50us();Delay50us(); Delay50us();Delay50us(); Delay50us(); Delay50us();
Delay50us(); Delay50us();Delay50us(); Delay50us();Delay50us(); Delay50us(); Delay50us();
for(z=12;z>0;z--)
{
SCD=1;
Delay10us();
SCD=0;
Delay10us();
}
SCD=1;
IE0=0;
}
//////////////////////////////////////////////////////////////////////////////////////////
void read()interrupt 0
{
unsigned char x,y;
unsigned char date;
EX0=0;
Delay50us();
for(x=5;x>0;x--)
{
SCD=0;
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
SCD=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
while(SCD);
while(!SCD);
for(y=8;y>0;y--)
{
while (SCD);
Delay50us();Delay50us();
SCD=1;
date>>=1;
if(SCD==1)
{date|=0x80;}
else
{date&=0x7f;}
while(!SCD);
}
if(date!=0xff)
key=date;
EX0=1;
EA=1;
IE0=0;
}
////////////////////////////////////////////////////////////////////////////////////
void main()
{
cmfs ();
zd0();
////while( 1){P1=key;}
while(1)
{
if(key==0x7f){P1=0xfe;}
}
}
现象,读不了键值,设置不了多键唤醒模式,是没设置I/o模式?求指教
|