Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone help me with my PIC program (assembly language)

Status
Not open for further replies.

Darkstar3000

Programmer
Apr 24, 2012
3
GB
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 (see attachment) 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. I can't test it out as I'm currently on vacation so I just need a verification of my work.

Thanks in advance
 
When i try to go to your link, i get:

The website you have attempted to access has been blocked for security reasons.

When you can take time from the festivities, suggest you post the bits of code that you are not comfortable about.

As there are many assemblers, it would be best if you mention which one, running on which platform, using which operating system.

 
Here it is. I'm using MPLAB IDE v8.84 on windows 7.

It's not just a small bit I have problem with, it's the whole thing, I'm not sure if I've written this correctly.

Code:
; WRITTEN BY            ME
; DATE                  23/04/12
; FILE SAVED AS         PicProgram.asm
; DEVICE                PIC16F684
; -----------------------   EQUATES    ------------------------------------
PORTA   EQU     0X05    ;ASSIGN THE PORTA REGISTER TO THE LABEL 'PORTA'
;counters for delay
COUNT1 EQU 20h;
COUNT2 EQU 21h

;------------------------ CONSTANTS -----------------------------------------
;Only defined constants for LEDS i need
;i/o for LEDS
#define TRIS_D0_D1	B'00001111'	; D0 and D1
#define TRIS_D2_D3	B'00101011'	; 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;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D0   
        MOVWF   PORTA   
		
		;Delay:
		decfsz    COUNT1,1       ;Subtract 1 from 00h 
        goto      LOOP0          ;If COUNT is zero, carry on.
        decfsz    COUNT2,1       ;Subtract 1 from 00h
        goto      LOOP0         ;Goto line:  'LOOP0'


; LED 1 ON
LOOP1
        CLRF PORTA;
		MOVLW   TRIS_D0_D1;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D1   
        MOVWF   PORTA  
		
		;Delay:
		decfsz    COUNT1,1        
        goto      LOOP1          
        decfsz    COUNT2,1       
        goto      LOOP1         

; LED 1 & 2 ON
LOOP2
        ;1
        CLRF PORTA;
		MOVLW   TRIS_D0_D1;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D1   
        MOVWF   PORTA  
		
		;2
		CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D2   
        MOVWF   PORTA  
		
		;Delay:
		decfsz    COUNT1,1;      
        goto      LOOP2          
        decfsz    COUNT2,1       
        goto      LOOP2         
		
; LED 3 ON
LOOP3

        CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D3   
        MOVWF   PORTA  
		
		;Delay:
		decfsz    COUNT1,1       
        goto      LOOP3         
        decfsz    COUNT2,1      
        goto      LOOP3        
		
; LED 3 & 1 ON
LOOP4

        CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D3   
        MOVWF   PORTA 
		
		CLRF PORTA;
		MOVLW   TRIS_D0_D1;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D1  
        MOVWF   PORTA 
		
		;Delay:
		decfsz    COUNT1,1       
        goto      LOOP4          
        decfsz    COUNT2,1       
        goto      LOOP4        

; LED 3 & 2 ON		
LOOP5
        CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D3   
        MOVWF   PORTA 
		
		CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D2  
        MOVWF   PORTA 
		
		;Delay:
		decfsz    COUNT1,1       
        goto      LOOP5          
        decfsz    COUNT2,1       
        goto      LOOP5        

; LED 3 & 2 & 1
LOOP6
     
	    CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D3   
        MOVWF   PORTA 
		
		CLRF PORTA;
		MOVLW   TRIS_D2_D3;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D2  
        MOVWF   PORTA 
		
		CLRF PORTA;
		MOVLW   TRIS_D0_D1;
        TRIS    PORTA   
        CLRF    PORTA   
        MOVLW   D1  
        MOVWF   PORTA 
		
		;Delay:
		decfsz    COUNT1,1       
        goto      LOOP6          
        decfsz    COUNT2,1       
        goto      LOOP6      
		
        END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top