标题:
单片机按键控制点阵显示数字
[打印本页]
作者:
led893
时间:
2021-11-23 21:04
标题:
单片机按键控制点阵显示数字
#include<reg51.h>
#include<intrins.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
#define GPIO_KEY P1
#define COMMONPORTS P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 code TAB[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
u8 code CHARCODE[18][8]=
{
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00}, //P
{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00}, //R
{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00}, //E
{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00}, //C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} // ?
};
void delay(u16 time)
{
u16 i,j;
for(i=0;i<time;i++)
for(j=0;j<121;j++);
}
void Hc595SendByte(u8 dat)
{
u8 a;
SRCLK=0;
RCLK=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat<<=1;
SRCLK=1;
_nop_();
_nop_();
SRCLK=0;
}
RCLK=1;
_nop_();
_nop_();
RCLK=0;
}
void InterruptTimer0 () interrupt 1
{
unsigned char i = 0;
static unsigned char KeyBuf[4]={
0xFF,0xFF,0xFF,0xFF
};
TH0 = 0xFC;
TL0 = 0x67;
KeyBuf [0] = (KeyBuf[0]<<1)|KEY_IN_1;
KeyBuf [1] = (KeyBuf[1]<<1)|KEY_IN_2;
KeyBuf [2] = (KeyBuf[2]<<1)|KEY_IN_3;
KeyBuf [3] = (KeyBuf[3]<<1)|KEY_IN_4;
for (i=0; i<4; i++)
{
if ((KeyBuf[i]&0x0F) == 0x00)
{
KeySta[i] = 0;
}
else if ((KeyBuf[i]&0x0F) == 0x0F)
{
KeySta[i] = 1;
}
}
}
void main()
{
while(1)
{
for (i=0; i<4; i++)
{
if (backup [i] != KeySta [i])
{
if(backup [i] != 0)
{
if(KeySta[0]==0)
{
TR1 = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 0;
ADDR1 = 0;
ADDR0 = 0;
if (KeySta[0]==0)
{
P0 = LedChar[cnt];
cnt++;
if(cnt >= 10)
cnt = 0;
}
}
}
}
}
}
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1