最新三星单片机应用

S3F9454驱动三位LED数码显示屏编程示例

Published:2010.10.13 NewsFrom:ZHANHENG TECHNOLOGY(HK)CO.,LTD/SHENZHEN ZHANHENGLONG ELECTRONIC CO,LTD Views:

S3F9454驱动三位数码LED显示示例
;注意: 直接使用本例程须安装我站的位操作小插件,以实现OPENICE
;下为S3F9454增加四条位操作指令功能
;点击这里查看位操作插件安装及使用方法
;-----------------------------------------------------
;S3F9454,FOSC=3.2MHZ
.include "s3c9454.reg"
;-----------------------------------------------------
;RAM定义
LED_LOOP EQU 00H
DIGITA EQU 01H
DIGITB EQU 02H
DIGITC EQU 03H
SEG_A EQU 04H
SEG_B EQU 05H
SEG_C EQU 06H
;-----------------------------------------------------
;各输入输出I/O口功能定义:
;P0各端口功能定义
;P0.3----LEDA_CTRL,数码管显示A位控制线,输出
;P0.4----LEDB_CTRL,数码管显示B位控制线,输出
;P0.5----LEDC_CTRL,数码管显示C位控制线,输出
LEDA_CTRL BIT P0.3
LEDB_CTRL BIT P0.4
LEDC_CTRL BIT P0.5
;-----------------------------------------------
;P2各端口功能定义
;P2.0---P2.6分别为数码管显示段A,B,C,D,E,F,G(输出)
;----------------------------------------------
A_SEG BIT P2.0
B_SEG BIT P2.1
C_SEG BIT P2.2
D_SEG BIT P2.3
E_SEG BIT P2.4
F_SEG BIT P2.5
G_SEG BIT P2.6
;--------------------------------------------------------
        ORG 0000H ;S3C9454 has only one interrupt vector
        VECTOR 00H,INT_9454
;-----------------------------------------------------------
;SMART OPTION
        ORG 003CH
        DB 00H
        DB 00H
        DB 0E7H
        DB 03H
;----------------------------------------------------------------
;digit display code rom define
;----------------------------
DIGIT_CODE:
        DB 10111111B ;'0'code
        DB 10000110B ;'1'code
        DB 11011011B ;'2'code
        DB 11001111B ;'3'code
        DB 11100110B ;'4'code
        DB 11101101B ;'5'code
        DB 11111101B ;'6'code
        DB 10000111B ;'7'code
        DB 11111111B ;'8'code
        DB 11101111B ;'9'code
;-------------------------------------------------------------------
        ORG 0100H

RESET: ;-------------------------
        ;follow must set
        DI ;disable interrupt
        LD BTCON,#10100011B ;Watch-dog disable
        LD CLKCON,#00011000B ;selet non-divided CPU clock
        LD SP,#0C0H ;Stack pointer must be set as 0C0H
        ;-------------------------
        LD P0PND,#00H ;P0/INT disable
        LD P0CONH,#00011010B ;set P0.7 as input with pull-up
                                                ;set P0.6 as PWM output
                                                ;set P0.5,P0.4 as push-pull output
        LD P0CONL,#10101111B ;set P0.0,P0.1 as A/D input
                                                ;set P0.2,P0.3 as push-pull output
     
        LD P1CON,#00001010B ;set P1.0 as push-pull output
                                                ;set P1.1 as push-pull output
        LD P2CONH,#01001010B ;set P2.6 as push-pull output
                                                ;set P2.5 as push-pull output
                                                ;set P2.4 as push-pull output
        LD P2CONL,#10101010B ;set P2.3 as push-pull output
                                                ;set P2.2 as push-pull output
                                                ;set P2.1 as push-pull output
                                                ;set P2.0 is T0 match output
        ;start initiated all ram
START_INIT:
        EI
        LD SEG_A,#00H
        LD SEG_B,#00H
        LD SEG_C,#00H
        LD LED_LOOP,#01H
              
        LD T0CON,#01001010B ;set T0 input clock=Fosc/256
        LD T0DATA,#32H ;set T0 interrup every 4ms
        
;---------------------------------------------------
;以下三位数码屏循环显示'000','111','222'...'999'
REPEAT:
        LD R15,#00H
_TEST:
        LD DIGITA,R15
        LD DIGITB,R15
        LD DIGITC,R15
        PUSH R15
        DI
        CALL DIGIT_CONVERT
        EI
        ;延时
        LD R10,#250
DELAYA:
        LD R11,#250
DELAYB:
        DEC R11
        JR NZ,DELAYB
        DEC R10
        JR NZ,DELAYA
        ;增量
        POP R15
        INC R15
        CP R15,#0AH
        JR ULT,_TEST
        JR REPEAT
;--------------------------------------------------------------------
DIGIT_CONVERT:
        LD R0,#00H
        LD R1,#DIGIT_CODE
        ADD R1,DIGITA
        LDC R10,@RR0
        LD SEG_A,R10
        
        LD R1,#DIGIT_CODE
        ADD R1,DIGITB
        LDC R10,@RR0
        LD SEG_B,R10
        
        LD R1,#DIGIT_CODE
        ADD R1,DIGITC
        LDC R10,@RR0
        LD SEG_C,R10
        RET
;--------------------------------------------------------------------
LED_SCAN:
        ;首先关闭所有位显示
        CLRBIT LEDA_CTRL ;低电平为关闭显示
        CLRBIT LEDB_CTRL
        CLRBIT LEDC_CTRL
        ;移位屏显指针,并根据指针值对相应位进行扫描显示
        RL LED_LOOP
        TM LED_LOOP,#01H
        JR NZ,SCAN_LEDA
        TM LED_LOOP,#02H
        JR NZ,SCAN_LEDB
        TM LED_LOOP,#04H
        JR NZ,SCAN_LEDC
        
        LD LED_LOOP,#01H
SCAN_LEDA:
        LD P2,SEG_A
        SETBIT LEDA_CTRL
        JR SCAN_BACK
SCAN_LEDB:
        LD P2,SEG_B
        SETBIT LEDB_CTRL
        JR SCAN_BACK
SCAN_LEDC:
        LD P2,SEG_C
        SETBIT LEDC_CTRL
SCAN_BACK:
        RET
;------------------------------------------------------------
;interrupt service routine
;TMR0 每4MS 中断一次
INT_9454:
        AND T0CON,#11111010B ;clear t0 interrupt pending
                                                ;clear T0CON.3
        CALL LED_SCAN ;scan led display
        
END_INT:
        LD BTCON,#02H ;Clear watch-dog
        IRET
;-------------------------------------------------------------

Development tools for MCU
Programming console for MCU
Development tools for ARM
the C compiler
Contact
Samsung SCM:

ic168@zh-ic.COM

Development Tools:

B6078S@163.com

Site suggestions:

zh-ic@163.com

  Service
 MSN