#include<reg51.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int uchar code Table_of_Digits[]= { 0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0 0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1 0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2 0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3 0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4 0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5 0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6 0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8 0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 //9 }; uchar i=0,t=0,Num_Index; //主程序 void main() { P3=0x80; //P3最高位为0,控制位选 Num_Index=0; //从0开始显示 TMOD=0x00; //T0方式0 TH0=(8192-2000)/32; //2ms定时 TL0=(8192-2000)%32; IE=0x82; TR0=1; //启动T0 while(1); } //T0中断函数 void LED_Screen_Display() interrupt 1 { TH0=(8192-2000)/32; //恢复初值 TL0=(8192-2000)%32; P0=0xff; //输出位码和段码 P0=~Table_of_Digits[Num_Index*8+i]; //补码 P3=_crol_(P3,1); if(++i==8) i=0; //每屏一个数字由8个字节构成 if(++t==250) //每个数字刷新显示一段时间 { t=0; if(++Num_Index==10) Num_Index=0; //显示下一个数字 } }
时间: 2023-08-28 15:03:26 浏览: 89
eeprom.rar_EEPROM int_Unsigned_intrins.h_site:www.pudn.com_换头文件e
下面是对应的汇编语言代码:
```
; 包含头文件
include reg51.inc
include intrins.inc
; 定义宏
#define uchar unsigned char
#define uint unsigned int
; 数码管显示的数字表
Table_of_Digits: db 0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00 ; 0
db 0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00 ; 1
db 0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00 ; 2
db 0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00 ; 3
db 0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00 ; 4
db 0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00 ; 5
db 0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00 ; 6
db 0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00 ; 7
db 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00 ; 8
db 0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 ; 9
; 定义变量
i: db 0 ; i 初始值为 0
t: db 0 ; t 初始值为 0
Num_Index: db 0 ; Num_Index 初始值为 0
; 主程序
main:
mov P3, #0x80 ; P3最高位为0,控制位选
mov Num_Index, #0 ; 从0开始显示
mov TMOD, #0x00 ; T0方式0
mov TH0, #(8192-2000)/32 ; 2ms定时
mov TL0, #(8192-2000)%32
mov IE, #0x82 ; 开启中断
setb TR0 ; 启动T0
loop:
jmp loop ; 无限循环
; T0中断函数
LED_Screen_Display:
mov TH0, #(8192-2000)/32 ; 恢复初值
mov TL0, #(8192-2000)%32
mov P0, #0xff ; 输出位码和段码
mov A, Num_Index
mul AB, #8
add A, i
mov DPTR, #Table_of_Digits
add DPTR, A
mov A, @DPTR
cpl A ; 补码
mov P0, A
mov A, P3
rl A
mov P3, A
inc i
cjne i, #8, no_reset_i ; 每屏一个数字由8个字节构成
mov i, #0 ; 重置 i
inc t
cjne t, #250, no_reset_Num_Index ; 每个数字刷新显示一段时间
mov t, #0 ; 重置 t
inc Num_Index
cjne Num_Index, #10, no_reset_Num_Index
mov Num_Index, #0
no_reset_Num_Index:
no_reset_i:
reti
```
阅读全文