1. billyboy1959

    Thread Starter New Member

    Apr 28, 2010
    3
    0
    Hi
    I am new on here and new to pics. I have tried to write a few lines but even with no errors it does not work can you point my faults out please i have been trying all day.I am just trying to switch on bank b with anyof switches on port a in my velleman k8048 board but programmed on my elvis programmer. I told the programmer to use xt forthe osc.

    Thanks
    Billyboy
     
  2. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Don't get upset. You have made a simple mistake which most of us do when we first start up with microcontrollers.

    What you must realize is that the PIC executes millions of instructions per second. If you have setup a port pin to a certain level, you must keep the level stable for a bit of time for human being to see. You can do that by telling the PIC to wait doing nothing for a million instructions. Then you change the port pin to another level. Doing so, the LED will remains lit for a second otherwise how can you see a LED lights up for only 1us.

    So after setting the port pin, your code should first go to a subroutine called "Wait", then go to LED1, change the port pin and Wait again, before jumping back to menu.

    You can get the necessary coding for the wait routine from this link.

    PIC Delay Code Generator
     
  3. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    It's not written to pulse the port, it writes all 1s continuously while a switch is on & clears the port if all switches are off.

    One problem appears to be that the TRIS registers are not being set to defne which pins are outputs?
     
  4. billyboy1959

    Thread Starter New Member

    Apr 28, 2010
    3
    0
    Thanks for replies
    Am i wrong in my thinking that setting status,5 then putting b'00000000' and b'11111111' to PORTA and PORTB i have set up outputs and inputs.
    regards
    Billyboy
     
  5. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Yes you're right. Completely missed the PORTB in code.

    Actually the OP did setup up(by mistake) the TRIS registers by changing into Bank1. The TRIS registers occupy the same address as PORT registers. However, it should be explicitly set up using the proper TRISA and TRISB name as registers instead of PORTA and PORTB.

    No. The code does not set the port to all 1s, instead it set PORTB into an INPUT port. It is caused by the switch BANK1 instruction and never a BANK0 instruction afterward.

    Perhaps this is where the mistake lies. The OP wants to set the port to high but instead went into BANK1 and changed it into an input port.

    To get what he wants, he should just leave out the "green" Bank change instruction.

    Code ( (Unknown Language)):
    1.  
    2. MENU        
    3.        
    4.         BTFSC    PORTA,0
    5.         GOTO    LED1
    6.         BTFSC    PORTA,1
    7.         GOTO    LED1
    8.         BTFSC    PORTA,2
    9.         GOTO    LED1
    10.         BTFSC    PORTA,3
    11.         GOTO    LED1
    12.         CLRF    PORTB               ;clear PORTB
    13.         GOTO    MENU
    14.              
    15. LED1                
    16.         [COLOR=Green][B]BSF    STATUS,5         ;Switch to reg. Bank 1[/B][/COLOR]
    17.         MOVLW    B'11111111'
    18.         MOVWF    PORTB            ;[COLOR=Red][B]set PORTB as INPUT  [/B][/COLOR]
    19.         GOTO    MENU    
    20.  
     
  6. billyboy1959

    Thread Starter New Member

    Apr 28, 2010
    3
    0
    Big Thanks

    It is working now i don't know why i did't get that till it was pointed out. Well at least i have made a start into the pic world. I had programmed using other peoples work but just thought i would try to get a simple (i thought) program to work.
    Thanks again
    bill.
     
  7. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    Well spotted, I'm used to using the TRIS mnemonics & didn't notice the wrong bank.
     
Loading...