标题:
这单片机程序 数码管显示不完全
[打印本页]
作者:
萌新小白一个
时间:
2021-4-7 21:55
标题:
这单片机程序 数码管显示不完全
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
#define GPIO_KEY P1
#define GPIO_DIG P0
#define NEGATIVE_SIGH_SUB=10
u8 KeyValue;
u8 code smgduan[]={1,2,3,0,
4,5,6,0,
7,8,9,0,
0,0,0,0};
u8 code smgduan1[]={1,2,3,0x2f-0x30,
4,5,6,0x2a-0x30,
7,8,9,0x2d-0x30,
0x01-0x30,0,0x3d-0x30,0x2b-0x30};
void delay(u16 i)
{
while(i--);
}
void KeyDown()
{
u8 a=0;
GPIO_KEY=0x0f;
if( GPIO_KEY!=0x0f)
{
delay(1000);
if( GPIO_KEY!=0x0f)
{
GPIO_KEY=0x0f;
switch(GPIO_KEY)
{
case(0x07): KeyValue=0;break;
case(0x0b): KeyValue=1;break;
case(0x0d): KeyValue=2;break;
case(0x0e): KeyValue=3;break;
}
GPIO_KEY=0xf0;
switch(GPIO_KEY)
{
case(0x70): KeyValue=KeyValue;break;
case(0xb0): KeyValue=KeyValue+4;break;
case(0xd0): KeyValue=KeyValue+8;break;
case(0xe0): KeyValue=KeyValue+12;break;
}
while((a<50)&&( GPIO_KEY!=0xf0))
{
delay(1000);
a++;
}
}
}
}
void main()
{
LSA=0;
LSB=0;
LSC=0;
while(1)
{
KeyDown();
GPIO_DIG=smgduan[KeyValue];
}
}
作者:
wulin
时间:
2021-4-8 06:37
//顺序共阴极数码管段码表,段码a-h顺序接PX0-PX7
unsigned char code table[]={//共阴数码管段码"0~f-."
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x40,0x80};
//反序共阴极数码管段码表,段码a-h顺序接PX7-PX0
unsigned char code Table[]={//共阴数码管段码"0~f-."
0xFC,0x60,0xDA,0xF2,
0x66,0xB6,0xBE,0xE0,
0xFE,0xF6,0xEE,0x3E,
0x9C,0x7A,0x9E,0x8E,0x02,0x01};
//顺序共阳极数码管段码表,段码a-h顺序接PX0-PX7
unsigned char code table[]={//共阳数码管段码"0~f-."
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
//反序共阳极数码管段码表,段码a-h顺序接PX7-PX0
unsigned char code Table[]={//共阴数码管段码"0~f-."
0x03,0x9f,0x25,0x0d,
0x99,0x49,0x41,0x1f,
0x01,0x09,0x11,0xc1,
0x63,0x85,0x61,0x71,0xfd,0xfe};
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1