need help pic16f84

Discussion in 'Embedded Systems and Microcontrollers' started by toxoid, Oct 7, 2010.

  1. toxoid

    Thread Starter New Member

    Oct 7, 2010
    2
    0
    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.....

    Code ( (Unknown Language)):
    1.  
    2. ;Project: Siren Sound
    3.  
    4. ;*************set up port******
    5.  
    6.     org 0000h        ;This is the start of memory for the program.
    7.     bsf 03h,5         ;Go to Bank 1
    8.     movlw b'11111'    ;taruh "11111" ke W
    9.     movwf 05h         ;RA1, Ra2, Ra3, Ra4, Ra5 input
    10.     bcf 03h,5         ;Go to Bank 0 - the program memory area.
    11.     bsf 03h,7        ;
    12.     movlw 00h        ;
    13.     movwf 06h        ;Rb1 - Rb7 ouput
    14.     bcf 03h, 7        ;
    15.  
    16.  
    17.  
    18. ;*******pemanggilan perintah*********
    19.  
    20.     btfsc 85h, 1    ;cek value di input
    21.     call siren
    22.  
    23.     btfsc 85h, 2    ;cek value di input
    24.     call hee1
    25.  
    26.     ;if 85h = b"00001" then Siren ELSE hee1
    27.  
    28.  
    29.  
    30.  
    31. ;********sirine***************
    32.  
    33. siren     movlw 80h     ;Number of cycles for each tone
    34.         MOVWF 0Eh    ;pindahkan isi register w ke f pada TMR1L    
    35.         MOVWF 10h    ;pindahkan isi register w ke f pada T1CON
    36.         movlw 50h     ;Number of steps
    37.         MOVWF 0Fh     ;File 0F holds the number of steps
    38.         movlw 50h     ;Determines frequency
    39.         MOVWF 0Ch     ;File 0C determines the frequency
    40.  
    41. repeat     MOVF 0C,0     ;File 0C is moved to W
    42.         MOVWF 0D     ;W is moved to file 0D for decrementing
    43.  
    44. on         BSF 06h,7     ;Length of HIGH time to Piezo
    45.         DECFSZ 0D,1
    46.     GOTO on
    47.         MOVWF 0Dh     ;W is moved to file 0D again
    48.  
    49. off     BCF 06h,7     ;Length of LOW time to Piezo
    50.         DECFSZ 0D,1
    51.     GOTO off
    52.         DECFSZ 10h,1     ;Number of cycles for each tone
    53.     GOTO repeat
    54.         DECF 0C,1     ;HIGH and LOW is shortened -tone rises
    55.         INCF 0E,1     ;Increase the number of cycles
    56.         MOVF 0E,0     ;File 0E to W
    57.         MOVWF 10h     ;W to file 10h
    58.         DECFSZ 0F,1     ;Number of steps
    59.     GOTO repeat
    60.     GOTO siren
    61.  
    62. ;*******************hee haw******************
    63.  
    64.  
    65. hee1     movlw 0FFh         ;Number of loops
    66.         MOVWF 14h         ;The loop file
    67. hee2     movlw 0C0h         ;Duration of HIGH
    68.         BSF 06h,7         ;Turn on piezo
    69. hee3     NOP
    70.         DECFSZ 15h,1     ;Create the HIGH time
    71.     GOTO     hee3
    72.         movlw 0C0h         ;Duration of the LOW
    73.         MOVWF 15h         ;The LOW file
    74.         BCF 06h,7         ;Turn off piezo
    75. hee4     NOP
    76.         DECFSZ 15h,1     ;Create the LOW time
    77.     GOTO     hee4
    78.         DECFSZ 14h,1     ;Decrement the loop file
    79.     GOTO     hee2         ;Do more cycles
    80.         movlw 0C0h         ;Number of loops
    81.         MOVWF 14h         ;The loop file
    82. haw1     MOVLW 0FFh
    83.         MOVWF 15h
    84.         BSF 06h,7         ;Turn on piezo
    85. haw3     NOP
    86.         DECFSZ 15h,1     ;Create the LOW time
    87.     GOTO     haw3
    88.         DECFSZ 14h,1     ;Decrement the loop file
    89.     GOTO     haw1         ;Do more cycles
    90.     GOTO     hee1
    91. ;    ENDIF
    92.     END
    93.  
    94.  
     
    Last edited: Oct 7, 2010
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
    .
    .
    Code ( (Unknown Language)):
    1.     list    p=16F84a
    2.     radix    hex
    3.     title "Timelapse"
    4.         #include <p16f84a.inc>
    5.     __config _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
    6.  
    7.  
    8.     cblock 0x0C
    9.     count1
    10.     count2
    11.     count3
    12.     temp1
    13.     endc
    14.     org 0000h
    15.     goto start
    16.  
    17. start bsf STATUS,5
    18.     movlw 1fh
    19.     movwf TRISA
    20.     movlw 60
    21.     movwf TRISB
    22.     bcf STATUS,5
    23.     clrf PORTB
    24.     clrf PORTA
    25.    
    26. pedal1 btfsc PORTA,4
    27.     goto pedal1
    28.     movlw 10
    29.     movwf temp1
    30.     bsf PORTB,7
    31.     call delay1
    32.     bcf PORTB,7
    33.    
    34.    
    35. chk1 btfss PORTA,1
    36.     call incr1
    37.     btfss PORTA,3
    38.     call decr1
    39.     btfss PORTA,0
    40.     goto prog1
    41.     goto chk1
    42. incr1 btfsc PORTA,4
    43.     goto incr1
    44.     movlw 1
    45.     addwf temp1,f
    46.     bsf PORTB,7
    47.     call delay1
    48.     bcf PORTB,7
    49.     return
     
  3. toxoid

    Thread Starter New Member

    Oct 7, 2010
    2
    0
    very need more advice for this things.....because its for my project college....
     
Loading...