16f84a help

Thread Starter

billyboy1959

Joined Apr 28, 2010
3
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
 

Attachments

eblc1388

Joined Nov 28, 2008
1,542
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.
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
 

rjenkins

Joined Nov 6, 2005
1,013
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?
 

Thread Starter

billyboy1959

Joined Apr 28, 2010
3
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
 

eblc1388

Joined Nov 28, 2008
1,542
It's not written to pulse the port,
Yes you're right. Completely missed the PORTB in code.

One problem appears to be that the TRIS registers are not being set to defne which pins are outputs?
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.

it writes all 1s continuously while a switch is on & clears the port if all switches are off.
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.

Rich (BB code):
MENU        
        
        BTFSC    PORTA,0
        GOTO    LED1
        BTFSC    PORTA,1
        GOTO    LED1
        BTFSC    PORTA,2
        GOTO    LED1
        BTFSC    PORTA,3
        GOTO    LED1
        CLRF    PORTB               ;clear PORTB
        GOTO    MENU
              
LED1                
        BSF    STATUS,5         ;Switch to reg. Bank 1
        MOVLW    B'11111111'
        MOVWF    PORTB            ;set PORTB as INPUT  
        GOTO    MENU
 

Thread Starter

billyboy1959

Joined Apr 28, 2010
3
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.
 
Top