1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with commenting on my code

Discussion in 'Assembly Language Programming (ALP) Forum' started by Darkstar3000, Apr 28, 2012.

  1. Darkstar3000

    Darkstar3000 New Member

    Joined:
    Apr 28, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    So I have this question

    Write an assembly language program for PIC 16F684 to switch ON LEDs to count in binary from 0 to 7. Allow a delay of about 1second between the change.Write the program, verify its operation by executing it

    I wrote the program but I'm not sure if it does the job correctly since I'm not really comfortable with assembly language so can anyone take a look at it and tell me if it's doing what the question specifies and if my comments are correct. I can't test it out as I'm currently on vacation so I just need a verification of my work.

    I'm using MPLAB V8.84
    Here's a link to the asm

    Code:
    ; WRITTEN BY            
    ; DATE                  28/04/12
    ; FILE SAVED AS         BinaryCounter.asm
    ; DEVICE                PIC16F684
    ; FUNCTION				PROGRAM COUNTS FROM 0 TO 7 IN BINARY
    ; -----------------------   EQUATES    ------------------------------------
    PORTA   EQU     05h    ;LABELS THE PORTA REGISTER AS "PORTA"
    ;DELAY COUNTERS 
    COUNT1 EQU 20h;
    COUNT2 EQU 21h
    
    ;------------------------ CONSTANTS -----------------------------------------
    ;IDENTIFIES CONSTANTS FOR REQUIRED LEDS
    ;I/O for LEDS
    #define TRIS_D0_D1	B'00001111'	; TRISIO SETTING FOR D0 AND D1
    #define TRIS_D2_D3	B'00101011'	; TRISIO SETTING FOR D2 AND D3
    
    ; the LEDS
    #define D0	B'00010000'		; D0 LED
    #define D1	B'00100000'		; D1 LED
    #define D2	B'00010000'		; D2 LED
    #define D3	B'00000100'		; D3 LED
    
    ; ----------------------- MAIN PROGRAM ------------------------------------
    START   ORG     0X00    ;'ORG' SPECIFIES THE MEMORY LOCATION OF THE PROGRAM
    
    ; LED 0 ON
    LOOP0
            MOVLW   TRIS_D0_D1;		;PUT 00001111 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA			;CLEAR THE CONTENTS OF PORTA
            MOVLW   D0      		;PUT 00010000 INTO W
            MOVWF   PORTA   		;MOVE W ONTO PORTA 
    		
    		;Delay:
    		decfsz    COUNT1,1       ;DECREASE THE VALUE OF COUNT1 BY 1
    								 ;AND SKIP NEXT LINE IF RESULT IS ZERO
            goto      LOOP0          ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								 ;GO TO LOOP0	
            decfsz    COUNT2,1       ;DECRESE THE VALUE OF COUNT2 BY 1
    								 ;AND SKIP NEXT LINE IF RESULT IT ZERO	
            goto      LOOP0          ;IF COUNT2 IS ZERO, CARRY ON OTHERWISE
    								 ;GO TO LOOP0
    
    
    ; LED 1 ON
    LOOP1
            CLRF    PORTA;			;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D0_D1;     ;PUT 00001111 INTO W	
            TRIS    PORTA   		; 
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D1   			;PUT 00100000 INTO W
            MOVWF   PORTA  			;MOVE W ONTO PORTA
    		
    		;Delay:
    		decfsz    COUNT1,1      ;DECREASE THE VALUE OF COUNT1 BY 1
    								;AND SKIP THE NEXT LINE IF RESULT IS ZERO
            goto      LOOP1         ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP1
            decfsz    COUNT2,1      ;DECREASE THE VALUE OF COUNT2 BY 1 
            goto      LOOP1         ;GO TO LOOP1
    
    ; LED 1 & 2 ON
    LOOP2
            ;1
            CLRF    PORTA;		    ;CLEAR THE CONTENTS OF PORTA 
    		MOVLW   TRIS_D0_D1		;PUT 00001111 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D1   			;PUT 00100000 INTO W	
            MOVWF   PORTA  			;MOVE W ONTO PORTA 
    		
    		;2
    		CLRF    PORTA		    ;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3		;PUT 00101011 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D2   			;PUT 00010000 INTO W
            MOVWF   PORTA  			;MOVE W ONTO PORTA 
    		
    		;Delay:
    		decfsz    COUNT1,1		;DECREASE THE VALUE OF COUNT1 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO
            goto      LOOP2         ;IF COUNT IS ZERO,CARRY ON OTHERWISE 
    								;GO TO LOOP 2 
            decfsz    COUNT2,1      ;DECRESE THE VALUE OF COUNT2 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO 	
            goto      LOOP2         ;IF COUNT2 IS ZERO, CARRY ON OTHERWISE 
    								;GO TO LOOP2
    ; LED 3 ON
    LOOP3
    
            CLRF    PORTA		    ;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3;		;PUT 00101011 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D3   			;PUT 00000100 INTO W 
            MOVWF   PORTA  			;MOVE W ONTO PORTA
    		
    		;Delay:
    		decfsz    COUNT1,1       ;DECREASE THE VALUE OF COUNT1 BY 1
    								 ;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO	
            goto      LOOP3          ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								 ;GO TO LOOP3
            decfsz    COUNT2,1       ;DECREASE THE VALUE OF COUNT2 BY 1 
    								 ;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO
            goto      LOOP3        	 ;IF COUNT2 IS ZERO, CARRY ON OTHERWISE
    								 ;GO TO LOOP3 
    		
    ; LED 3 & 1 ON
    LOOP4
    
            CLRF    PORTA		    ;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3;		;PUT 00101011 INTO W		
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D3   			;PUT 00000100 INTO W
            MOVWF   PORTA 			;MOVE W TO PORTA 
    		
    		CLRF    PORTA				;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D0_D1		;PUT 00001111 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D1  			;PUT 00010000 INTO W
            MOVWF   PORTA 			;MOVE W ONTO PORTA
    		
    		;Delay:
    		decfsz    COUNT1,1      ;DECREASE THE VALUE OF COUNT1 BY 1 
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO	
            goto      LOOP4         ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP4
            decfsz    COUNT2,1      ;DECREASE THE VALUE OF COUNT2 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO
            goto      LOOP4         ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP4
    
    ; LED 3 & 2 ON		
    LOOP5
            CLRF    PORTA			;CLEAR THE CONTENTS OF PORTA				
    		MOVLW   TRIS_D2_D3		;PUT 00101011 INTO W	
            TRIS    PORTA   		;	
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D3   			;PUT 00000100 INTO W
            MOVWF   PORTA 			;MOVE W TO PORTA
    		
    		CLRF    PORTA			;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3;		;PUT 00101011 INTO W 
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D2  			;00010000
            MOVWF   PORTA 			;MOVE W TO PORTA 
    		
    		;Delay:
    		decfsz    COUNT1,1      ;DECREASE THE VALUE OF COUNT1 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO
            goto      LOOP5         ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP5 
            decfsz    COUNT2,1      ;DECREASE THE VALUE OF COUNT2 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO 	
            goto      LOOP5        	;IF COUNT2 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP5
    
    ; LED 3 & 2 & 1
    LOOP6
         
    	    CLRF    PORTA			;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3		;PUT 00101011 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D3   			;PUT 00000100 INTO W
            MOVWF   PORTA 			;MOVE W TO PORTA
    		
    		CLRF    PORTA			;CLEAR THE CONTENTS OF PORTA
    		MOVLW   TRIS_D2_D3		;PUT 00101011 INTO W
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR THE CONTENTS OF PORTA
            MOVLW   D2  			;PUT 00010000 INTO W
            MOVWF   PORTA 			;MOVE W TO PORTA 
    		
    		CLRF    PORTA			;CLEAR CONTENTS OF PORTA	
    		MOVLW   TRIS_D0_D1		;PUT 00001111 INTO W	 
            TRIS    PORTA   		;
            CLRF    PORTA   		;CLEAR CONTENTS OF PORTA
            MOVLW   D1  			;PUT 00010000 INTO W
            MOVWF   PORTA 			;MOVE W TO PORTA 
    		
    		;Delay:
    		decfsz    COUNT1,1      ;DECREASE THE VALUE OF COUNT1 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO 
            goto      LOOP6         ;IF COUNT1 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP6
            decfsz    COUNT2,1      ;DECREASE THE VALUE OF COUNT2 BY 1
    								;AND SKIP THE NEXT LINE IF THE RESULT IS ZERO 	
            goto      LOOP6         ;IF COUNT2 IS ZERO, CARRY ON OTHERWISE
    								;GO TO LOOP6
    
    		
    
            END
    
    If the code is messy I've attached a zip file with the asm
     

    Attached Files:

  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Strange request. The assignment says "verify its operation by executing it" - so why don't you do that?

    "I wrote the program" Are you sure about that? It seems quite advanced code for someone who is "not comfortable with assembly language" and thinks "execute it" means "post it on a forum for people to comment on".

    Methinks the task is actually to modify the given program so that it works as described. Correct?
     
  3. Darkstar3000

    Darkstar3000 New Member

    Joined:
    Apr 28, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0

    Well I don't have a PIC so I can't check if it works correctly. Also I put it together based on the samples we were given throughout the weeks, most of it is just leeched from these examples and I don't really have an idea on what's going on.
     

Share This Page