Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

down here an assembly language program using 16f877 instruction set for ADC, Ple

ID: 2084962 • Letter: D

Question

down here an assembly language program using 16f877 instruction set for ADC, Please do explain the code code should be commented to explained all the Ideas, and draw a flow chart of the process.

the Code:

count   EQU   30  
ADhi   EQU   31  
ADlo   EQU   32  
thos   EQU   33  
huns   EQU   34  
tens   EQU   35  
ones   EQU   36  

;----------------------------------------------------------
; PROGRAM BEGINS
;----------------------------------------------------------

   ORG   0       ; Default start address
   NOP           ; required for ICD mode

;----------------------------------------------------------  
; Port & display setup

   BANKSEL   TRISC       
   CLRF   PORTD      
   MOVLW   B'10000011'  
   MOVWF   ADCON1      
              
              

   BANKSEL PORTC        ; choose bank sell 1  
   CLRF   PORTD       ; set port D outputs
   MOVLW   B'01000001'   ;osc/8, analog channel 0, A/D on.

   MOVWF   ADCON0       ; move 0x41 to ADCON1 register

   CALL   inid       ;   Initialise the LCD

;----------------------------------------------------------
; MAIN LOOP
;----------------------------------------------------------

start   CALL   getADC   ; start the counter loop  
        CALL   con4   ; start the conversion programe.  
        CALL   putLCD      
       GOTO   start      

;-----------------------------------------------------------
; SUBROUTINES
;-----------------------------------------------------------
; Read ADC input and store
;-----------------------------------------------------------

getADC   MOVLW   007      
        MOVWF   count

down   DECFSZ   count,1      
        GOTO   down  

       BSF   ADCON0,GO   
  
wait   BTFSC   ADCON0,GO   
        GOTO   wait
        RETURN              
  
;-----------------------------------------------------------
; Convert 10-bit input to decimal
;-----------------------------------------------------------

con4   MOVF   ADRESH,W   
       MOVWF   ADhi      
       BANKSEL   ADRESL         
       MOVF   ADRESL,W   
       BANKSEL ADRESH      
       MOVWF   ADlo      

; Multiply by 4 for result 0 - 4096 by shifting left.........

   BCF   STATUS,C          
   RLF   ADlo,1               

   BTFSS   STATUS,C  
   GOTO   rot1      
   BSF   STATUS,C  
rot1   RLF   ADhi,1      

   BCF   STATUS,C  
   RLF   ADlo,1      
   BTFSS   STATUS,C  
   GOTO   rot2      
   BSF   STATUS,C  
rot2   RLF   ADhi,1      


; Clear BCD registers........................................

clrbcd   CLRF   thos      
   CLRF   huns      
   CLRF   tens      
   CLRF   ones      


; Calclulate thousands low byte .............................

tholo   MOVF   ADhi,F      
   BTFSC   STATUS,Z  
   GOTO   hunlo      

   BSF   STATUS,C  
   MOVLW   0xE8      
   SUBWF   ADlo,1      
   BTFSC   STATUS,C  
   GOTO   thohi      
   DECF   ADhi,1      

; Calculate thousands high byte..............................
  
thohi   BSF   STATUS,C  
   MOVLW   003      
   SUBWF   ADhi,1      
   BTFSC   STATUS,C  
   GOTO   incth          
   ADDWF   ADhi,1      

; Restore remainder when done ...............................

   BCF   STATUS,C  
   MOVLW   0E8      
   ADDWF   ADlo,1      
   BTFSC   STATUS,C  
   INCF   ADhi,1  
   GOTO   hunlo      

; Increment thousands digit and repeat.......................

incth   INCF   thos,1      
   GOTO   tholo      
; Calclulate hundreds .......................................

hunlo   MOVLW   064      
   BSF   STATUS,C  
   SUBWF   ADlo,1      
   BTFSC   STATUS,C  
   GOTO   inch      
  
   MOVF   ADhi,F      
   BTFSC   STATUS,Z  
   GOTO   remh      
   DECF   ADhi,1      
inch   INCF   huns,1      
   GOTO   hunlo      

remh   ADDWF   ADlo,1      


; Calculate tens digit......................................

subt   MOVLW   D'10'      
   BSF   STATUS,C  
   SUBWF   ADlo,1      
   BTFSS   STATUS,C  
   GOTO   remt      
   INCF   tens,1      
   GOTO   subt      


; Restore remainder.........................................

remt   ADDWF   ADlo,1      
   MOVF   ADlo,W      
   MOVWF   ones      

   RETURN          


;-----------------------------------------------------------
; Output to display
;-----------------------------------------------------------

putLCD   BCF   Select,RS  
   MOVLW   080      
   CALL   send      
   BSF   Select,RS  
; Convert digits to ASCII and display.......................

   MOVLW   030      
   ADDWF   thos,1      
   ADDWF   huns,1      
   ADDWF   tens,1      
   ADDWF   ones,1      

   MOVF   thos,W      
   CALL   send      
   MOVLW   '.'      
   CALL   send      
   MOVF   huns,W      
   CALL   send      
   MOVF   tens,W      
   CALL   send      
   MOVF   ones,W      
   CALL   send      
   MOVLW   ' '      
   CALL   send      
   MOVLW   'V'      
   CALL   send      
   MOVLW   'o'      
   CALL   send      
   MOVLW   'l'      
   CALL   send      
   MOVLW   't'      
   CALL   send      
   MOVLW   's'      
   CALL   send      

   RETURN         

Explanation / Answer

PIC16f877 ADC PROGRAM:

count EQU 30
ADhi EQU 31
ADlo EQU 32
thos EQU 33
huns EQU 34
tens EQU 35
ones EQU 36
;----------------------------------------------------------
; PROGRAM BEGINS
;----------------------------------------------------------
ORG 0 ; Default start address
NOP ; required for ICD mode
;----------------------------------------------------------
; Port & display setup
BANKSEL TRISC   
CLRF PORTD
MOVLW B'10000011'
MOVWF ADCON1
  
  
BANKSEL PORTC ; choose bank sell 1
CLRF PORTD ; set port D outputs
MOVLW B'01000001' ;osc/8, analog channel 0, A/D on.
MOVWF ADCON0 ; move 0x41 to ADCON1 register
CALL inid ; Initialise the LCD
;----------------------------------------------------------
; MAIN LOOP
;----------------------------------------------------------
start CALL getADC ; start the counter loop
CALL con4 ; start the conversion programe.
CALL putLCD
GOTO start
;-----------------------------------------------------------
; SUBROUTINES
;-----------------------------------------------------------
; Read ADC input and store
;-----------------------------------------------------------
getADC MOVLW 007 ; Move constant 007 to W
MOVWF count ; Store 007 in count
down DECFSZ count,1 ; loop 7 times to generate delay
GOTO down
BSF ADCON0,GO ; Starts the A/D conversion
  
wait BTFSC ADCON0,GO ;Wait for the conversion to complete
GOTO wait
RETURN ; return with result stored in ADRESL
  
;-----------------------------------------------------------
; Convert 10-bit input to decimal
;-----------------------------------------------------------
con4 MOVF ADRESH,W ; copying the ADRESH to ADhi
MOVWF ADhi
BANKSEL ADRESL   
MOVF ADRESL,W ; copying the ADRESL to ADlo
BANKSEL ADRESH
MOVWF ADlo
; Multiply by 4 for result 0 - 4096 by shifting left.........
BCF STATUS,C ; making carry 0 so that left rotation will have 0 in LSB
RLF ADlo,1 ; multiplying ADlo by 2 using left shiftting through carry   
BTFSS STATUS,C ; checkiing if any carry was generated
GOTO rot1 ; if no carry, then leave C as it is
BSF STATUS,C ; else set C to 1 so that left rotation will have 1 in LSB
rot1 RLF ADhi,1 ; multiplying ADhi by 2 using left shiftting through carry   
BCF STATUS,C ; making carry 0 so that left rotation will have 0 in LSB
RLF ADlo,1 ; multiplying ADlo by 2 again   
BTFSS STATUS,C
GOTO rot2
BSF STATUS,C
rot2 RLF ADhi,1 ; multiplying ADhi by 2 again

; Clear BCD registers........................................
clrbcd CLRF thos ; set thous to 0   
CLRF huns ; set huns to 0
CLRF tens ; set tens to 0
CLRF ones ; set ones to 0

; Calclulate thousands low byte .............................
tholo MOVF ADhi,F
BTFSC STATUS,Z
GOTO hunlo
BSF STATUS,C
MOVLW 0xE8
SUBWF ADlo,1
BTFSC STATUS,C
GOTO thohi
DECF ADhi,1
; Calculate thousands high byte..............................
  
thohi BSF STATUS,C
MOVLW 003
SUBWF ADhi,1
BTFSC STATUS,C
GOTO incth
ADDWF ADhi,1
; Restore remainder when done ...............................
BCF STATUS,C
MOVLW 0E8
ADDWF ADlo,1
BTFSC STATUS,C
INCF ADhi,1
GOTO hunlo
; Increment thousands digit and repeat.......................
incth INCF thos,1
GOTO tholo
; Calclulate hundreds .......................................
hunlo MOVLW 064
BSF STATUS,C
SUBWF ADlo,1
BTFSC STATUS,C
GOTO inch
  
MOVF ADhi,F
BTFSC STATUS,Z
GOTO remh
DECF ADhi,1
inch INCF huns,1
GOTO hunlo
remh ADDWF ADlo,1

; Calculate tens digit......................................
subt MOVLW D'10'
BSF STATUS,C
SUBWF ADlo,1
BTFSS STATUS,C
GOTO remt
INCF tens,1
GOTO subt

; Restore remainder.........................................
remt ADDWF ADlo,1
MOVF ADlo,W
MOVWF ones
RETURN

;-----------------------------------------------------------
; Output to display
;-----------------------------------------------------------
putLCD BCF Select,RS
MOVLW 080
CALL send
BSF Select,RS
; Convert digits to ASCII and display.......................
MOVLW 030
ADDWF thos,1
ADDWF huns,1
ADDWF tens,1
ADDWF ones,1
MOVF thos,W
CALL send
MOVLW '.'
CALL send
MOVF huns,W
CALL send
MOVF tens,W
CALL send
MOVF ones,W
CALL send
MOVLW ' '
CALL send
MOVLW 'V'
CALL send
MOVLW 'o'
CALL send
MOVLW 'l'
CALL send
MOVLW 't'
CALL send
MOVLW 's'
CALL send
RETURN