|
#include /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include
#define C8LED PORTA
#define P3 PORTB
#pragma MESSAGE DISABLE C4000
byte LED_num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};byte key=0;
void delayms (int m) {int x,y;for(x=0;x
void display(key) C8LED=LED_num[key];
void matrixkeyscan()
{
byte temp;
P3=0x01;
temp=P3;
temp=temp&0xf0;
if(temp!=0x00)
{
delayms(50);
temp=P3;
temp=temp&0xf0;
if(temp!=0x00)
{
temp=P3;
switch(temp)
{
case 0x11:
key=1;
break;
case 0x21:
key=2;
break;
case 0x41:
key=3;
break;
}
while(temp!=0x00)
{
temp=P3;
temp=temp&0xf0;
}
display(key);
}
}
P3=0x02;
temp=P3;
temp=temp&0xf0;
if(temp!=0x00)
{
delayms(50);
if(temp!=0x00)
{
temp=P3;
switch(temp)
{
case 0x12:
key=4;
break;
case 0x22:
key=5;
break;
case 0x42:
key=6;
break;
}
while(temp!=0x00)
{
temp=P3;
temp=temp&0xf0;
}
display(key);
}
}
P3=0x04;
temp=P3;
temp=temp&0xf0;
if(temp!=0x00)
{
delayms(50);
if(temp!=0x00)
{
temp=P3;
switch(temp)
{
case 0x14:
key=7;
break;
case 0x24:
key=8;
break;
case 0x44:
key=9;
break;
}
while(temp!=0x00)
{
temp=P3;
temp=temp&0xf0;
}
display(key);
}
}
}
void main(void)
{
DDRA=0xff;
DDRB=0x0f;PUCR=0X02;
while(1)
{
void matrixkeyscan()
;}
}
|
|