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.

what am i doing wrong?

Status
Not open for further replies.
You must have something wrong with your button on GP3. Do you have the button from the pin to Vdd and a resistor from the pin to ground?

Mike.
 
Hi,
The configuration setting, _MCLRE_ON means enable MCLR. Since you're using this pin as input, MCLR should be tied up internally by changing the configuration setting to _MCLRE_OFF.
 
Bananasiong,

You've done it again. Well spotted.

However, to the OP, you need to move your switch to a different pin. If you turn off MCLR with internal oscillator enabled you will have problems reprogramming.

Mike.
 
GP3 isconnected to one pin of the momentary push button switch, and the other side of the switch is connected to + 5v
 
ok so now after making GP4 input, both led's are working all the time, meaning GP1, andGP5. when i press switch on GP4,
the led's are brighter then when I don't touch anything.
Also, the pic is not waiting for GP4 to go high. It automaticaly turns all led's on, and when I press switch again, GP5 does not go low.
What else can be wrong.

+5v on vdd
Gnd on vss
GP1 220 ohm res then to led then to gnd
GP2 to +5v via 1k resistor
GP3
GP4 has switch to 5v+
GP5 220ohm then to LED
there is one decoupling cap between vss and vdd.
Should gP3 be floating? I already tried vdd with 10k

Thanks everyone.
 
Try this:

Code:
start
			 
		bsf	GPIO,1		;set GP1 high
					;LED on GP1 should be on. 
			 
check		btfss      GPIO,3                ; if SW still pressed dont clr led
                    bcf	GPIO,5		;turn off LED
		btfss	GPIO,3		;test GP3 if button on computer was pressed
		goto	check		;if not then return to check again
		
		bsf	GPIO,5		;turn on LED
		goto	check		;do it all again


		end

Dont think this will make a difference though... without having the hardware in front of me to test, I'm out of things to try.
 
Last edited:
same result as before.

I'm late getting to the party. Here might be a problem:

It looks like you are using the same delay routine as given in Nigel's tutorials. If so, you have mis-directed one "goto" (the one after the third decfsz. Nigel's code has a loop to d1, which points to the loading of your variable (d2).

I'm still really too new at this to give a definative answer, but it could be the LED is on and off faster than you can see.

Check it out.

Also, the first thing I learned was: just because it will assemble doesn't necessarily mean it will work.

G'luck
 
But, selecting internal oscillator and turning off MCLR is to be avoided. Best to leave MCLR enabled.

Mike.
 
Ok, guys, I successfully have GP1 showing power, and GP5 turning on after 1 minute delay and staying on, and then GP1 flashing every second after that. now when I introduce btfss (read GP3), everything craps out. so for now, I will admire the two led's doing there thing. Does anyone know why btfss command is a problem with this PIC? Thanks for all the help.
here code without trying to read GP3.
Code:
	list      p=12f629            ; list directive to define processor
	#include <p12f629.inc>        ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT  






;***** VARIABLE DEFINITIONS
w_temp        EQU     0x20        ; variable used for context saving 
status_temp   EQU     0x21        ; variable used for context saving
d1            EQU     0x40
d2            EQU     0x41
d3            EQU     0x42
d5            EQU     0x43
d6            EQU     0x44
d7            EQU     0x45

;**********************************************************************
		ORG     0x000             ; processor reset vector
		goto    main              ; go to beginning of program


		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register





		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt



main
		bsf     STATUS,RP0        ; set file register bank to 1
        call    0x3FF             ; retrieve factory calibration value
		 
		movwf   OSCCAL            ; update register with factory cal value 
		bcf STATUS,RP0
        clrf GPIO          
                                  ;GPIO port setup

        movlw 07h                 ;set GP0,GP1 and GP2
        movwf CMCON               ;turn comparator off
        bsf STATUS,RP0            ;set file register to bank 1
        movlw 08h                 ;move literal(value) 1C in hex or 00001000 in binary to working register.
        movwf TRISIO              ;move literal(value) in working register to TRISIO making  GP3 as input(default)
                                  ;and leaving GP0,GP1,GP2,GP4 and GP5 as outputs.
        bcf STATUS,RP0            ;set file register bank to 0


start
		
        nop
        nop
        nop	 
		bsf	GPIO,1		;set GP1 high
					;LED on GP1 should be on. 
					;to confirm that microprocessor has setup all ports to input and outputs. 
		goto check

	 
check	
     	bcf	GPIO,5		;turn off LED
        call Delay2
        bsf GPIO,5
        call Delay

flash   bcf GPIO,1      ;infinite loop
        call Delay
        bsf GPIO,1      
        call Delay
        goto flash

Delay
			;999990 cycles
	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return

Delay2
			;59999994 cycles
	movlw	0x23
	movwf	d5
	movlw	0xCB
	movwf	d6
	movlw	0x83
	movwf	d7
Delay2_0
	decfsz	d5, f
	goto	$+2
	decfsz	d6, f
	goto	$+2
	decfsz	d7, f
	goto	Delay2_0

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return

		END                       ; directive 'end of program'
 
GP3 should be connected to Vdd via a 10k (any) resistor.

Mike.
If you have it connected to VDD and when pressed its grounded then shouldn't it be "btfsc" ?
If thats the case this should be the code.

Code:
start

           bsf  GPIO,1          ;set GP1 high
				;LED on GP1 should be on.
check
           btfsc  GPIO,3        ; if SW still pressed dont clr led
           bcf    GPIO,5	;turn off LED
           btfsc  GPIO,3	;test GP3 if button on computer was pressed
           goto   check		;if not then return to check again

           bsf    GPIO,5	;turn on LED
           goto   check		;do it all again
           end
 
Pin4 can be one of two things, it can be GP3 or it can be MCLR. In your config line you have _MCLRE_ON which makes it MCLR and so the pin cannot be used as an I/O pin. Don't be tempted to change it to _MCLRE_OFF as this may make your chip unprogrammable. Pic chips with internal oscillator and MCLR turned off are very difficult to reprogram.

Configure a different pin as the input and it should all work fine.

Mike.
 
why is this simple loop not working? This program always loops back to start, when all I want to do is stay stuck in the shutdown mode until I press the switch. then it can go to start.


There is no residual power on GP2, as there is a10k resistor to GND.
I cleared the working register, and GP2 and still it goes to start.

How annoying

12f629

Thanks
 
Status
Not open for further replies.

Latest threads

Back
Top