bcd七段控制来自汇编语言MPlab的输入

时间:2018-04-05 09:44:21

标签: assembly pic mplab

我正在尝试制作一个BCD七段显示器,它接收4位输入(端口d),并在端口b输出lsb,输出端口c用于msb,我试着做的是我接受输入,我会如果结果为零,则用我存储在w寄存器中的值减去它,因此我将打开或关闭端口b和c处的那些引脚。每次我都会在w寄存器中更改值这里是我的代码在下面的链接代码是make只显示14和15.但它不工作可以任何人帮助我。

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

; TODO ADD INTERRUPTS HERE IF USED             
FIXED EQU 20h       
;INPUT EQU 21h          
;output_LSB EQU 22h         
;output_MSB EQU 23h       
MAIN_PROG CODE ; let linker place main program       
START        

BSF STATUS,RP0          
MOVLW b'00000000'         ;making all pins of port b as output         
MOVWF TRISB         
MOVLW b'00000000'         ;making all pins of port c as output        
MOVWF TRISC           
MOVLW b'00001111'         ;making first 4  pins of port d as input        
MOVWF TRISD       
BCF STATUS,5         
;MOVF PORTD,W        
;MOVWF PORTB        
;CLRF PORTD           
MAIN_LOOP           
BCF STATUS, 2                 ;CLEAR STATUS REGISTER PIN 2             
CLRF PORTD                     ;CLEARING ALL PORT D PINS            
MOVF PORTD, W               ;TAKING VALUES FROM PORTD AND STORING IN W REGISTER          
MOVWF FIXED                  ;MOVING VALUE FROM W REGISTER TO VARIABLE FIXED          
MOVF b'00001111',W        ;MOVING 15('F') TO W REGISTER               
SUBWF FIXED, 0               ;SUBTRACTING VALUE OF W REGISTER FROM FIXED AND         
                             ;STORING RESULT IN W REGISTER                          
BTFSS STATUS,2               ;BIT TEST IF ZERO REGISTER OF STATUS REGISSSTER IF 
                             ;IT IS SET. SKIP NEXT LINE              
MOVLW b'00000101'          ; TRANSFERING 5 ON PORT B "WHICH IS LSB OF OUTPUT"        
MOVWF PORTB           
MOVLW b'00000001'          ;TRANSFERING 1 ON PORT C "WHICH IS MSB OF OUTPUT"             
MOVWF PORTC          
GOTO LINEAR_1              
GOTO MAIN_LOOP             

LINEAR_1               
MOVF PORTD ,W             
MOVF b'00001110',W      ;MOVING 14('E') TO W REGISTER           
SUBWF FIXED, 0             ;SUBTRACTING VALUE OF W REGISTER FROM FIXED AND         
                           ;STORING RESULT IN W REGISTER                  
BTFSS STATUS, 2            ;BIT TEST IF ZERO REGISTER OF STATUS REGISSSTER IF IT 
                           ;IS SET. SKIP NEXT LINE                  
GOTO LINEAR_2                   
MOVLW b'00000100'       ;TRANSFERING 4 ON PORT B "WHICH IS LSB OF OUTPUT"          
MOVWF PORTB                 
MOVLW b'00000001'       ;TRANSFERING 1 ON PORT C "WHICH IS MSB OF OUTPUT"         
MOVWF PORTC              
BSF PORTD,7              
GOTO MAIN_LOOP             

END           

}

enter image description here 在此处输入图像描述

1 个答案:

答案 0 :(得分:1)

好的,从哪里开始。 1)BCD,除非你说的是更高密度的编码,只是从0b00000000到0b00001001(十进制0-9),你想要的是一个十六进制到十进制的转换器。 2)你没有包括linear_2,所以我们没有完整的图片。 3)假设你想要一个十六进制(4位)到十进制(2位)转换器并假设你正在使用某种BCD到7段,你需要做的就是检查端口D是否超过9如果更大,则将MSB设置为1并将lsb设置为val-9,例如:

MOVF  PORTD, W               ; move input to working reg
MOVWF FIXED                  ; move value to ram
SUBLW b'00001001'            ; subtract 9 from input
btfsc STATUS,C               ; check the carry bit, skip if no carry
CALL  ADJUST                 ; Adjust FIXED register    
MOVWF PORTC                  ; save msb to port C
MOVF  FIXED, W               ; reload port D, but from ram to avoid changes
MOVWF PORTB                  ; save LSB
RETURN
ADJUST
MOVF b'00001010',W           ; move dec 10 to W               
SUBWF FIXED, 0               ; subtract and store back to fixed
retlw b'00000001'            ; return with 1 in w 

基本前提是看D的值是否小于或等于9,如果是,则清除MSB并将输入值存储到LSB。如果输入大于9(大于或等于10),则将MSB设置为1并从输入中减去10->将结果存储到LSB。