练习: 按下S5,产生中断,LED点亮, 再次按下S5,LED左移一位
#include"reg52.h"
void SelectHC573(unsigned char n){
switch(n){
case 4:
P2 = (P2 & 0x1f) | 0x80;
break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;
break;
case 6:
P2 = (P2 & 0x1f) | 0xc0;
break;
case 7:
P2 = (P2 & 0x1f) | 0xe0;
break;
}
}
void Init_Int0(){
EX0=1;
IT0=1;
EA=1;
}
unsigned char Staic_K=0;
void SeverInt0() interrupt 0
{
Staic_K=1;
}
void Delay(unsigned int t){
while(t--);
while(t--);
}
unsigned int i;
void ledrun(){
SelectHC573(4);
P0=0xff;
if(Staic_K==1)
{
for(i=0;i<=8;i++)
{
P0 = 0xff<<i;
Delay(60000);
}
}
Staic_K=0;
}
void InitSystem(){
SelectHC573(5);
P0=0x00;
SelectHC573(4);
P0=0xff;
}
int main(){
InitSystem();
Init_Int0();
while(1){
ledrun();
}
}
|