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.

Help me with code for electronic switch pls

Status
Not open for further replies.

x-land

New Member
I need help with a little code if you can help me.
First I'm sorry for my bad english. I try read in forum but I can't understand nothing. I'm verry n00b in pic programming and in English :(.

So, I need next aplication (electronic switch) :

I have 1 input (I1) and 4 (O1, O2, O3, O4) outputs.

At input port is 3.3V all time and when push on reset button input is in "0".
I want next:
First situation: If I press reset less 0.5s outputs must be: O1= GND, O2=5V, O3=0 (not GND), O4=0; (if press time is 0.3 for ex. the outputs must be executed)
Second situation: If I press more or equal like 0.5s outputs must be: O1= 0 (not GND), O2=0, O3=GND, O4=5V; (when press time = 0.5s the ouptuts must be executed)


I think 12C508 or 509 is good for what I need but I'm not sure :). I have and 5V for Vdd.
I have mikroBasic software. So, if code is for mikroBasic is verry good. I compile them after I have the code. But isn't bad and if is write in asm.

I hope my explication is good :)

Thanks, thanks, th.........
 
So, I make alone with help tutorial Nigel Goodwin (good tutorial for n00bs) this aplication for 16F628 (it's what I write in my preview post):

Code:
	LIST	p=16F628		
	include "P16F628.inc"		
	__config 0x3D18			


	cblock 	0x20 			
		cnt1 				;for delay routine
		cnt2				;for delay routine
		cnt3				;for delay routine
	endc

		org	0x0000
	
	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)
  	bsf 	STATUS, RP0	
	movlw 	B'00100000'		;set PortA 1 inputs, 7 outputs
   	movwf   TRISA
	bcf		STATUS,	RP0		    
	clrf	PORTA			;set all outputs low
	bsf		PORTA, 4
Loop	btfss PORTA, 5  	;wait for press "reset"
	call short
	goto Loop

short	call Delay       	; delay ~700ms 
  
	btfsc	PORTA, 5		; verify if "reset" is pressed
	call	output1			; if not execute output1
	bsf		PORTA, 0		
	bcf		PORTA, 1		; here I need output GND. I don't know how and if it's possible
	bsf		PORTA, 2			
	bsf		PORTA, 4		; here I need output GND. I don't know how and if it's possible
	goto	finish			; "stop" program, execute countinous loop

output1	bcf PORTA, 0		; here I need output GND. I don't know how and if it's possible
	bsf		PORTA, 1
	bcf		PORTA, 2		; here I need output GND. I don't know how and if it's possible
	bcf		PORTA, 4
	goto	finish

Delay	movlw	3			; delay routine ~700ms
	movwf	cnt3
	movlw	b'11111111'
	movwf	cnt2
	movlw	b'11111111'
	movwf	cnt1
	decfsz	cnt3, F
	goto	$+2
	goto	$+0A
	decfsz	cnt2, F
	goto	$+2
	goto	$+6
	btfsc	PORTA, 5		; verify if "reset" is pressed
	retlw	0x00			; if not return
	decfsz	cnt1, F
	goto	$-1
	goto	$-7
	goto	$-0B
	movlw	b'01111111'
	movwf	cnt2
	movlw	b'11111111'
	movwf	cnt1
	decfsz	cnt2, F
	goto	$+2
	goto	$+6
	btfsc	PORTA, 5		; verify if "reset" is pressed
	retlw	0x00			; if not return
	decfsz	cnt1, F
	goto	$-1
	goto	$-7
	movlw	89
	movwf	cnt1
	decfsz	cnt1, F
	goto	$-1
	retlw	0x00			;return after delay it's over

finish sleep				; stop all, it's enough ;-)
			end

I don't know if is something wrong in them but work :).

Now I need if somebody can help me for have at output port Ground (GND) not "0". I don't know if it's possible.
I don't want use transistors for make GND where I need.
And when I build proiect in MPLAB I have this message:
"Message[302] D:\KIT\16F628TEST\TEST1.ASM 18 : Register in operand not in bank 0. Ensure that bank bits are correct."
at line : movwf TRISA
. It's some problem with them?

Thanks
 
Last edited:
x-land said:
And when I build proiect in MPLAB I have this message:
"Message[302] D:\KIT\16F628TEST\TEST1.ASM 18 : Register in operand not in bank 0. Ensure that bank bits are correct."
at line : movwf TRISA
. It's some problem with them?

It's not an error, it's a warning, it's NOT a problem - it's explained in a later tutorial how to prevent it.
 
Thank's. And it's possible have GND at output? Maybe I apear stupid but it's first time when I see pic and assambler. Only positive or negative answer it's enough and I try find solution. I don't want lose the time if isn't possible.
If I read value from one input port what it's at GND and I write that value in output port is that output port at GND?
 
x-land said:
Thank's. And it's possible have GND at output? Maybe I apear stupid but it's first time when I see pic and assambler. Only positive or negative answer it's enough and I try find solution. I don't want lose the time if isn't possible.
If I read value from one input port what it's at GND and I write that value in output port is that output port at GND?

Basically yes, but 'GND' isn't really the correct term, digital I/O pins can be either HIGH or LOW, below a certain voltage means it's LOW, and above a certain voltage means it's HIGH - it doesn't have to be 0V or 5V, there's a logic switching point somewhere in between.
 
I try this with RA4, pin for "open drain output". And I change the input at RA5.
I see it's only one port at 16f628 what can do OD. Is that the solution for what I want? (I change the code in my post with new code). Is real 0V (is pin at Vss?) or is logic "0" when I have bsf PORTA, 4?
 
x-land said:
I try this with RA4, pin for "open drain output". And I change the input at RA5.
I see it's only one port at 16f628 what can do OD. Is that the solution for what I want? (I change the code in my post with new code). Is real 0V (is pin at Vss?) or is logic "0" when I have bsf PORTA, 4?

I speak not seening your circuit, but bsf is "Bit Set" so you will have a logic one. It will not be 5 volts, there is a loss from the output of the chip.

bcf porta,4 will send it low. Under a volt, drop a meter on it.. And flip it high and low.
 
PORTA.4 is an open drain, unless you add a external pull-up resistor, you'll probably never reach the VDD voltage. Mostely noise and wind will go out of there... it's floating in the air.
 
In datasheet at 16F628 pin 3 (RA4) is designed like "open drain output" when is set for output. So, I understand from this when I have bsf porta,4 pin 3 is send in 0. But I don't know if is 0 logic or real 0V (Vss). Maybe I wrong, I don't read good english and I don't write code never but that I understand.
And I try the code live (in circuit) and work like 0V (Vss), but the question remain if is real or not.

Edit: @mister_e: thanks, I write before read your post :).
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top