查看: 992|回复: 0
打印 上一主题 下一主题

实验22-按键发音

[复制链接]
跳转到指定楼层
沙发
发表于 2015-5-5 16:23:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int

sbit BEEP = P1^4;
sbit K1   = P1^0;
sbit K2   = P1^1;
sbit K3   = P1^2;
sbit K4   = P1^3;

void DelayMS(uint x)
{
        uchar t;
        while(x--)
        {
                 for(t=0;t<120;t++);
        }
}

void Play(uchar t)
{
        uchar i;
        for(i=0;i<100;i++)
        {
                 BEEP = ~BEEP;
                DelayMS(t);
        }
        BEEP = 0;
}

void main()
{
        P1 = 0xff;
        while(1)
        {
                 if(K1==0) Play(1);
                if(K2==0) Play(2);
                if(K3==0) Play(3);
                if(K4==0) Play(4);
        }
}



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?加入因仑

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表