高级会员
- 积分
- 816
- 威望
- 406
- 贡献
- 252
- 兑换币
- 236
- 注册时间
- 2013-1-22
- 在线时间
- 79 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define uchar unsigned char
#define uint unsigned int
#define dula PORTK_PK0
#define wela PORTK_PK1
#define dula_dir DDRK_DDRK1
#define wela_dir DDRK_DDRK0
#define DATA PORTA
#define DATA_dir DDRA
#define KEY PORTB
#define KEY_dir DDRB
byte shuma[20]={
0x03,0x9f,0x25,0x0d,
0x99,0x49,0x41,0x1f,
0x01,0x09
};
/*************************************************************/
/* 延时函数 */
/*************************************************************/
void delay(uint xms)
{
uint i,j;
for(j=xms;j>0;j--)
for(i=110;i>0;i--);
}
/*************************************************************/
void display(uchar num) {
DATA=shuma[num];
dula=1;
dula=0;
}
/*************************************************************/
void keyscan() {
uchar temp,n;
KEY = 0Xfe;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xee :n=0;break;
case 0xde :n=1;break;
case 0xbe :n=2;break;
case 0x7e :n=3;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xfd;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xed :n=4;break;
case 0xdd :n=5;break;
case 0xbd :n=6;break;
case 0x7d :n=7;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xfb;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xeb :n=8;break;
case 0xdb :n=9;break;
case 0xbb :n=10;break;
case 0x7b :n=11;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
KEY = 0Xf7;
temp = KEY;
temp =temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp = KEY;
switch(temp)
{ case 0xe7 :n=12;break;
case 0xd7 :n=13;break;
case 0xb7 :n=14;break;
case 0x77 :n=15;break;
}
while(temp!=0xf0)
{
temp = KEY;
temp =temp&0xf0;
}
display(n);
}
}
/*************************************************************/
void init()
{
dula_dir = 1;
wela_dir = 1;
DATA_dir = 0xff;
KEY_dir = 0xff;
}
/*************************************************************/
void main(void) {
init();
dula = 1;
DATA = 0xff;
dula = 0;
wela = 1;
DATA = 0xff;
wela = 0;
for(;;)
{
keyscan();
}
}
|
|