#INCLUDE "P16F877.inc"
Reference address:PIC microcontroller converts 2 hexadecimal numbers into 5-digit decimal numbers and displays them
W_TEMP EQU 20H; Actually 20H, A0H, 120H and 1A0H STATUS_TEMP EQU 21H ;Create protection unit in bank 0 PCLATH_TEMP EQU 22H ;Create protection unit in bank 0 ORG 000H GOTO A1 ORG 004H; timing interrupt entry address GOTO ZD01; ORG 0CH A1 MOVLW 1; bit 1 displays the number MOVWF 5AH; MOVLW 2; bit 2 displays the number MOVWF 5BH; MOVLW 3; bit 3 displays the number MOVWF 5CH; MOVLW 4; bit 4 displays the number MOVWF 5DH; MOVLW 4; Display digits MOVWF 40H; MOVLW B'00000001'; bit code MOVWF 41H; MOVLW 5AH; MOVWF FSR ; indirect addressing BSF STATUS, RP0; select body 1 BCF STATUS,RP1; MOVLW 00H; 1:2TMRO ratio MOVWF OPTION_REG; divide by 1/2 BCF STATUS, RP0; BODY0 BCF STATUS,RP1; MOVLW 0FFH; MOVFW TMR0; initial value BCF INTCON, T0IF; clear the timing interrupt flag BSF INTCON, T0IE; open timer interrupt BSF INTCON, GIE; open general interrupt A2 CALL CL0; adjust the hexadecimal number to a 5-digit decimal number NOP; NOP; MOVFW 50H MOVWF 5AH MOVFW 51H MOVWF 5BH MOVFW 52H MOVWF 5CH MOVFW 53H MOVWF5DH GOTO A2 CL0; MOVLW 0H; To display the low digit of the hexadecimal number ; MOVWF 50H; ; MOVLW 00H; ; MOVWF 51H; To display the high digit of the hexadecimal number CALL CL1 MOVLW B'00001111' ANDWF 54H,0 MOVWF 50H MOVLW B'11110000' ANDWF 54H,1 SWAPF 54H,0 MOVWF 51H MOVFW 52H MOVWF 54H MOVLW B'00001111' ANDWF 53H,0 MOVWF 52H MOVLW B'11110000' ANDWF 53H,1 SWAPF 53H,1 RETURN CL1 MOVLW 0; MOVWF 52H; ten thousand digit MOVWF 53H; hundreds and thousands of bits MOVWF 54H; Tens digit MOVWF 55H; carry flag MOVLW 10H; MOVWF 56H;Number of cycles CLRF 57H; CL2 BCF STATUS, C; Clear C RLF 51H,1; Circular left shift RLF 50H,1; Circular left shift BTFSC STATUS, C; Check whether the C bit is high BSF 55H,0; is set to 1 MOVFW 54H; ADDWF 55H,0; PIC does not have ADDC instruction, it can only judge C to add 1 ADDWF 54H,0; add to itself BTFSC STATUS, C; Determine whether there is a carry BSF 57H,7; Set flag if yes BTFSC STATUS, DC; Determine whether there is a carry BSF 57H,3; Set flag if yes CALL DA1; Call the decimal adjustment subroutine MOVWF 54H; store back to 54H CLRF 55H; clear carry flag BTFSC STATUS, C; Check whether the C bit is high BSF 55H,0; is set to 1 MOVFW 53H; ADDWF 55H,0; PIC does not have ADDC instruction, it can only judge C to add 1 ADDWF 53H,0; add to itself BTFSC STATUS,C; BSF 57H,6; BTFSC STATUS, DC; Determine whether there is a carry BSF 57H,2; Set flag if yes CALL DA1; MOVWF 53H; CLRF 55H ; BTFSC STATUS,C; BSF 55H,0; MOVFW 52H; ADDWF 55H,0; ADDWF 52H,0; BTFSC STATUS,C; BSF 57H,5; BTFSC STATUS, C; Determine whether there is a carry BSF 57H,1; Set flag if yes CALL DA1; MOVWF 52H; CLRF 55H; BTFSS 57H,7; Check if the flag has a carry GOTO CL03; No INCF 53H,1; is carry MOVLW 60H; ADDWF 54H,1; add 60H to itself CL03 BTFSS 57H,3; Check if there is a carry flag GOTO CL3; No MOVLW 6H; ADDWF 54H,1; add 6H to itself CL3 BTFSS 57H,6; Check whether the flag has a carry GOTO CL04; INCF 52H,1; is carry MOVLW 60H; ADDWF 53H,1; add 60H to itself CL04 BTFSS 57H,2; Check if there is a carry flag GOTO CL4; No MOVLW 6H; ADDWF 53H,1; add 6H to itself CL4 BTFSS 57H,5; Check if there is a carry flag GOTO CL05; INCF 51H,1; is carry MOVLW 60H; ADDWF 52H,1; add 60H to itself CL05 BTFSS 57H,1; Check if there is a carry flag GOTO CL5; No MOVLW 6H; ADDWF 52H,1; add 6H to itself CL5 CLRF 57H; Clear flag DECFSZ 56H,1; GOTO CL2; RETURN; [page] ;;;**************************************************** *************** ;;; Decimal adjustment ;;;****************************************************** *************** DA1 MOVWF 60H; save the number in W to 60H MOVLW B'00001111'; ANDWF 60H,0; add the number 60H to 00001111 and remove the high 4 bits MOVWF 62H; save the number after removing the high bit to 62H MOVLW 0AH; SUBWF 62H,0; remove the high-order number minus 0AH BTFSS STATUS, DC; Check whether it is greater than 0AH GOTO DA2; otherwise jump ADDLW B'10000'; if it is greater than 0AH, carry MOVWF 62H; add 1 to the upper 4 bits DA2 MOVLW B'11110000'; ANDWF 60H,1; add the number in 60H and 11110000 to remove the lower 4 bits MOVLW 0A0H; SUBWF 60H,0; Subtract 0A0H from the high 4 bits BTFSS STATUS, C; Determine whether it is greater than 0A0H GOTO DA3; No ADDWF 62H,1; if yes, add the difference to the low bit BSF STATUS, C; if yes, set GOTO DA4; DA3 MOVFW 60H; ADDWF 62H,1; otherwise add the high 4 bits to the low 4 bits MOVFW 62H; ANDLW B'11110000'; SUBLW 0A0H ; after adding, check whether it is greater than or equal to 0A0H BCF STATUS,C; BTFSS STATUS,Z; GOTO DA4; otherwise exit MOVLW B'00001111'; yes ANDWF 62H,1; remove the high 4 bits and carry BSF STATUS, C; Set carry flag DA4 MOVFW 62H; RETURN; ;****************************************************** ************* ; Timed interruption of digital tube display program ;****************************************************** ************* ZD01 BTFSS INTCON, T0IF; Determine whether a timing interrupt occurs GOTO ZD03; No, jump out, continue to execute MOVWF W_TEMP;W is backed up to W_TEMP SWAPF STATUS, 0; STATUS half word swap and send W CLRF STATUS; Select body 0 as the current body backup MOVWF STATUS_TEMP; send the original STATUS to the MOVF PCLATH,0;PCLATH sends W MOVWF PCLATH_TEMP;W is sent to the backup register CLRF PCLATH ; set to 0 pages BCF INTCON,T0IF BSF STATUS, RP0; BODY1 BCF STATUS,RP1; MOVLW 0; MOVWF TRISB; RB port is set as output port MOVWF TRISD; RD port is set as output port BCF STATUS, RP0; BODY0 BCF STATUS,RP1; MOVLW 0FFH; MOVWF PORTB; RB port outputs high level MOVLW 0 MOVWF PORTD; RD port outputs low level to clear the screen MOVFW INDF; indirect addressing display data CALL Q1; check the data table MOVWF PORTB; Display the broken code output to port RB INCF FSR,1; Indirect addressing address plus 1 MOVFW 41H ; bit code MOVWF PORTD; bit code output to RD port RLF 41H,0; Process C RLF 41H,1; left shift code DECFSZ 40H,1; Determine whether the 4 bits are displayed GOTO ZD02; otherwise continue to display MOVLW 4; Display digits MOVWF 40H; MOVLW B'00000001'; bit code MOVWF 41H; MOVLW 5AH; MOVWF FSR ; indirect addressing ZD02 MOVLW 0FFH; MOVFW TMR0; reload initial value ; Restore the scene CLRF STATUS; Restore to body 0 MOVF PCLATH_TEMP,0; start to recover data MOVWF PCLATH; restore PCLATH SWAPF STATUS_TEMP,0 MOVWF STATUS; RESTORE STATUS SWAPF W_TEMP,1; put back after half word swap SWAPF W_TEMP,0; then swap half words and send W ZD03 RETFIE ;Interrupt return M001 MOVLW 4 MOVWF 30H M002 MOVLW 248 MOVWF 31H M003 MOVLW 250 MOVWF 32H DECFSZ 32H GOTO $-1 DECFSZ 31H GOTO M003 DECFSZ 30H GOTO M002 RETURN ;************************************************ ; data sheet ;************************************************ Q1 ADDWF PCL,1 RETLW 00C0H ;0 RETLW 00F9H ;1 RETLW 00A4H ;2 RETLW 00B0H ;3 RETLW 0099H ;4 RETLW 0092H ;5 RETLW 0082H ;6 RETLW 00F8H ;7 RETLW 0080H ;8 RETLW 0090H ;9 RETLW 0088H ;A RETLW 0083H ;B RETLW 00C6H ;C RETLW 00A1H ;D RETLW 0086H ;E RETLW 008EH ;F END
Previous article:PIC microcontroller 65535*65535 subroutine
Next article:NRF2401 sending program based on PIC microcontroller
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
Guess you like
- Questions about rotary transformers
- Help, the turn-off speed problem related to the MOS tube drive resistor
- SIwave Chinese Training Manual
- Job hunting after the epidemic
- What are the advantages of machine vision defect detection systems?
- Happy New Year to everyone!
- How can a car's keyless entry system be hacked?
- What is a battery monitoring system (BMS)? What are its main functions? What is the BMS architecture? This article explains
- I want to learn quantum mechanics by myself. What kind of mathematics books should I read first? Thank you.
- What books are there on the desk for reading? [Show it]