要学按键功能,在数码管上显示,显示函数式可行的,但是
一直显示8怎么回事啊?
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar disbuf[4]={0,0,0,0};
uchar discode[11]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};//段码表
uchar disbit[4]={ 0xFE,0xFD,0xFB,0xF7}; //选通值
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void show(uchar i,uchar j)
{ // uchar m;
DDRB=0Xff;
PORTB=discode
;
PORTA=disbit[j];
// PORTA=0xff;
// PORTD=0xff;
delay(2);
}
uchar key_press()
{
uchar j,k;
DDRD|=0X08; // 0000 1000
// DDRA|=0X30; //PA4,PA5
PORTD|=0X08;
DDRD&=0XF7; //shuru 1111 0111
// DDRA&=0XCF;
j=PIND;
j=j&0X08;
// k=PINA;
// k=i&0X30;
if(j==0X08)
{
DDRD|=0X08;
return 0;
}
else
{
DDRD|=0X08;
return 1;
}
}
uchar key_scan()
{
uchar key;
delay(10);
if(key_press())
{
key=PIND;
key&=0X08;
switch(key)
{
case 0x08: key=1; break;
default: key=11;
}
delay(2);
while(key_press()); //等待按键松开
}
else
{
key=11;
}
return key;
}
void main()
{
uchar l;
DDRA|=0x0f; //PA0输出
PORTA=0X00;
DDRB=0Xff;
PORTB=0XFF;
while(1);
{
if(key_press())
{ delay(2);
l=key_scan();
show(l,0);
}
}
}
此帖出自小平头技术问答
PORTA=disbit[j];
这两句是显示的吗?
一周热门 更多>