Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Push Button PIC16F877A

Status
Not open for further replies.
Joined
Apr 8, 2012
Messages
201
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Activity points
0
Hello!
My Circuit Contains a PIC16F877A. PIN RB0 and PB1 is connected to two mom switches with pull-ups and pin RD0 is configured as output pin and is connected to a relay via uln2003a. The mikroBasic code below is not working properly. When I press sw2 the relay gets turned ON but the relay turns off after 3-4 secs. what might be the problem.

Code:
TRISA = %00011
TRISB = %00000000

while(1)
        if(PORTB.0 = 0) then
           delay_ms(10)
           if(PORTB.0 = 0) then
              PORTD.0 = 1
           end if
        end if

        if(PORTB.1 = 0) then
           delay_ms(10)
           if(PORTB.1 = 0) then
              PORTD.0 = 0
           end if
        end if
        
    wend
 
Last edited by a moderator:

Hello!
My Circuit Contains a PIC16F877A. PIN RB0 and PB1 is connected to two mom switches with pull-ups and pin RD0 is configured as output pin and is connected to a relay via uln2003a. The mikroBasic code below is not working properly. When I press sw2 the relay gets turned ON but the relay turns off after 3-4 secs. what might be the problem.

Code:
TRISA = %00011
TRISB = %00000000

while(1)
        if(PORTB.0 = 0) then
           delay_ms(10)
           if(PORTB.0 = 0) then
              PORTD.0 = 1
           end if
        end if

        if(PORTB.1 = 0) then
           delay_ms(10)
           if(PORTB.1 = 0) then
              PORTD.0 = 0
           end if
        end if
        
    wend

While I'm not familiar with mikroBASIC, there appears to be a few issues after glancing at your code.

All pins of PORTB appear to be configured for output only:

Code:
TRISB = %00000000

Try this instead to configure RB0 and RB1 as inputs:

Code:
TRISB = %00000011

You also should configure RD0 as output using TRISD, although it maybe the default configuration.


Rather than polling for a change, a more efficient and preferred method would be to using interrupts to detect a change of state of either RB0 or RB1.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top