4X4的按健程序
马老师下便是我的4X4按健程序,前8个键与后8个健功能不一样,用8515的 A口,帮我看看有何不妥用16M晶体
DDRA = 0xf0;
PORTA =0x7f;
keytemp=PINA;
delay(15);
keytemp=PINA;
switch(keytemp) {
case 0x77:
{
do
{
wait;
}
while(PINA!=0x7f);
SPI_MasterTransmit(0x25);
}
break;
case 0x7b:
{
do
{
wait;
}
while(PINA!=0x7f);
SPI_MasterTransmit(0x24);
}
break;
case 0x7d:
{
do
{
wait;
}
while(PINA!=0x7f);
SPI_MasterTransmit(0x27);
}
break;
case 0x7e:
{
do
{
wait;
}
while(PINA!=0x7f);
SPI_MasterTransmit(0x26);
}
break;
default:break;
}
PORTA=0xbf;
keytemp=PINA;
delay(15);
keytemp=PINA;
switch(keytemp) {
case 0xb7:
{
do
{
wait;
}
while(PINA!=0xbf);
SPI_MasterTransmit(0x21);
}
break;
case 0xbb:
{
do
{
wait;
}
while(PINA!=0xbf);
SPI_MasterTransmit(0x20);
}
break;
case 0xbd:
{
do
{
wait;
}
while(PINA!=0xbf);
SPI_MasterTransmit(0x23);
}
break;
case 0xbe:
{
do
{
wait;
}
while(PINA!=0xbf);
SPI_MasterTransmit(0x22);
}
break;
default:
break;
}
PORTA=0xdf;
keytemp=PINA;
delay(15);
keytemp=PINA;
switch(keytemp) {
case 0xd7:
{
wait;
do
{
SPI_MasterTransmit(0x03);
delay(30);
}
while(PINA!=0xdf);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
case 0xdb:
{
wait;
do
{
SPI_MasterTransmit(0x13);
delay(15);
}
while(PINA!=0xdf);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
case 0xdd:
{
wait;
do
{
SPI_MasterTransmit(0x07);
delay(30);
}
while(PINA!=0xdf);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
case 0xde:
{
wait;
do
{
SPI_MasterTransmit(0x05);
delay(30);
}
while(PINA!=0xdf);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
default:
break;
}
PORTA=0xef;
keytemp=PINA;
delay(15);
keytemp=PINA;
switch(keytemp) {
case 0xe7:
{
wait;
do
{
SPI_MasterTransmit(0x17);
delay(15);
}
while(PINA!=0xef);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
case 0xeb:
{
wait;
do
{
SPI_MasterTransmit(0x15);
delay(15);
}
while(PINA!=0xef);
delay(5);
SPI_MasterTransmit(0x00);
}
break;
case 0xed:
{
wait;
do
{
SPI_MasterTransmit(0x01);
delay(20);
ktp=52;
sendchar(ktp);
delay(10);
}
while(PINA!=0xef);
ktp=48;
sendchar(ktp);
delay(10);
SPI_MasterTransmit(0x00);
}
break;
case 0xee:
{
wait;
do
{
SPI_MasterTransmit(0x08);
delay(20);
ktp=56;
sendchar(ktp);
delay(10);
}
while(PINA!=0xef);
ktp=48;
sendchar(ktp);
delay(10);
SPI_MasterTransmit(0x00);
}
break;
default:
break;
} 我的按键为单键工作,前8个按一下发送一个数,后8个按着键发送,松开口不发送。请知道的打下看看
页:
[1]