HJ-2G(AVR)矩阵键盘+数码管显示
2019-03-24 20:46发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
为什么(0,1,2,3)在数码管上不显示?
求高人指导
源程序(ICC-AVR)如下:
#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar Key;
#pragma data:code
flash table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<1141;j++);
}
void number_show(uchar num)
{
PORTB=table[num];
PORTA|=BIT(3);
PORTA&=~BIT(3);
PORTB=0XFF;
PORTB=~BIT(0);
PORTA|=BIT(4);
PORTA&=~BIT(4);
delay(10);
}
void key_scan()
{
uchar key,i;
DDRD=0xf0;
PORTD=0x0f;
key=PIND;
key&=0x0f;
if(key!=0x0f)
{
delay(10);
for(i=0;i<4;i++)
{
PORTD=~BIT(i);
DDRD=0x0f;
key=PIND;
key_result(key&0xf0,i);
}
//while();
}
}
void key_result(uchar keyread,uchar i)
{
if(i==0)
{
switch(keyread)
{
case 0xe0:
Key=0; break;
case 0xd0:
Key=1; break;
case 0xb0:
Key=2; break;
case 0x70:
Key=3; break;
}
}
else if(i==1)
{
switch(keyread)
{
case 0xe0:
Key=4; break;
case 0xd0:
Key=5; break;
case 0xb0:
Key=6; break;
case 0x70:
Key=7; break;
}
}
else if(i==2)
{
switch(keyread)
{
case 0xe0:
Key=8; break;
case 0xd0:
Key=9; break;
case 0xb0:
Key=10; break;
case 0x70:
Key=11; break;
}
}
else if(i==3)
{
switch(keyread)
{
case 0xe0:
Key=12; break;
case 0xd0:
Key=13; break;
case 0xb0:
Key=14; break;
case 0x70:
Key=15; break;
}
}
else
Key=16;
}
void main()
{
DDRA|=BIT(3);
DDRA|=BIT(4);
DDRB=0XFF;
while(1)
{
key_scan();
number_show(Key);
}
}HJ-2G原理图
[
本帖最后由 cxchenxingcool 于 2012-11-13 20:42 编辑 ]
此帖出自
小平头技术问答
一周热门 更多>