Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

switching problem

Status
Not open for further replies.
i hv a problem in my switches connected to the micro controller.i have 2 switches which s connected to micro controller.i am getting the correct voltages.while pressing 0,othr wise 5v through multimetr.i used pull up resistor 10k.i made this one for changing the display.but there is no relation between switch and the controller software.what will be the problm?
 
Last edited:
i hv a problem in my switches connected to the micro controller.i have 2 switches which s connected to micro controller.i am getting the correct voltages.while pressing 0,othr wise 5v through multimetr.i used pull up resistor 10k.i made this one for changing the display.but there is no relation between switch and the controller software.what will be the problm?

hi jimmy,
If the pin voltage is changing from +5v to 0v when the switch is pressed and the PIC does not respond then the problem is most likely your program.

Post you program and also show which pin the switch is connected to.
 
switching

LIST P = PIC16F877A

#INCLUDE "P16F877A.INC"


__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF

cblock 20h
ss,sp,rr

endc


ORG 0X00
MOVLW 00H
MOVWF PCLATH
CLRF STATUS
GOTO main





;****************************************************************************************************
initport

bsf STATUS,RP0
bsf TRISA,0 ;display enable (input)
movlw 0x00
movwf TRISC ;display output
bsf TRISD,0 ;switch control pin
bsf TRISD,1 ;switch control pin
bcf STATUS,RP0
clrf PORTD
clrf PORTA
return

;**************************************************************************************************
mainline

btfss PORTD,0 ;switch sensing
goto mainline
movlw 0xfe ;displaying 8
movwf PORTC
bsf PORTA,0 ;display
call delay
bcf PORTA,0
goto mainline
return
;**************************************************************************************************
;delay
delay

movlw .5
movwf rr
back21 movlw 0xff
movwf sp
back11 decfsz sp,1
goto back11
decfsz rr,1
goto back21
return

;***************************************************************************************************************************************
main


call initport
call mainline
end

but sir this is my testing program...is it ok?
 
This looks way cleaner, try to post like this from now on. What is this supposed to do?

I see:
Code:
    btfss PORTD,0   ;if RD0 is HIGH then skip the loop
    goto  mainline  ;loop
    movlw 0xfe      ;move 0xFE to WREG
    movwf PORTC     ;Move 0xFE (WREG) to PORTC (PORTC0 should be on)
    bsf   PORTA,0   ;TURN ON PORTA0
    call  delay     ;DELAY
    bcf   PORTA,0   ;CLEAR PORTA0
    goto  mainline  ;LOOP
That seems fine but here you have:
Code:
    bsf   STATUS,RP0
    ;bsf   TRISA,0  ;display enable (input) [B][COLOR="Red"](WHY IS THIS INPUT?)[/COLOR][/B]
    bcf   TRISA,0   ;[B][COLOR="Red"]TRY THIS LINE[/COLOR][/B]
    movlw 0x00
    movwf TRISC     ;display output
    bsf   TRISD,0   ;switch control pin
    bsf   TRISD,1   ;switch control pin
    bcf   STATUS,RP0
    clrf  PORTD
    clrf  PORTA

THIS WAS YOUR ORIGINAL CODE: (CLEAN LOOKING)
Code:
LIST P = PIC16F877A

#INCLUDE "P16F877A.INC"    

__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF

cblock 20h
ss,sp,rr

endc

ORG 0X00
    MOVLW 00H
    MOVWF PCLATH
    CLRF  STATUS
GOTO main

;************************************************* ************************************************** *
initport

    bsf   STATUS,RP0
    bsf   TRISA,0   ;display enable (input)
    movlw 0x00
    movwf TRISC     ;display output
    bsf   TRISD,0   ;switch control pin
    bsf   TRISD,1   ;switch control pin
    bcf   STATUS,RP0
    clrf  PORTD
    clrf  PORTA
    return

;************************************************* *************************************************
mainline

    btfss PORTD,0   ;switch sensing
    goto  mainline
    movlw 0xfe      ;displaying 8
    movwf PORTC
    bsf   PORTA,0   ;display
    call  delay
    bcf   PORTA,0
    goto  mainline
    return
;************************************************* *************************************************
;delay
delay

    movlw .5
    movwf rr
back21
    movlw 0xff
    movwf sp
back11
    decfsz sp,1
    goto   back11
    decfsz rr,1
    goto   back21
    return

;************************************************* ************************************************** ************************************
main

    call initport
    call mainline
end

NEW CODE TO TEST:
Code:
LIST P = PIC16F877A

#INCLUDE "P16F877A.INC"    

__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF

cblock 20h
ss,sp,rr

endc

ORG 0X00
    MOVLW 00H
    MOVWF PCLATH
    CLRF  STATUS
GOTO main

;************************************************* ************************************************** *
initport

    bsf   STATUS,RP0
    bcf   TRISA,0   ;display enable (OUTPUT)
    movlw 0x00
    movwf TRISC     ;display output
    bsf   TRISD,0   ;switch control pin
    bsf   TRISD,1   ;switch control pin
    bcf   STATUS,RP0
    clrf  PORTD
    clrf  PORTA
    return

;************************************************* *************************************************
mainline

    btfss PORTD,0   ;switch sensing
    goto  mainline
    movlw 0xfe      ;displaying 8
    movwf PORTC
    bsf   PORTA,0   ;display
    call  delay
    bcf   PORTA,0
    goto  mainline
    return
;************************************************* *************************************************
;delay
delay

    movlw .5
    movwf rr
back21
    movlw 0xff
    movwf sp
back11
    decfsz sp,1
    goto   back11
    decfsz rr,1
    goto   back21
    return

;************************************************* ************************************************** ************************************
main

    call initport
    call mainline
end
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top