单片机实验操作:用8位LED数码管显示“XYZ-NNNN”信息,NNNN=3113

谢谢了 希望大家解答了 奉上20分小小心意
2025-01-31 03:10:42
推荐回答(1个)
回答1:

/* “验证式"?实验十一 八段数码管显示 */
#include
#define LEDLen 6
#define mode 0x03;
#define CAddr XBYTE[0xe100]/* 控制字地址 */
#define OUTBIT XBYTE[0xe101]/* 位控制口 */
#define CLK164 XBYTE[0xe102]/* 段控制口(接164时钟位) */
#define DAT164 XBYTE[0xe102] /* 段控制口(接164数据位) */
#define IN XBYTE[0xe103] /* 键盘读入口 */

unsigned char LEDBuf[LEDLen]; /* 显示缓冲 */
code unsigned char LEDMAP[] = { /* 八段管显示码 */
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
void Delay(unsigned char CNT)
{
unsigned char i;
while (CNT-- !=0)
for (i=100; i !=0; i--);
}
void DisplayLED()
{
unsigned char i, j;
unsigned char Pos;
unsigned char LED;
Pos = 0x20; /* 从左边开始显示 */
for (i = 0; i < LEDLen; i++) {
OUTBIT = 0; /* 关所有八段管 */
LED = LEDBuf[i];
for (j = 0; j < 8; j++) { /*送164*/
if (LED & 0x80) DAT164 = 1; else DAT164 = 0;
CLK164 = CLK164|0x02;
CLK164 = CLK164&0xfd;
LED <<= 1;
}
OUTBIT = Pos; /* 显示一位八段管 */
Delay(1);
Pos >>= 1; /* 显示下一位 */
}
OUTBIT = 0; /* 关所有八段管 */
}
void main()
{
unsigned char i = 0;
unsigned char j;
CAddr = mode;
while(1) {
LEDBuf[0] = LEDMAP[ i & 0x0f];
LEDBuf[1] = LEDMAP[(i+1) & 0x0f];
LEDBuf[2] = LEDMAP[(i+2) & 0x0f];
LEDBuf[3] = LEDMAP[(i+3) & 0x0f];
LEDBuf[4] = LEDMAP[(i+4) & 0x0f];
LEDBuf[5] = LEDMAP[(i+5) & 0x0f];
i++;
for(j=0; j<30; j++)
DisplayLED(); /* 延时 */
}
}
发给你参考下吧
略微修改下就ok了