need help pic16f84

Thread Starter

toxoid

Joined Oct 7, 2010
2
I am new to pic programming. I want to create a tool that produces 2 votes with the switch and I've tried to make programs and I beg you to check for errors and make suggestions for my program.....

Rich (BB code):
;Project: Siren Sound

;*************set up port******

    org 0000h        ;This is the start of memory for the program.
    bsf 03h,5         ;Go to Bank 1
    movlw b'11111'    ;taruh "11111" ke W
    movwf 05h         ;RA1, Ra2, Ra3, Ra4, Ra5 input
    bcf 03h,5         ;Go to Bank 0 - the program memory area.
    bsf 03h,7        ;
    movlw 00h        ;
    movwf 06h        ;Rb1 - Rb7 ouput
    bcf 03h, 7        ;



;*******pemanggilan perintah*********

    btfsc 85h, 1    ;cek value di input
    call siren

    btfsc 85h, 2    ;cek value di input
    call hee1

    ;if 85h = b"00001" then Siren ELSE hee1




;********sirine***************

siren     movlw 80h     ;Number of cycles for each tone
        MOVWF 0Eh    ;pindahkan isi register w ke f pada TMR1L    
        MOVWF 10h    ;pindahkan isi register w ke f pada T1CON
        movlw 50h     ;Number of steps
        MOVWF 0Fh     ;File 0F holds the number of steps
        movlw 50h     ;Determines frequency
        MOVWF 0Ch     ;File 0C determines the frequency

repeat     MOVF 0C,0     ;File 0C is moved to W
        MOVWF 0D     ;W is moved to file 0D for decrementing

on         BSF 06h,7     ;Length of HIGH time to Piezo
        DECFSZ 0D,1
    GOTO on
        MOVWF 0Dh     ;W is moved to file 0D again

off     BCF 06h,7     ;Length of LOW time to Piezo
        DECFSZ 0D,1
    GOTO off
        DECFSZ 10h,1     ;Number of cycles for each tone
    GOTO repeat
        DECF 0C,1     ;HIGH and LOW is shortened -tone rises
        INCF 0E,1     ;Increase the number of cycles
        MOVF 0E,0     ;File 0E to W
        MOVWF 10h     ;W to file 10h
        DECFSZ 0F,1     ;Number of steps
    GOTO repeat
    GOTO siren

;*******************hee haw******************


hee1     movlw 0FFh         ;Number of loops
        MOVWF 14h         ;The loop file
hee2     movlw 0C0h         ;Duration of HIGH
        BSF 06h,7         ;Turn on piezo
hee3     NOP
        DECFSZ 15h,1     ;Create the HIGH time
    GOTO     hee3
        movlw 0C0h         ;Duration of the LOW
        MOVWF 15h         ;The LOW file
        BCF 06h,7         ;Turn off piezo
hee4     NOP
        DECFSZ 15h,1     ;Create the LOW time
    GOTO     hee4
        DECFSZ 14h,1     ;Decrement the loop file
    GOTO     hee2         ;Do more cycles
        movlw 0C0h         ;Number of loops
        MOVWF 14h         ;The loop file
haw1     MOVLW 0FFh
        MOVWF 15h
        BSF 06h,7         ;Turn on piezo
haw3     NOP
        DECFSZ 15h,1     ;Create the LOW time
    GOTO     haw3
        DECFSZ 14h,1     ;Decrement the loop file
    GOTO     haw1         ;Do more cycles
    GOTO     hee1
;    ENDIF
    END
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
It would be a great improvement if you give things names. Things like PORTB, STATUS, etc are already defined if you use the #include line.
Use CBLOCK to give variables names.
If you make these changes it will make spotting errors much easier.
.
.
.
Just an example.
.
.
Rich (BB code):
    list    p=16F84a
    radix    hex
    title "Timelapse"
        #include <p16f84a.inc>
    __config _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC


    cblock 0x0C
    count1
    count2
    count3
    temp1
    endc
    org 0000h
    goto start

start bsf STATUS,5
    movlw 1fh
    movwf TRISA
    movlw 60
    movwf TRISB
    bcf STATUS,5
    clrf PORTB
    clrf PORTA
    
pedal1 btfsc PORTA,4
    goto pedal1
    movlw 10
    movwf temp1
    bsf PORTB,7
    call delay1
    bcf PORTB,7
    
    
chk1 btfss PORTA,1
    call incr1
    btfss PORTA,3
    call decr1
    btfss PORTA,0
    goto prog1
    goto chk1
incr1 btfsc PORTA,4
    goto incr1
    movlw 1
    addwf temp1,f
    bsf PORTB,7
    call delay1
    bcf PORTB,7
    return
 
Top