PIC16F877A ADC汇编:如何在7段显示屏上显示结果

时间:2018-04-26 11:05:12

标签: assembly microcontroller pic seven-segment-display

我正在尝试在PIC16f877a上执行模数转换。好吧问题是当我显示我的结果导致它正常工作但是当我在7段显示我的结果时我有一些无效输出可能是我无法正确地将二进制转换为十进制(“对于BCD转换我我正在使用74ls47“)任何人都可以帮助我。 问候, Haziq。

图片在这里。 enter image description here

RES_VECT  CODE    0x0000            ; processor reset vector              
GOTO    START                   ; go to beginning of program           

; TODO ADD INTERRUPTS HERE IF USED              
CNT0    EQU 0x21 ;            

MAIN_PROG CODE                      ; let linker place main program         

START           

BSF STATUS,RP0         
MOVLW b'00000000'         
MOVWF TRISB         
MOVLW b'11110000'               
MOVWF TRISD            
MOVLW b'00000001'          
MOVWF TRISA              
BCF STATUS,5              

MAIN_LOOP          
CALL ADC_INIT ;INIT ADC MODULE          
CALL ADC_READ ;READ ANALOG VALUE AND STORE TO ANVAL REGISTER          

;OUTPUT ANVAL TO         
 ;==================================            
GOTO MAIN_LOOP               
;========================================================================================            
ADC_INIT       
BSF STATUS,RP0          ;SELECTING BANK 01 FOR ADCON1 REG           
MOVLW b'00001110'       ;LEFT JUSTIFIED, FOcs/8, +VREF=VDD, -VREF=VSS,          
AN0=ANALOG               
MOVWF ADCON1         
BCF STATUS,5            ;GOING BACK TO BANK 00         
MOVLW b'010000001'      ;FOcs/8, A0=ANALOG INPUT,             
MOVWF ADCON0              
RETURN           
;=========================================================================================              
ADC_READ               
BCF STATUS,5            ;SELECTING BANK 00              
BSF ADCON0, 2           ;START CONVERTION PROCESS (WE SET THE GO BIT)         
WAIT:      
BTFSC ADCON0, 2          
GOTO WAIT           ;WAIT FOR CONVERTION TO FINISH (WAIT FOR GO BIT TO CLEAR)             
MOVF ADRESH, W          ;MOVE ADRESH TO W           
MOVWF PORTB         ;SHOWING 8 MOST SIGNIFICANT BITS OF A/D RESULT         
MOVLW 0x06               
MOVWF CNT0              
AGAIN_0:               
BCF STATUS, C           ;WE WANT SHIFT (NOT ROTATE), SO WE CLEAR CARRY        
RLF ADRESL, 1           ;SHIFT LEFT 6 BITS A/D RESULT HIGH BYTE            
DECFSZ CNT0             
GOTO AGAIN_0                            
MOVF ADRESL, W          ;MOVE ADRESH TO W           
MOVWF PORTD         ;SHOWING 2 LEAST SIGNIFICANT BITS OF A/D RESULT          
RETURN              

END

1 个答案:

答案 0 :(得分:0)

您必须在软件中进行HEX到BCD转换才能获得每个数字的BCD值。