PIC microcontroller drives LED digital tube display program

Publisher:tmgouziLatest update time:2012-12-11 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;*****This program is used to drive the LED digital tube display, and display the numbers 1, 2, 3, 4, 5, 6, 7, 8 on the 8 LED digital tubes in sequence*******
;****http://www.51hei.com The classic program of the microcontroller learning network has been tested. If the common cathode and common anode of the LED digital tube are different, please modify the code value conversion table part

LIST P=18F458
INCLUDE "P18F458.INC"
;The register used
XIANR EQU 0X20
ORG 0X00
GOTO MAIN
ORG 0X30
;****************The following is the code value conversion table********************
CONVERT ADDWF PCL, 1
RETLW 0XC0 ;0, the display segment code is related to the specific hardware connection
RETLW 0XF9 ;1
RETLW 0XA4 ;2
RETLW 0XB0 ;3
RETLW 0X99 ;4
RETLW 0X92 ;5
RETLW 0X82 ;6
RETLW 0XD8 ;7
RETLW 0X80 ;8
RETLW 0X90 ;9
RETLW 0X88 ;A
RETLW 0X83 ;B
RETLW 0XC6 ;C
RETLW 0XA1 ;D
RETLW 0X86 ;E
RETLW 0X8E ;F
RETLW 0X7F ;"."
RETLW 0XBF ;"-"
RETLW 0X89 ;H
RETLW 0XFF ;DARK
RETURN
;**************Initialization subroutine********************
INITIAL
BCF TRISA,5 ;Set RA5 to output mode to output latch signal
BCF TRISC,5
BCF TRISC,3 ;Set SCK and SDO to output mode
BCF INTCON,GIE ;Turn off all interrupts
MOVLW 0XC0
MOVWF SSPSTAT ;Set SSPSTAT register
MOVLW 0X30
MOVWF SSPCON1 ;Set the SPI control mode, allow SSP mode, and
send data along the falling edge of the clock, which
corresponds to the characteristic of "74HC595 when its SCLK jumps from low to high level, the serial input data (DI) is moved into the register"
MOVLW 0X11 ;Assign initial values ​​to the display value register, each value occupies two bytes,
MOVWF XIANR ;Start displaying from 8
RETURN ;Return
; ******************LED digital tube display subroutine **********************
;SPI transmission display submodule
DISPLAY
TRANSMIT CLRF PORTA ;LACK sends low level to prepare for latching
MOVWF SSPBUF ;Start sending
WAIT
BTFSS PIR1, SSPIF
GOTO WAIT ;Wait for the end of sending
BCF PIR1, SSPIF ;Clear interrupt flag
NOP
BSF PORTA, 5 ;Finally, give a latch signal to represent the completion of a display task
RETURN
;********************The main program of the pic microcontroller driving LED display program starts *****************
MAIN NOP
CALL INITIAL ;Call system initialization subroutine
LOOP MOVF XIANR, W
CALL CONVERT ;Find out the display segment code value of XIANR
CALL DISPLAY
DECF XIANR
DECF XIANR ;Decrease the display value by 2, because it is stored by word and read by byte
MOVF XIANR, W
SUBLW 0X01
BTFSS STATUS, Z
GOTO LOOP ;If the displayed number is sent, exit the display
HERE GOTO HERE
END
This program is completed. For the C language version of this program, please open http://www.51hei.com/mcu/558.html

Reference address:PIC microcontroller drives LED digital tube display program

Previous article:PIC microcontroller keyboard scanning assembly program
Next article:PIC18F458 single-chip microcomputer sleep state working mode and activation

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号