need help coding pic16f84a scanning of switches

Discussion in 'Embedded Systems and Microcontrollers' started by ernestclydeachua, Aug 26, 2012.

  1. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    hello i need help coding
    i want to produce an out put like this
    [​IMG]

    ive done some programming

    and changed the ports it runs on simulation but wont run in the circuit it cause my LEDs to turn off and on when i energize a single switch

    heres the code
    Code ( (Unknown Language)):
    1. ;RB0 controls RB7 and RA0
    2. ;RB0=0 then RB4 and RA0=0, else it will be 1 when RB0=1
    3. ;RB1 controls RB5 and RA1
    4. ;RB2 controls RB6 and RA2
    5. ;RB3 controls RB7 and RA3
    6.  
    7.     list      p=16F84A            ; list directive to define processor
    8.     #include <p16F84A.inc>        ; processor specific variable definitions
    9.     errorlevel -302, -207  
    10.  
    11.     __config _CP_OFF &_XT_OSC & _PWRTE_ON & _WDT_OFF
    12.  
    13. cntr1   equ h'21'
    14. cntr2   equ h'22'
    15. bfr1    equ     23h
    16.  
    17.     ORG     0x000             ; processor reset vector
    18.     goto    main              ; go to beginning of program
    19.  
    20.     ORG     0x004             ; interrupt vector location
    21.     nop
    22.     retfie                    ; return from interrupt
    23.  
    24. main:
    25.     bsf STATUS,RP0
    26.     movlw   b'00000000'
    27.     movwf   TRISA
    28.     movlw   b'00001111'
    29.     movwf   TRISB
    30.     bcf STATUS,RP0
    31.  
    32. newloop:
    33.     movf PORTB,W
    34.     movwf bfr1
    35.     movf bfr1,W
    36.     movwf PORTA
    37.     rlf bfr1,F
    38.     rlf bfr1,F
    39.     rlf bfr1,F
    40.     rlf bfr1,F
    41.     movf bfr1,W
    42.     movwf PORTB
    43.     goto newloop   
    44.  
    45.     end
     
  2. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    Are you using tactile switch or locking switch?

    Is it possible to show your schematic?

    Allen
     
  3. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    im using slide switches
     
  4. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    Your schematics?
     
  5. nerdegutta

    Moderator

    Dec 15, 2009
    2,517
    785
    [​IMG]

    Something like this...?
     
    absf likes this.
  6. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    If your schematic looks something like mine it should work.

    Of course, you have to put in the 4MHz crystal and the 2x 22p capacitors since you're defining "_XT_OSC". You see, the simulator is very forgiving. It works even without that.

    Allen
     
    • chua.PNG
      chua.PNG
      File size:
      147.1 KB
      Views:
      37
    Last edited: Aug 26, 2012
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    If it works in sim but not on the hardware then the sim and the hardware don't match.

    Did you try to see what happens at the inputs when you change the switches? Can you drop a voltmeter on them and see you have good goes-into's that don't interact?
     
  8. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    well it look the same but my resistors are connected to gnd and my switches are connected to vdd
     
  9. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    my lay out
    [​IMG]
    just right click again
    is there something wrong here?
     
  10. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    Is this your circuit?

    [​IMG]

    Allen
     
  11. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    It looks like your switches are connected to gnd, and pulled up with 10K resistors. And your 16F84A has 20 pins?

    Allen
     
    Last edited: Aug 26, 2012
  12. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    changed the pull ups into pull down
     
  13. ernestclydeachua

    Thread Starter New Member

    Aug 5, 2012
    16
    0
    im gonna try to build the circuit again
     
Loading...