这是两个程序代码段,合并很简单,要写出你想要显示哪些内容或者要达到什么目的,下面是合并的结果:
#include "reg52.h"
#include "key.h"
/////////移到这里//////////////////////
//#include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
/////////////////////////////////
sbit led=P2^5;
unsigned int Tab_F[]={440,494,554,220,
440,494,554,220,
554,587,659,554,
587,659,999,};
unsigned char key_num;
unsigned int Pinlv,Shichang;
bit beep;
void Timer0Init()
{
TMOD|=0X01;
TH0=(65536-92)/256;
TL0=(65536-92)%256;
ET0=1; //T0中断
EA=1; //cpu总中断
TR0=1;
}
/*/////////////下面这段声明移到最后面的main主程序里面
void main()
{
Timer0Init();
while(1)
{
key_num=KeyDown();
if(key_num!=0xff)
{
Pinlv=Tab_F[key_num];
beep=1;
Shichang=0;
EA=1;
}
};
}
//////////////////////*/
void Timer0() interrupt 1
{
static unsigned int i;
TH0=(65536-92)/256;
TL0=(65536-92)%256;
i++;
if(i>(5000/Pinlv))
{
if(beep==1)
{led=~led;}
i=0;
}
Shichang++;
if(Shichang==1000)
{
beep=0;
led=0;
EA=0;
}
}
//===========================分隔//
#include "key.h"
unsigned char KeyValue=0;
void delay(unsigned int i)
{
while(i--);
}
unsigned char KeyDown(void)
{
char a=0;
GPIO_KEY=0x0f;
if(GPIO_KEY!=0x0f)
{
delay(1000);
if(GPIO_KEY!=0x0f)
{
GPIO_KEY=0X0F;
switch(GPIO_KEY) //lie
{
case(0X07): KeyValue=0;break;// 0111
case(0X0b): KeyValue=1;break;// 1011
case(0X0d): KeyValue=2;break; // 1101
case(0X0e): KeyValue=3;break;// 1110
}
GPIO_KEY=0XF0; //hang
switch(GPIO_KEY)
{
case(0X70): KeyValue=KeyValue;break; //0111
case(0Xb0): KeyValue=KeyValue+4;break;
case(0Xd0): KeyValue=KeyValue+8;break;
case(0Xe0): KeyValue=KeyValue+12;break;
}
while((a<50)&&(GPIO_KEY!=0xf0))
{
delay(1000);
a++;
}
}
}
else
{
KeyValue=0xff;
}
return KeyValue;
}
//===========================分隔//
/*/////////////下面这段声明移到前面开头的声明
//#include <reg52.h>
//typedef unsigned char uchar;
//typedef unsigned int uint;
//sbit LSA=P2^2;
//sbit LSB=P2^3;
//sbit LSC=P2^4;
//uchar smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
//0x7f,0x6f};
//////////////////////*/
void delay(uint a)
{
while(a--);
}
void dig_Disp()
{
uchar i=0;
for(;i<8;i++)
{
switch(i)
{
case 0:
LSA=0;LSB=0;LSC=0;P0=smg[0];break;
case 1:
LSA=1;LSB=0;LSC=0;P0=smg[1];break;
case 2:
LSA=0;LSB=1;LSC=0;P0=smg[2];break;
case 3:
LSA=1;LSB=1;LSC=0;P0=smg[1];break;
case 4:
LSA=0;LSB=0;LSC=1;P0=smg[9];break;
case 5:
LSA=1;LSB=0;LSC=1;P0=smg[1];break;
case 6:
LSA=0;LSB=1;LSC=1;P0=smg[0];break;
case 7:
LSA=1;LSB=1;LSC=1;P0=smg[2];break;
}
delay(100);
P0=0x00;
}
}
void main()
{
while(1)
{
//////////////移到这里,屏蔽多余的语句
//void main()
//{
// Timer0Init();
// while(1)
// {
key_num=KeyDown();
if(key_num!=0xff)
{
Pinlv=Tab_F[key_num];
beep=1;
Shichang=0;
EA=1;
}
// };
//
//}
/////////////////////////////////
dig_Disp();
}
}
|