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.

_mclre_off?

Status
Not open for further replies.

Roger_NO

Member
Hi,

When I write _MCLRE_OFF in the config FUSES to make RA5 as a normal input, RA1 goes high! And when i turn it on again RA1 goes low! This is a problem since i've got a switch connetcted to ra5 and when i press it, RA1 should go high. But it goes high even when RA5 input reads "0".

I use a PIC16F628A btw.

Thanks.

Here is the code. Couldent find anything wrong. Maby you can:p
Code:
  list      p=16F628A           ; list directive to define processor
    #include <p16F628A.inc>       ; processor specific variable definitions

    errorlevel  -302              ; suppress message 302 from list file

    __CONFIG   _CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

 cblock		0x20
	d1
	d2
	d3
	endc

 org		0x0000

 movlw		0x07		;Turn Off comp
 movwf		CMCON


 clrf		PORTA
 clrf		PORTB

 banksel	TRISA		;Port definitions
 movlw		b'11110001'
 movwf		TRISA
 movlw		0x00
 movwf		TRISB
 Banksel	PORTA
;main----------------------------
start					;Switch interactions
 movlw		b'00001111'
 movwf		PORTB
 movlw		b'00000000'
 movwf		PORTA
 btfsc		PORTA,7
 call		Enable
 btfsc		PORTA,6
 call		ENRW
 btfsc		PORTA,5
 call		RSEN
 btfsc		PORTA,4
 call		clrRW
 btfsc		PORTA,0
 call		clrRS
 goto		start 


;sub-----------------------------

Enable
 bsf		PORTA,3
 call		Delay
 bcf		PORTA,3
 retlw		0x00

ENRW			
 bsf		PORTA,2
 call		Delay
 retlw		0x00

RSEN		
 bsf		PORTA,1
 call		Delay
 retlw		0x00 

clrRW
 bcf		PORTA,2
 call		Delay
 retlw		0x00

clrRS
 bcf		PORTA,1
 call		Delay
 retlw		0x00





Delay
   						;0.2sec delay
 movlw		0x3F
 movwf		d1
 movlw		0x9D
 movwf		d2
Delay_0
 decfsz		d1, f
 goto		$+2
 decfsz		d2, f
 goto		Delay_0
 
 goto		$+1
 retlw		0x00
		
 end
 
hi,
This is your PIC as powered up, no buttons pressed,,, RA1 is high.
 

Attachments

  • 000esp02.gif
    000esp02.gif
    9.7 KB · Views: 232
I am using the QL200 Dev board, and the switch is connected like this:

hi Roger,

When you set AN1 on with the switch thats OK, but then you switch all of PORTA off at the start subr.
So when the RA5 switch is pressed the AN1 is toggling on/off, so depending when you take your finger off the switch it will always switch AN1 off,


Code:
start                    ;Switch interactions
 movlw        b'00001111'
 movwf        PORTB

 movlw        b'00000000' ' but [B]here you are turning AN1 off[/B]
 movwf        PORTA
 btfsc        PORTA,7
 call        Enable
 btfsc        PORTA,6
 call        ENRW

 btfsc        PORTA,5; [B]switch pressed so call AN1 on[/B]
 call        RSEN

 btfsc        PORTA,4
 call        clrRW
 btfsc        PORTA,0
 call        clrRS
 goto        start
 
yep, i posted the wrong code. the part where i force all of port A to "0" was just somthing i wanted to try. And it didn't turn out well. But i have loaded the code without that part and stil RA1 is high, before i press any buttons! Every other button interacts as it should.

This is the code i am using!

Code:
  list      p=16F628A           ; list directive to define processor
    #include <p16F628A.inc>       ; processor specific variable definitions

    errorlevel  -302              ; suppress message 302 from list file

    __CONFIG   _CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

 cblock		0x20
	d1
	d2
	d3
	endc

 org		0x0000

 movlw		0x07		;Turn Off comp
 movwf		CMCON


 clrf		PORTA
 clrf		PORTB

 banksel	TRISA		;Port definitions
 movlw		b'11110001'
 movwf		TRISA
 movlw		0x00
 movwf		TRISB
 Banksel	PORTA
;main----------------------------
start					;Switch interactions
 movlw		b'00001111'
 movwf		PORTB
 btfsc		PORTA,7
 call		Enable
 btfsc		PORTA,6
 call		ENRW
 btfsc		PORTA,5
 call		RSEN
 btfsc		PORTA,4
 call		clrRW
 btfsc		PORTA,0
 call		clrRS
 goto		start 


;sub-----------------------------

Enable
 bsf		PORTA,3
 call		Delay
 bcf		PORTA,3
 retlw		0x00

ENRW			
 bsf		PORTA,2
 call		Delay
 retlw		0x00

RSEN		
 bsf		PORTA,1
 call		Delay
 retlw		0x00 

clrRW
 bcf		PORTA,2
 call		Delay
 retlw		0x00

clrRS
 bcf		PORTA,1
 call		Delay
 retlw		0x00





Delay
   						;0.2sec delay
 movlw		0x3F
 movwf		d1
 movlw		0x9D
 movwf		d2
Delay_0
 decfsz		d1, f
 goto		$+2
 decfsz		d2, f
 goto		Delay_0
 
 goto		$+1
 retlw		0x00
		
 end
 
hi,
It runs OK in simulation see these two images.
The first one is when RA5 is low at power on and the second when RA5 is high at power on.

Disconnect the switch from RA5 and ground the pin, power up, check if RA1 is on.???

EDIT:
How long are the wires to the switch.?
 

Attachments

  • 000esp03.gif
    000esp03.gif
    9.8 KB · Views: 204
  • 000esp04.gif
    000esp04.gif
    9.7 KB · Views: 190
Last edited:
hi,
Good ide! I'll try that tomorrow as I left the project at my workspace at work:) I did run the program in Proteus where it ran without any problem. i also ran a simple "led on off" code on all PORTA and PORTB outputs without any complications. Good to know that the code is right, maybe a hardware error!

Thanks:)
 
Last edited:
They are about 30cm long.

hi Roger,
For a test, shorten the wires down to say 5cms and twist them together, the problem may be caused by the long 30cm wires, lets know.
 
hi Roger,
For a test, shorten the wires down to say 5cms and twist them together, the problem may be caused by the long 30cm wires, lets know.

Hi Eric,

I discoverd the error! I feel stupid for not cheking this erlier... The RA5 pin is as you know the VPP pin.. On my dev board the vpp signal is high even when its not receiving any program. The developers of this dev board did not emplement a link witch they should have so I could deactivate the vpp input while onboard testing! I'll just use a bigger Chip with more PORTS..

Thanks for all the good help!

Cheers!
 
Hi Eric,

I discoverd the error! I feel stupid for not cheking this erlier... The RA5 pin is as you know the VPP pin.. On my dev board the vpp signal is high even when its not receiving any program. The developers of this dev board did not emplement a link witch they should have so I could deactivate the vpp input while onboard testing! I'll just use a bigger Chip with more PORTS..

Thanks for all the good help!

Cheers!

hi,
Thanks for letting me know, your post will make other users of dev pcbs aware of the problem.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top