help me with using pic16f873

Discussion in 'The Projects Forum' started by sammymtech, Nov 2, 2010.

  1. sammymtech

    Thread Starter New Member

    Sep 19, 2010
    2
    0
    hi i am mtech student. i tried to burn the the following program into pic using ezpic software during the burning process the led in the burner goes red and when i use the pic in the board it didnt work properly. i have tried to use pic16f873 simply to use as a 4bit remote control by initialising 4bits of the portb as input and other 4 bits as output. is there any problem in program??
    here is the program

    list p=16f873
    include <p16f873.inc>
    status equ 03h
    portb equ 06h
    trisb equ 86h
    org 0x00
    start
    bcf status,6
    bsf status,5
    movlw 0fh
    movwf trisb
    bcf status,5
    clrf portb
    fir
    btfss portb,0
    goto sec
    goto sw1
    sec
    btfss portb,1
    goto thir
    goto sw2
    thir
    btfss portb,2
    goto fore
    goto sw3
    fore
    btfss portb,3
    goto fir
    goto sw4
    sw1
    btfss portb,4
    goto on_1
    bcf portb,4
    goto fir
    on_1
    bsf portb,4
    goto fir
    sw2
    btfss portb,5
    goto on_2
    bcf portb,5
    goto fir
    on_2
    bsf portb,5
    goto fir
    sw3
    btfss portb,6
    goto on_3
    bcf portb,6
    goto fir
    on_3
    bsf portb,6
    goto fir
    sw4
    btfss portb,7
    goto on_4
    bcf portb,7
    goto fir
    on_4
    bsf portb,7
    goto fir
    goto start
    end
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    When posting source code, you should either attach it as a .txt file, or use the [ code] [ /code] blocks (no spaces) to preserve your formatting; otherwise it all gets left-justified.

    I've re-formatted your code for you.

    Code ( (Unknown Language)):
    1.     list p=16f873
    2.     include <p16f873.inc>
    3.     status equ 03h
    4.     portb equ  06h
    5.     trisb equ  86h
    6.     org 0x00
    7. start
    8.     bcf status,6
    9.     bsf status,5
    10.     movlw 0fh
    11.     movwf trisb
    12.     bcf status,5
    13.     clrf portb
    14. fir
    15.     btfss portb,0
    16.     goto sec
    17.     goto sw1
    18. sec
    19.     btfss portb,1
    20.     goto thir
    21.     goto sw2
    22. thir
    23.     btfss portb,2
    24.     goto fore
    25.     goto sw3
    26. fore
    27.     btfss portb,3
    28.     goto fir
    29.     goto sw4
    30. sw1
    31.     btfss portb,4
    32.     goto on_1
    33.     bcf portb,4
    34.     goto fir
    35. on_1
    36.     bsf portb,4
    37.     goto fir
    38. sw2
    39.     btfss portb,5
    40.     goto on_2
    41.     bcf portb,5
    42.     goto fir
    43. on_2
    44.     bsf portb,5
    45.     goto fir
    46. sw3
    47.     btfss portb,6
    48.     goto on_3
    49.     bcf portb,6
    50.     goto fir
    51. on_3
    52.     bsf portb,6
    53.     goto fir
    54. sw4
    55.     btfss portb,7
    56.     goto on_4
    57.     bcf portb,7
    58.     goto fir
    59. on_4
    60.     bsf portb,7
    61.     goto fir
    62.     goto start
    63.     end
    64.  
     
  3. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    I have seen plenty of PIC code like this and it is very hard to know if it works or what's wrong with it if it doesn't.

    Well written code has plenty of comments - possibly one on every line. Another good idea is to draw a detailed flowchart. In fact I usually start with a flowchart and then turn it into well commented code!
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    JDT echoes my sentiments exactly. Assembler is one of the most difficult languages to understand. Documenting what each line is supposed to do, will be a great help in determining what the problem is.
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Also what are the configuration word settings? Can you show how the switches and LEDs are connected.
     
  6. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Assembly mnemonic by itself is not difficult to understand.

    However, the reason/logic why the writer choose to use one particular mnemonic would often take a long time for another person to figure out. This is assuming the software worked correctly and comments are there.

    In the case when there are logical errors in codes without comments, e.g. setting bit6 instead of bit5, shifting left instead of shifting right etc... it is next to impossible to find as someone else often don't know what the writer is thinking at that particular moment.
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Code ( (Unknown Language)):
    1. sw1
    2.     btfss portb,4
    3.     goto on_1
    4.     bcf portb,4
    5.     goto fir
    6. on_1
    7.     bsf portb,4
    8.     goto fir
    I think you should replace both "goto fir" with "goto sec" because otherwise it might not get to "sec". Make similar changes to the rest.
    Unless that was the intention.
     
  8. sammymtech

    Thread Starter New Member

    Sep 19, 2010
    2
    0
    here i am posting the flowchart of my work pls help me out..
     
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Does this program run in the MPLAB simulation?
     
  10. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You don't need to redefine the ports as they are already defined in the include file.
     
Loading...