📄 ok.c
字号:
/******************************************************************************
*
* pm5050语音遥控输出程序 40w *
* 单片机 AT89C2051 *
* 功放为TDA2003 *
* 设计:叶设炉 *
* 时间:2006年10月25日完成 *
* *
******************************************************************************/
/* 加载头文件 */
#include <reg52.h>
#include <intrins.h>
/*定义宏变量*/
#define highfiltertime 0 //0.2S
#define highshorttime 1 //0.5S
#define highlongtime 10 //1S
/* 定义全局变量 */
unsigned long highkeycount_A;
unsigned long highkeycount_B;
unsigned long highkeycount_C;
unsigned long highkeycount_D;
unsigned long s_count;
unsigned long s10_count;
/* 子函数声明 */
void delayNms (unsigned long partnumx);
void outkey (unsigned char partnum);
void readkey (void);
void o1 (void);
void o2 (void);
void o3 (void);
void o4 (void);
void o5 (void);
void o6 (void);
void o7 (void);
void o8 (void);
void Count_S(void);
unsigned char bdata highkeyflgshort,highkeyflglong;//input station var
sbit highkeyflgshort_A = highkeyflgshort^0;
sbit highkeyflgshort_B = highkeyflgshort^1;
sbit highkeyflgshort_C = highkeyflgshort^2;
sbit highkeyflgshort_D = highkeyflgshort^3;
sbit highkeyflglong_A = highkeyflglong^0;
sbit highkeyflglong_B = highkeyflglong^1;
sbit highkeyflglong_C = highkeyflglong^2;
sbit highkeyflglong_D = highkeyflglong^3;
sbit busy_01 = highkeyflglong^4;
sbit play_busy = highkeyflglong^5;
/* 定义单片机管脚 */
sbit in_key_A = P3^2;
sbit in_key_B = P3^3;
sbit in_key_C = P3^4;
sbit in_key_D = P3^5;//11000011
sbit in_spk_01 = P3^7;
sbit k1 = P1^7;
sbit k2 = P1^6;
sbit k3 = P1^5;
sbit k4 = P1^4;
sbit k5 = P1^3;
sbit k6 = P1^2;
sbit k7 = P1^1;
sbit k8 = P1^0;
sbit out_led_D2 = P3^1;
/* 主程序 */
void main (void)
{
P1 = 0xFF; // 端口初始化
P3 = 0xFF;
highkeyflgshort = 0;
highkeyflglong = 0;
// 主程序初始化
for ( ; ; )
{
readkey ();
Count_S();
if (highkeyflgshort != 0x0)//if 1
{
switch (highkeyflgshort)//highkeyflgshort//switch 1
{
case 0x01: o1();//S_A
break;
case 0x02: o2();//S_B
break;
case 0x04: o3();//S_C
break;
case 0x08: o4();//S_D
break;
default: delayNms (30);//保证时基的均匀
break;
}//switch 1 end
highkeyflgshort = highkeyflgshort & 0xf0;//得到有效按键,只播放一次,故要清掉
}
else
{ if ((highkeyflglong & 0x0f) != 0x0)//if 2
{
switch ((highkeyflglong & 0x0f))//highkeyflgshort
{
case 0x01: o5();//L_A
break;
case 0x02: o6();//L_B
break;
case 0x04: o7();//L_C
break;
case 0x08: o8();//L_D
break;
default: delayNms (30);//保证时基的均匀
break;
}//switch 2 end
highkeyflglong =highkeyflglong & 0xf0;//得到有效按键,只播放一次,故要清掉
}// if 2 end
else//未进入两个SWITCH
delayNms (60);//保证时基的均匀
}//if 1 else is end
} //for end
}//main end
/****************************************************************/
void readkey (void) //扫描时间较确定
{
/**************************in_key_A*******************************/
if (in_key_A) //如果A按下
{ highkeycount_A++;} //时间累积
else
{
if(highkeycount_A>0)
{
if ( highkeycount_A > highlongtime )//长信号
{ highkeyflglong_A = 1;
highkeyflgshort_A = 0;
}
else
{ highkeyflgshort_A = 1;
highkeyflglong_A = 0;
}
// }
}
highkeycount_A = 0; //计数清零
}
/****************************in_key_B*****************************/
if (in_key_B)
{ highkeycount_B++;}
else
{
if(highkeycount_B>0)
{
if ( highkeycount_B > highlongtime )//长信号
{ highkeyflglong_B = 1;
highkeyflgshort_B = 0;
}
else
{
highkeyflgshort_B = 1;
highkeyflglong_B = 0;
}
}
highkeycount_B = 0; //计数清零
}
/*************************in_key_C********************************/
if (in_key_C)
{ highkeycount_C++;}
else
{
if(highkeycount_C>1)
{
if ( highkeycount_C > highlongtime )//长信号
{ highkeyflglong_C = 1;
highkeyflgshort_C = 0;
}
else
{
highkeyflgshort_C = 1;
highkeyflglong_C = 0;
// }
}
}
highkeycount_C = 0; //计数清零
}
/***********************in_key_D**********************************/
if (in_key_D)
{ highkeycount_D++;}
else
{
if(highkeycount_D>1)
{
if ( highkeycount_D > highlongtime )//长信号
{ highkeyflglong_D = 1;
highkeyflgshort_D = 0;
}
else
{
highkeyflgshort_D = 1;
highkeyflglong_D = 0;
}
}
highkeycount_D = 0; //计数清零
}
}
/************************************************************/
void delayNms (unsigned long partnumx)
{
unsigned long i;
do{
for (i=0;i<10;i++); //实际测试设定
partnumx--;
} while (partnumx != 0);
}
/************************************************************/
void o1 (void)
{
k1=1;
delayNms(100);
k1=0;
}
void o2 (void)
{
k2=1;
delayNms(100);
k2=0;
}
void o3 (void)
{
k3=1;
delayNms(100);
k3=0;
}
void o4 (void)
{
k4=1;
delayNms(100);
k4=0;
}
void o5 (void)
{
k5=1;
delayNms(100);
k5=0;
}
void o6 (void)
{
k6=1;
delayNms(100);
k6=0;
}
void o7 (void)
{
k7=1;
delayNms(100);
k7=0;
}
void o8 (void)
{
k8=1;
delayNms(100);
k8=0;
}
void Count_S(void)
{ s_count++;
if (s_count > 15)
{ out_led_D2 =0;//1秒
delayNms(15);
out_led_D2 =1;//1秒
s_count =0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -