Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Keep up the good work - excellent site - i'd been looking for something like this for ages !..."

Geography

Where in the world do Tek-Tips members come from?

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

Darkstar3000 (Programmer)
24 Apr 12 8:22
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
papadba (MIS)
24 Apr 12 14:19
When i try to go to your link, i get:

Quote:

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.

 
Darkstar3000 (Programmer)
24 Apr 12 16:45
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close