電路原理圖如下:
單片機程序源碼:
#include <reg52.h> //頭文件
#include <intrins.h>
#define uint unsigned int //宏定義
#define uchar unsigned char
sbit SW1 =P1^0; //按鍵1
sbit SW2 =P1^1; //按鍵2
sbit SW3 =P1^2; //按鍵3
sbit SW4 =P1^3; //按鍵4
uint num;
uchar huayang1[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0xff};
uchar huayang2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar huayang3[]={0xaa,0x55,0xfb,0xf7,0xef,0x39,0xf1,0xe5,0x02,0xe3,0x2c,};
void delay(uint S)
{
while(S--);
}
void ms()
{
uint i;
for(i=0;i<200;i++)
{
delay(200);
}
}
void main()
{
while(1)
{
if(SW1==0)
{
delay(10);
if(SW1==0)
{
while(!SW1);
while(1)
{
for(num=0;num<9;num++)
{
P0=huayang1[num]; P2=~huayang1[num];
ms();
}
}
}
}
if(SW2==0)
{
delay(10);
if(SW2==0)
{
while(!SW2);
while(1)
{
for(num=0;num<8;num++)
{
P0=0xff; P2=0;
ms();
P0=huayang2[num]; P2=~(0x55 & huayang2[num]);
ms();
}
}
}
}
if(SW3==0)
{
delay(10);
if(SW3==0)
{
while(!SW3);
while(1)
{
for(num=0;num<11;num++)
{
P0=huayang3[num]; P2=~(0xaa & huayang3[num]);
ms(); ms();
if(SW1==0||SW2==0||SW3==0||SW4==0)
break;
}
}
}
}
}
}
一個不用中斷可立即跳出當前運行狀態的操作.rar
(17.29 KB, 下載次數: 94)
2019-1-22 02:53 上傳
點擊文件名下載附件
|