📄 iar6-6.c
字号:
#include<iom16.h>
#define uchar unsigned char
#define uint unsigned int
__flash uchar SKEY[16]={10,11,12,13,3,6,9,14,2,5,8,0,1,4,7,15};
__flash uchar act[4]={0xfe,0xfd,0xfb,0xf7};
__flash uchar SEG7[16]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay_ms(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<1140;j++);
}
}
//=============================
uchar scan_key(void)
{
uchar i,j,in,ini,inj;
uchar find=0;
for(i=0;i<4;i++)
{
PORTB=act[i];
delay_ms(10);
in=PINB;
in=in>>4;
in=in|0xf0;
for(j=0;j<4;j++)
{
if(act[j]==in)
{find=1;
inj=j;ini=i;
}
}
}
if(find==0)return 16;
return (ini*4+inj);
}
//=============================
void main(void)
{
uchar c,key_value;
DDRA=0xff;
DDRC=0xff;
DDRB=0x0f;
PORTA=0x00;
PORTC=0xff;
PORTB=0xff;
while(1)
{
c=scan_key();
if(c!=16)key_value=SKEY[c];
PORTA=SEG7[key_value];
PORTC=0xfe;
delay_ms(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -