单片机
返回首页

四字16*16点阵显示程序

2018-01-07 来源:eefocus

;显示字用查表法,不占内存,用四个16*16共阳LED点阵显示, 
;效果:向上滚动显示字,每次四个,重复循环。 
;R2:行扫描地址(从00-0FH)。 
;R3:滚动显示时控制移动速度,也可控制静止显示的时间。 
;************; 
;中断入口程序; 
;************; 

ORG     0000H 

LJMP    START 
ORG     0003H 
RETI 
ORG     000BH 
LJMP    INTT0 
ORG     0013H 
RETI 
ORG     001BH 
RETI 
ORG     0023H 
RETI 
ORG     002BH 
RETI 

;************; 
; 初始化程序 ; 
;************; 


;************; 
;   主程序   ; 
;************; 

START:          MOV     20H,#00H             ;清标志,00H为1帧扫描结束标志 
                MOV     A,#0FFH              ;端口初始化 
                MOV     P1,A 
                MOV     P2,A 
                MOV     P3,A 
                MOV     P0,A 
                CLR     P1.6            ;串行寄存器打入输出端控制位 
                MOV     TMOD,#01H       ;使用T0作16位定时器,行扫描用。 
                MOV     TH0,#0FCH       ;1ms初值(12MHz) 
                MOV     TL0,#18H 
                MOV     SCON,#00H       ;串口0方式传送显示字节 
                MOV     IE,#82H         ;T0中断允许,总中断允许 
                MOV     SP,#70H 
                LCALL   DIS1            ;显示准备,黑屏,1.5秒 
MAIN:           MOV     DPTR,#TAB 
                LCALL   MOVDISP         ;逐排显示,每次四字) 
                MOV     DPTR,#TAB 
                LCALL   MOVDISP1        ;滚动显示,每排四字) 
                AJMP    MAIN 


;********************; 
; 四字逐排显示子程序 ; 
;********************; 
;每次四字移入移出显示方式,入口时定义好DPTR值 

MOVDISP:        MOV     R1,#6           ;显示6排字,每排四字(R1=排数) 
DISLOOP:        MOV     R3,#100         ;每排显示时间1.6*100=1.6S 
DISMOV:         MOV     R2,#00H         ;第0行开始 
                SETB    TR0             ;开扫描(每次一帧) 
WAITMOV:        JBC     00H,DISMOV1     ;标志为1扫描一帧结束(16毫秒为1帧,每行1毫秒) 
                AJMP    WAITMOV 
DISMOV1:        DJNZ    R3,DISMOV       ;1帧重复显示(控制显示时间) 
                MOV     A,#128          ;显示字指针移一排(每排4字*32=128) 
                ADD     A,DPL           ; 
                MOV     DPL,A 
                MOV     A,#0 
                ADDC    A,DPH 
                MOV     DPH,A 
                DEC     R1              ;R1为0,显示完 
                MOV     A,R1 
                JZ      MOVOUT          ; 
                AJMP    DISLOOP         ; 
MOVOUT:         RET                     ;移动显示结束 

;********************; 
; 四字滚动显示子程序 ; 
;********************; 
;每排四字向上移出显示方式,入口时定义好DPTR值 

MOVDISP1:        MOV     R1,#255          ;向上移动显示6排字,每排四字(R1=排数*16) 
DISLOOP1:        MOV     R3,#10          ;移动速度1.6*10=0.16S 
DISMOV2:         MOV     R2,#00H         ;第0行开始 
                 SETB    TR0             ;开扫描(每次一帧) 
WAITMOV1:        JBC     00H,DISMOV3     ;标志为1扫描一帧结束(16毫秒为1帧,每行1毫秒) 
                 AJMP    WAITMOV1 
DISMOV3:         DJNZ    R3,DISMOV2      ;1帧重复显示(控制移动速度) 
                 INC     DPTR            ;显示字指针移一行(二字节位置) 
                 INC     DPTR 
                 DEC     R1              ;R1为0,显示完 
                 MOV     A,R1 
                 JZ      MOVOUT1         ; 
                 AJMP    DISLOOP1        ; 
MOVOUT1:         RET                     ;移动显示结束 


;*****************; 
; 四个字显示子程序  ; 
;*****************; 
;静止显示表中某四个字 
DIS1:           MOV     R3,#5AH         ;静止显示时间控制(16MS*#=1.6秒) 
DIS11:          MOV     R2,#00H         ;一帧扫描初始值(行地址从00-0FH) 
                MOV     DPTR,#TAB       ;取表首址 
                SETB    TR0             ;开扫描(每次一帧) 
WAIT11:         JBC     00H,DIS111      ;为1,扫描一帧结束 
                AJMP    WAIT11 
DIS111:         DJNZ    R3,DIS11 
                RET 


;************; 
;  扫描程序  ; 
;************; 
;1MS传送一行,每行显示1毫秒,一次传送四个字的某行共8个字节. 

INTT0:          PUSH    ACC 
                MOV     TH0,#0FCH       ;1ms初值重装 
                MOV     TL0,#18H 
                MOV     A,#97           ;指向第四个字行右字节 
                ADD     A,DPL 
                MOV     DPL,A 
                MOV     A,#0 
                ADDC    A,DPH 
                MOV     DPH,A 
                MOV     A,#0 
                MOVC     A,@A+DPTR      ;查表 
                MOV     SBUF,A          ;串口0方式发送 
WAIT:           JBC     TI,GO           ;等待发送完毕 
                AJMP    WAIT            ; 
GO:             MOV     A,DPL           ;指向第四个字行左字节 
                SUBB    A,#1 
                MOV     DPL,A 
                MOV     A,DPH 
                SUBB    A,#0 
                MOV     DPH,A 
                MOV     A,#0 
                MOVC     A,@A+DPTR 
                MOV     SBUF,A 
WAIT1:          JBC     TI,GO1 
                AJMP    WAIT1 

GO1:            MOV     R0,#03H 
MLOOP:          MOV     A,DPL           ;指向前三个字行右字节 
                SUBB    A,#31 
                MOV     DPL,A 
                MOV     A,DPH 
                SUBB    A,#0 
                MOV     DPH,A 
                MOV     A,#0 
                MOVC     A,@A+DPTR      ;查表 
                MOV     SBUF,A          ;串口0方式发送 
WAIT2:          JBC     TI,GO2           ;等待发送完毕 
                AJMP    WAIT2            ; 
GO2:            MOV     A,DPL           ;指向前三个字行左字节 
                SUBB    A,#1 
                MOV     DPL,A 
                MOV     A,DPH 
                SUBB    A,#0 
                MOV     DPH,A 
                MOV     A,#0 
                MOVC     A,@A+DPTR 
                MOV     SBUF,A 
WAIT3:          JBC     TI,GO3 
                AJMP    WAIT3 
GO3:            DJNZ    R0,MLOOP        ;执行三次 


                SETB    P1.7            ;关行显示,准备涮新 
                NOP                     ;串口寄存器数据稳定 
                SETB    P1.6            ;产生上升沿,行数据打入输出端 
                NOP                     ; 
                NOP                     ; 
                CLR     P1.6            ;恢复低电平 
                MOV     A,R2            ;修改显示行地址 
                ORL     A,#0F0H         ;修改显示行地址 
                MOV     R2,A            ;修改显示行地址 
                MOV     A,P1            ;修改显示行地址 
                ORL     A,#0FH          ;修改显示行地址 
                ANL     A,R2            ;修改显示行地址 
                MOV     P1,A            ;修改完成 
                CLR     P1.7            ;开行显示 
                INC     R2              ;下一行扫描地址值 
                INC     DPTR            ; 
                INC     DPTR            ;下一行数据地址 
                MOV     A,R2 
                ANL     A,#0FH 
                JNZ     GO4 
                SETB    00H             ;R2为10H,现为末行扫描,置1帧结束标志 
                MOV     A,DPL           ;指针修正为原帧初值 
                SUBB    A,#32 
                MOV     DPL,A 
                MOV     A,DPH 
                SUBB    A,#0 
                MOV     DPH,A 
                CLR     TR0             ;一帧扫描完,关扫描 
GO4:            POP     ACC 
                RETI                    ;退出 


;***************; 
;  扫描文字表   ; 
;***************; 
; 共五排字,每排四个字,前后为黑屏 
TAB:    DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH     ;黑屏 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH     ;黑屏 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH     ;黑屏 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH     ;黑屏 
        DB  0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH 
        DB  0F7H,0DFH,0F9H,0CFH,0FBH,0BFH,0C0H,007H,0DEH,0F7H,0C0H,007H,0DEH,0F7H,0DEH,0F7H    ;--  文字:  单  -- 
        DB  0C0H,007H,0DEH,0F7H,0FEH,0FFH,000H,001H,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH 
        DB  0FFH,0BFH,0EFH,0BFH,0EFH,0BFH,0EFH,0BBH,0E0H,001H,0EFH,0FFH,0EFH,0FFH,0EFH,0FFH    ;--  文字:  片  -- 
        DB  0E0H,00FH,0EFH,0EFH,0EFH,0EFH,0EFH,0EFH,0DFH,0EFH,0DFH,0EFH,0BFH,0EFH,07FH,0EFH 
        DB  0EFH,0FFH,0EFH,007H,0EFH,077H,001H,077H,0EFH,077H,0EFH,077H,0C7H,077H,0CBH,077H    ;--  文字:  机  -- 
        DB  0ABH,077H,0AFH,077H,06EH,0F7H,0EEH,0F5H,0EDH,0F5H,0EDH,0F5H,0EBH,0F9H,0EFH,0FFH 
        DB  0FFH,0FFH,0F0H,00FH,0F7H,0EFH,0F0H,00FH,0F7H,0EFH,0F0H,00FH,0FFH,0FFH,000H,001H    ;--  文字:  是  -- 
        DB  0FEH,0FFH,0F6H,0FFH,0F6H,007H,0F6H,0FFH,0EAH,0FFH,0DCH,0FFH,0BFH,001H,0FFH,0FFH 
        ; 
        DB  0FFH,0FFH,0C0H,003H,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH     ;--  文字:  工  -- 
        DB  0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,000H,001H,0FFH,0FFH,0FFH,0FFH 
        DB  0FBH,0BFH,0FBH,0BFH,0FBH,0BFH,0FBH,0BBH,0BBH,0B9H,0DBH,0B3H,0DBH,0B7H,0EBH,0AFH     ;--  文字:  业  -- 
        DB  0E3H,0AFH,0EBH,09FH,0FBH,0BFH,0FBH,0BFH,0FBH,0BBH,000H,001H,0FFH,0FFH,0FFH,0FFH 
        DB  0FEH,0FFH,0FEH,0FFH,0DEH,0F7H,0C0H,003H,0DEH,0F7H,0DEH,0F7H,0DEH,0F7H,0DEH,0F7H     ;--  文字:  中  -- 
        DB  0DEH,0F7H,0C0H,007H,0DEH,0F7H,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH 
        DB  0E0H,00FH,0EFH,0EFH,0E0H,00FH,0EFH,0EFH,0E0H,00FH,0FFH,0FFH,000H,001H,0DDH,0FFH    ;--  文字:  最  -- 
        DB  0C1H,003H,0DDH,077H,0C1H,0AFH,0DCH,0DFH,0C1H,0AFH,01DH,071H,0FCH,0FBH,0FDH,0FFH 
        ; 
        DB  0F7H,0DFH,0F7H,0DFH,080H,003H,0F7H,0DFH,0F0H,01FH,0F7H,0DFH,0F0H,01FH,0F7H,0DFH    ;--  文字:  基  -- 
        DB  000H,001H,0F7H,0DFH,0EEH,0E7H,0C0H,011H,03EH,0FBH,0FEH,0FFH,080H,003H,0FFH,0FFH 
        DB  0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,000H,001H,0FCH,07FH,0FCH,0BFH,0FAH,0BFH,0FAH,0DFH    ;--  文字:  本  -- 
        DB  0F6H,0EFH,0EEH,0E7H,0D0H,011H,03EH,0FBH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FFH,0FFH 
        DB  0EFH,07FH,0EFH,07FH,0DFH,07FH,083H,003H,0BAH,0FBH,0BAH,0FBH,0B9H,0FBH,083H,07BH    ;--  文字:  的  -- 
        DB  0BBH,0BBH,0BBH,09BH,0BBH,0DBH,0BBH,0FBH,083H,0FBH,0BBH,0D7H,0BFH,0EFH,0FFH,0FFH 
        DB  0FEH,0FFH,0FFH,07FH,0C0H,003H,0DFH,0FFH,0DDH,0FFH,0DEH,0F7H,0CFH,073H,0D7H,037H   ;--  文字:  应  -- 
        DB  0DBH,06FH,0DBH,06FH,0D9H,0DFH,0BBH,0DFH,0BFH,0BFH,0A0H,001H,07FH,0FFH,0FFH,0FFH 
        ; 
        DB  0FFH,0FFH,0E0H,003H,0EFH,07BH,0EFH,07BH,0EFH,07BH,0E0H,003H,0EFH,07BH,0EFH,07BH   ;--  文字:  用  -- 
        DB  0EFH,07BH,0E0H,003H,0EFH,07BH,0EFH,07BH,0DFH,07BH,0DFH,07BH,0BFH,06BH,07FH,077H 
        DB  0FDH,0FFH,0FEH,0FFH,0FFH,07FH,000H,001H,0FDH,0FFH,0FDH,0FFH,0FCH,00FH,0FDH,0EFH    ;--  文字:  方  -- 
        DB  0FBH,0EFH,0FBH,0EFH,0F7H,0EFH,0F7H,0EFH,0EFH,0EFH,0DFH,06FH,03FH,09FH,0FFH,0FFH 
        DB  0FFH,05FH,0FFH,067H,0FFH,06FH,080H,003H,0FFH,07FH,0FFH,07FH,0FFH,07FH,0C1H,07FH    ;--  文字:  式  -- 
        DB  0F7H,0BFH,0F7H,0BFH,0F7H,0BFH,0F4H,0DFH,0E3H,0DDH,08FH,0EDH,0DFH,0F5H,0FFH,0FBH 
        DB  0F9H,0BFH,0C7H,0AFH,0F7H,0B7H,0F7H,0B7H,0F7H,0BFH,000H,001H,0F7H,0BFH,0F7H,0B7H    ;--  文字:  我  -- 
        DB  0F1H,0D7H,0C7H,0CFH,037H,0DFH,0F7H,0AFH,0F6H,06DH,0F7H,0F5H,0D7H,0F9H,0EFH,0FDH 
        ; 
        DB  0FFH,007H,0C0H,06FH,0EDH,0EFH,0F6H,0DFH,0C0H,001H,0DDH,0FDH,0BDH,0FFH,0C0H,003H    ;--  文字:  爱  -- 
        DB  0FBH,0FFH,0F8H,00FH,0F3H,0DFH,0F4H,0BFH,0EFH,03FH,09CH,0CFH,073H,0F1H,0CFH,0FBH 
        DB  0F7H,0DFH,0F9H,0CFH,0FBH,0BFH,0C0H,007H,0DEH,0F7H,0C0H,007H,0DEH,0F7H,0DEH,0F7H    ;--  文字:  单  -- 
        DB  0C0H,007H,0DEH,0F7H,0FEH,0FFH,000H,001H,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH,0FEH,0FFH 
        DB  0FFH,0BFH,0EFH,0BFH,0EFH,0BFH,0EFH,0BBH,0E0H,001H,0EFH,0FFH,0EFH,0FFH,0EFH,0FFH    ;--  文字:  片  -- 
        DB  0E0H,00FH,0EFH,0EFH,0EFH,0EFH,0EFH,0EFH,0DFH,0EFH,0DFH,0EFH,0BFH,0EFH,07FH,0EFH 
        DB  0EFH,0FFH,0EFH,007H,0EFH,077H,001H,077H,0EFH,077H,0EFH,077H,0C7H,077H,0CBH,077H    ;--  文字:  机  -- 
        DB  0ABH,077H,0AFH,077H,06EH,0F7H,0EEH,0F5H,0EDH,0F5H,0EDH,0F5H,0EBH,0F9H,0EFH,0FFH 
        ; 
        END 


进入单片机查看更多内容>>
相关视频
  • RISC-V嵌入式系统开发

  • SOC系统级芯片设计实验

  • 云龙51单片机实训视频教程(王云,字幕版)

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

精选电路图
  • 光控音效发生器电路

  • 非常简单的150W功放电路图

  • 优化电路板布局的简单方法

  • 如何使用LED驱动器LM3915制作振动计

  • 电谐波图形均衡器示意图

  • 一种构建12V和230V双直流电源的简单方法

    相关电子头条文章