51单片机ADC0809函数信号发生器搭配44独立键盘代码
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar delay=0;
uchar key,k;
uchar th0,tl0;
uchar pinlv=4679;
uchar N;
//zhengxianbo
uchar code sin[64]={
135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,
146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128
};
//fangbo
uchar code juxing[64]={
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
//juchibo
uchar code juchi[64]={
0,4,8,12,16,20,24,28,32,36,40,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,130,134,138,142,
146,150,154,158,162,166,170,174,178,182,186,190,194,198,202,206,210,215,219,223,227,231,235,239,243,247,251,255
};
//sanjiaobo
uchar code sanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,
248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0
};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void matrixkeyscan()
{
uchar temp;
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp != 0xf0)
{
delayms(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xee:
key=0;
break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp != 0xf0)
{
delayms(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xed: //pinlv+=1;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=1*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0xdd: //pinlv+=10;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=10*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0xbd: //pinlv+=50;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=50*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0x7d: pinlv+=100;
N=(unsigned long) 1000000/356/pinlv;
//pinlv+=100*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp != 0xf0)
{
delayms(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xeb:// pinlv-=1;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=1*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0xdb: //pinlv-=10;
// N=(unsigned long) 1000000/356/pinlv;
pinlv+=10*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0xbb: //pinlv-=50;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=50*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
case 0x7b: //pinlv-=100;
//N=(unsigned long) 1000000/356/pinlv;
pinlv+=100*15;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp != 0xf0)
{
delayms(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xe7: key=12;
break;
case 0xd7: key=13;
break;
case 0xb7: key=14;
break;
case 0x77: key=15;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
}
void main()
{
TMOD=0x01;
th0=(65536-pinlv)/256;
tl0=(65536-pinlv)%256;
TH0=th0;
TL0=tl0;
EA=1;
IT0=1;
EX0=1;
IT1=1;
EX1=1;
ET0=1;
TR0=1;
pinlv=15;
while(1)
{
matrixkeyscan();
}
}
void time0() interrupt 1
{
TH0=th0;
TL0=tl0;
switch(key)
{
case 0:
P2=sin[k];
k=(k+1)%64;
break;
case 1:
P2=juxing[k];
k=(k+1)%64;
break;
case 2:
P2=juchi[k];
k=(k+1)%64;
break;
case 3:
P2=sanjiao[k];
k=(k+1)%64;
break;
default: P2=0;
}
}