#include<pic.h>
#define uint unsigned int
#define uchar unsigned char
__CONFIG(0x3B31);
const uchar table[]={0x3f,0x30,0x5b,0x4f,0x66,0x6d,0x7d,0x7h,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint num;
void beep(uchar y);
void init();
void display();
void scan();
void delay(uchar x);
void main()
{
init();
scan();
display();
}
void init()
{
TRISD=0xf0;
TRISA=0;
TRISB=0;
PORTB=0;
RA1=0;
}
void scan()
{
uint temp;
PORTD=0xfe;
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
delay(15);
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
temp=num;
while(temp!=0xf0)
{
temp=PORTD;
temp=temp&0xf0;
}
num=num|0x0e;
}
}
else
{
PORTD=0xfd;
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
delay(15);
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
temp=num;
while(temp!=0xf0)
{
temp=PORTD;
temp=temp&0xf0;
}
num=num|0x0d;
}
}
else
{
PORTD=0xfb;
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
delay(15);
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
temp=num;
while(temp!=0xf0)
{
temp=PORTD;
temp=temp&0xf0;
}
num=num|0x0b;
}
}
else
{
PORTD=0xf7;
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
delay(15);
num=PORTD;
num=num&0xf0;
if(num!=0xf0)
{
temp=num;
while(temp!=0xf0)
{
temp=PORTD;
temp=temp&0xf0;
}
num=num|0x07;
}
}
}
}
}
}
void display()
{
uint n;
switch(num)
{
case 0xee:n=0;break;
case 0xde:n=1;break;
case 0xbe:n=2;break;
case 0x7e:n=3;break;
case 0xed:n=4;break;
case 0xdd:n=5;break;
case 0xbd:n=6;break;
case 0x7d:n=7;break;
case 0xeb:n=8;break;
case 0xdb:n=9;break;
case 0xbb:n=10;break;
case 0x7b:n=11;break;
case 0xe7:n=12;break;
case 0xd7:n=13;break;
case 0xb7:n=14;break;
case 0x77:n=15;break;
}
PORTB=table[n];
}
void delay(uchar x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--)
;
}
void beep(uchar y)
{
uchar di_num;
for(di_num=y;di_num>0;di_num--)
{
RA1=1;
delay(50);
RA1=0;
delay(20);
}
}
[
本帖最后由 飓风狂飙 于 2013-9-14 08:12 编辑 ]
此帖出自
小平头技术问答
一周热门 更多>