16f84 asm to 16f628

Status
Not open for further replies.

_ab

New Member
Dear friends hi!!!!!

Once again i would like your help because i am in a trouble.I have built the circuit below with the lcd version....
https://jap.hu/electronic/combination_lock.html
The problem i have is that i want this circuit to act as a toggle switch.When you press the code,to arm the relay,and when i press it again to disarm.I tried to contact the aythor,but he didn't reply to me.The aythor has to his page,the particular code,but it is used for a pic16f84.What part in the code should i change to convert it to the pic16f628??? i also tried to use the xor operation but as a newbie to microcontrollers world i didn't achived anything..... :-(
I attached the two codes and i would like to tell me if it is circle correct the part that it must be changed to work as a toogle switch....

Sincerely _ab


P.s=sorry for my poor english
 

Attachments

  • asms.GIF
    14.5 KB · Views: 942
  • Files.zip
    6.2 KB · Views: 464
The differences between 16F84 and 16F628 are only tiny, and it was the 'modern' replacement for it last century.

To alter 84 code to 628, you just need to:

1) Alter the fuse settings and heard of the assembly file.

2) Alter the GPR start address.

2) Turn off the analogue comparators.

You can check my tutorials to see what these all look like.
 
"1) Alter the fuse settings and heard of the assembly file.
2) Alter the GPR start address.
3) Turn off the analogue comparators"

I think that these instructions are changed (aren't they)because already the file works on 16f628 but it has a different output for the relay state.....I don't have the expierience to change these variables.....

What is the Gpr address and what is the correct starting value????
How can i turn off the analogue comparators(and what they do)

Which tutorial from 1 to 10 should i look????

Thanks a lot for your reply!!!!!!
 

5) GPR's start at 20h on the '628 and at 0Ch on the '84.
 
_ab said:
What part in the code should i change to convert it to the pic16f628???

You have asked the question badly. It is not about changing from 16F84 to 16F628. The original author had already provided correct source code for the 16F628. It is the function you required not being provided in the F628 source code. So it is a question of modifying the 16F628 source code to include your requirement.

The change required is easily done. See below, change marked with "<<<<<<".

Code:
;**********************************************************************
;                                                                     *
;    Filename:	    cl2.asm                                           *
;    Date:                                                            *
;    File Version:  Combination lock rewritten                        *
;                                                                     *
;    Author:        Peter Jakab <el@jap.hu>                           *
;                   http://jap.hu/electronic/                         *
;**********************************************************************
;..............
;
pulseout				; # operates output

		movf PORTA, W	;get port A into W <<<<<<<<<<
		xorlw 0x04 	;toggle RA2      <<<<<<<<<<
		movwf PORTA




		movlw msg_line
		call lcd_cmdout
		movlw msg_ok
		call lcd_strout

		movlw pulsewidth
		movwf dcnt2

out0		movlw d'200'
		call udelay
		decfsz dcnt2, F
		goto out0

		goto loop
 
Thank you very much for replying me......
I changed the code as you say ,but i have the same results of the circuit..... :-(
 
_ab said:
Thank you very much for replying me......
I changed the code as you say ,but i have the same results of the circuit..... :-(

Somewhere else the author reset the output, missed that earlier. Try this:

Code:
warm		movlw 0xf0
		call beep
		call eep_read ; read code from eeprom to ram at cod

loopx	clrf PORTA ; clear output   <<<<<<<<<<< 

loop		movlw msg_line    ;<<<<<<<<<<<<
		call lcd_cmdout
		movlw msg_code
		call lcd_strout
		
		call read ; read code from keyboard into readbuf
		movlw cod
		call compbuf ; compare code in readbuf with code at cod
		bnz loop ; the code is different
 
You are the best my friend!!!!!Thanks a lot for helping me.......!!!!!!!!!
And one last question is it possible,when you first power up the circuit the output to be in the off state instead of the on state that it is now?????

P.s=I wouldn't have done anything without your help.....

Sincerely
 
_ab said:
And one last question is it possible,when you first power up the circuit the output to be in the off state instead of the on state that it is now?????

I don't know why the output is default ON at power up. Could be due to LCD routines.

Anyway, you can try to replace:
Code:
loopx	clrf PORTA ; clear output

with these two instructions:
Code:
loopx   movlw  0x04     ;<<<<<<<<<
        movwf PORTA     ;<<<<<<<<<

loop     movlw msg_line

to see if it works.
 
From what I read from .asm and see in the schematic, I would say that the RELAY output is defaulting to its unenergized state. The BC transistor drivers is not inverted and the PIC code clears PortB on startup. Is this the output to which you are asking?

If the relay in your setup is always closing the contacts between relay pins S and P, you might be using a relay with normally closed (N.C) contacts as opposed to normally open (N.O.) contacts. Or you have a single-pole-double-throw (SPDT) relay and are using the wrong throw pin.

With all the versions of toggling floating around and since I do not trust that experimental toggle (ON/OFF) source, I suggest you perform an absolute test. Remove relay and the transistor from PIC and remove relay from transistor. Verify relay is connected to work as N.O. Reconnect relay to transistor, bias relay base with 5v and verify relay works as N.O. Before connecting relay/transistor to PIC, power on the PIC and monitor RB2 output from power up, which should be low. If its high then the asm code is toggling prematurely. I can see why because dcnt2 is use in multiple places. Just use a dedicated variable for Relay output and toggle it instead of a commonly shared variable.
 
Last edited:


I forgot to mention that i have a led right now in the output,instead the relay.(i don't know if that matters...)So It worked!!!!!!!But when i power up the circuit i have a pulse.The led lights for a moment and then it goes to the off state....(it's not much problem)

Thanks all for all you have done for me!!!!!!!!!!!!and especially eblc1388
 

It matters a lot. How was the LED connected?

From +5V to RA2 or from RA2 to 0V?
 
eblc1388 said:
It matters a lot. How was the LED connected?

From +5V to RA2 or from RA2 to 0V?

Why matters can you explain me?????

friend donniedj yes it's porta the output in pic16f628 version with the lcd....
 

Attachments

  • connection.GIF
    3.7 KB · Views: 368
Ok, I see from the attached image that the output is visually inverted. The PIC is not doing the inversion but your connection method is. Turn the led around, connect the resistor to Ground instead of +V, and all will be good for now anyway.
 
_ab said:
Why matters can you explain me?????

The code that I posted before last changes already worked but your way of connection of LED have given you a false impression that the output is reversed which if you connect it to a NPN transistor+relay will work correctly. If you connect a LED from +5V to RA2, then the pin need to be at 0V for the LED to light. Therefore your LED lights up when the pin is 0V. But 0V on the pin will not turn ON your relay so the relay will be OFF.

Your LED lights when in actual the relay is OFF. Got that now?

So forget about:
Code:
loopx   movlw  0x04     
        movwf PORTA
and use the previous code instead.
Code:
loopx	clrf PORTA ; clear output
 
Thanks a lot my friend i appreciate what you have done for me!!!!!!!!!!!!As i said i am newbie and i wouldn't have done anything without your help......

Cheers

))
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…