Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 25th June 2008, 02:55 PM   (permalink)
Default Password/USART/CFSEQ

Using ASM Im trying to wrap my head on this for days now just cant focus. I want to create a USART Program for my pic which requires the user to enter a password.

I have futz old code and working on it .
I can receive info no problem like 1 character at a time now the issue is how would i store these into 1 password to check 4 charactors long?

Or would i have to create 4 separate variables and logged flag current flag?

so it checks if logged in already if so skip entire login and show menu
if not set current flag to 1 and get first character then check if curr = 4
get second and set current to 2 then check if curr = 4
get third and set current to 3 then check if curr = 4
get 4th and set current to 4 then check if curr = 4
if curr = 4 then compare "CFSEQ" each to the 4 other variable burned into chip. If correct then set logged in flag.


Does this sound overcomplicated? or just about right?

Please any tips would help alot!

Last edited by AtomSoft; 25th June 2008 at 02:56 PM.
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 03:10 PM   (permalink)
Default

The simplest way would be a brute force compare,

Code:
Reject	call	GetChar
	xorlw	'P'
	btfss	STATUS,Z
	goto	Reject
	call	GetChar
	xorlw	'a'
	btfss	STATUS,Z
	goto	Reject
	call	GetChar
	xorlw	's'
	btfss	STATUS,Z
	goto	Reject
	call	GetChar
	xorlw	's'
	btfss	STATUS,Z
	goto	Reject
	
;if it gets here then the 4 characters matched.
Note that entering "PPass" would be invalid. So you tell people it is "xPass".

Edit, GetChar would, of course, wait for a character to be received and return it in W.

Mike.

Last edited by Pommie; 25th June 2008 at 03:12 PM.
Pommie is online now   Reply With Quote
Old 25th June 2008, 03:21 PM   (permalink)
Default

awsome! Thanks a bunch Mike.

So the GetChar would be a loop wait until char is read then have it place it in w then continue on. Nice coding!


EDIT:

I guess i just need to add a loggedin flag to determine if the user already logged in before i ask for login info.

Last edited by AtomSoft; 25th June 2008 at 03:22 PM.
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 03:28 PM   (permalink)
Default

Quote:
Originally Posted by AtomSoft View Post
awsome! Thanks a bunch Mike.
So the GetChar would be a loop wait until char is read then have it place it in w then continue on. Nice coding!
Yup, something like,
Code:
GetChar	btfss	PIR1,RCIF
	goto	GetChar
	movfw	RCREG
	return
Mike.
Pommie is online now   Reply With Quote
Old 25th June 2008, 03:37 PM   (permalink)
Default

Hope you dont mind i had the below alread in my code so reusing it.

Code:
rs_recv	btfss	PIR1,RCIF		;wait for a byte from RS232
		goto	rs_recv
		movf	RCREG,W			;return received byte in W
		return
Also i noticed i wont need a logged in flag really. because nothing goes back to that part of the code only a reset which would ask for pass again anyway which is good. Thanks a bunch!
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 03:47 PM   (permalink)
Default

Need some help:

I get :

Argument out of range. Least significant bits used.

what does this mean?
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 03:51 PM   (permalink)
Default

Where do you get the error? You should be able to double click on the error message and it will take you to the line with the error.

It could be that the single quotes ('P') have to be double quotes ("P").

Mike.
Pommie is online now   Reply With Quote
Old 25th June 2008, 03:59 PM   (permalink)
Default

Oh its on my code tho its here:
Code:
		list	p=18F1320
		include	<p18f1320.inc>
		;CONFIG	OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF
		CONFIG	OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON	

		cblock	0x00
			buff2,buff3,char,numr,bitnum,loop1,loop2,temp1,temp2
		endc

		org		0x0000
		goto	init

hello	db		0x0d,0x0a,"Hello World!",0x0d,0x0a,0x00
pa_val	db		0x0d,0x0a,"PortA = ",0x00
pb_val	db		0x0d,0x0a,"PortB = ",0x00
string3	db		0x0d,0x0a,"PORTA cleared",0x0d,0x00
string4	db		0x0d,0x0a,"PORTB cleared",0x0d,0x00
string5	db		0x0d,0x0a,"RA1 toggled",0x0d,0x00
string6	db		0x0d,0x0a,"RA4 toggled",0x0d,0x00
string7	db		0x0d,0x0a,"RA6 toggled",0x0d,0x00
string8	db		0x0d,0x0a,"RA7 toggled",0x0d,0x00
string9	db		0x0d,0x0a,"RB0 toggled",0x0d,0x00
stringa	db		0x0d,0x0a,"RB2 toggled",0x0d,0x00
stringb	db		0x0d,0x0a,"RB3 toggled",0x0d,0x00
stringc	db		0x0d,0x0a,"RB5 toggled",0x0d,0x00
stringd	db		0x0d,0x0a,"LEDs flashed",0x0d,0x00 
stringe	db		0x0d,0x0a,"RA3 toggled",0x0d,0x00  
stringf	db		0x0d,0x0a,"Please Enter Code:",0x0d,0x00    ; Happened when i added this line 
menu	db		0x0d,0x0a,0x0d,0x0a,"Junebug PIC18F1320",0x0d,0x0a,0x0d,0x0a
		db		"      A - PORTA Status",0x0d,0x0a
		db		"      B - PORTB Status",0x0d,0x0a
		db		"      C - Clear PORTA bits 1,2,3,4,6,7",0x0d,0x0a
		db		"      D - Clear PORTB bits 0,5",0x0d,0x0a
		db		"      H - Hello World!",0x0d,0x0a
		db		"      L - Flash LEDs",0x0d,0x0a
		db		"1,2,3,4,6,7 - Toggle PORTA pins ",0x0d,0x0a
		db		"0,5 - Toggle PORTB pins ",0x0d,0x0a
		db		"<ENTER> - Display menu",0x0d,0x0a
		db		"Modded by Jason aka AtomSoft, thx futz!",0x0d,0x0a,0x0d,0x0a,0x00

init	bsf		OSCCON,IRCF2	;set to 8MHz clock
		bsf		OSCCON,IRCF1
		bsf		OSCCON,IRCF0
		setf	ADCON1			;set PortA to all digital
		clrf	TRISA			;set PortA pins to outputs
		clrf	LATA			;turn off LEDs
		movlw	b'00010010'		;set PORTB data directions
		movwf	TRISB
		call	rs_init			;init rs232
;STARTUP HERE MAIN
      ;
Reject
		movlw	stringf
		call	strsend  		;Send Login text
                ; 
		call	rs_recv
		xorlw	'P'
		btfss	STATUS,Z
		goto	Reject
		call	rs_recv
		xorlw	'a'
		btfss	STATUS,Z
		goto	Reject
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		goto	Reject
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		goto	Reject
ShowMen							;if it gets here then the 4 characters matched. 

		movlw	menu			;send menu
		call	strsend                 ; 
Is it possible i have too many db things?
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 04:10 PM   (permalink)
Default

It looks like stringf is greater than 255 and so you have the error. You need a different way to store (and access) messages. For now you could shorten your other messages (change "toggled" to "Tg") in order to see if it works and then work out how to have a message bank bigger than 256 bytes.

Mike.
P.S. Bed time for me now. If you get stuck I'll look tomorrow.
Pommie is online now   Reply With Quote
Old 25th June 2008, 04:28 PM   (permalink)
Default

ok thanks! BTW that Tg fixed it now how to learn the rest.
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 04:33 PM   (permalink)
Default

Good to hear it's working.

And now I really am going to bed - 2.30 here.

Mike.
Pommie is online now   Reply With Quote
Old 25th June 2008, 05:16 PM   (permalink)
Default

ok cool thanks look into eeprom (de) Good night its 1:16pm here
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 06:11 PM   (permalink)
Default

the other code would send them to reject to soon doing it that way anyone with time can get the pass quick by simple trying every character 1 by 1.
Code:
Reject	
		movlw	stringf
		call	strsend  		;Send Login text

		movlw	0x00
		movwf	temp3

		call	rs_recv
		xorlw	'P'
		btfss	STATUS,Z
		INCF	temp3
		bcf		STATUS,Z
		call	rs_recv
		xorlw	'a'
		btfss	STATUS,Z
		INCF	temp3
		bcf		STATUS,Z
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		INCF	temp3
		bcf		STATUS,Z
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		INCF	temp3

		movlw	0x01
		CPFSLT	temp3
		goto	Reject2
		goto	ShowMen
Reject2
		movlw	nogo			;send incorrect info
		call	strsend
		goto	Reject
		
ShowMen							;if it gets here then the 4 characters matched.

		movlw	menu			;send menu
		call	strsend
This lets them enter all 4 then if correct lets them in
AtomSoft is offline   Reply With Quote
Old 25th June 2008, 06:11 PM   (permalink)
Default

We are having kind of an electronic pijama party here....
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline   Reply With Quote
Old 25th June 2008, 07:55 PM   (permalink)
Default

I sort of figured out a way to save tons of space instead of hard coding the text into the chip i can hard code into my own vb6 program and just send as many commands as needed this way i can send and receive my way ...

Like if i run out of 0xff bytes to send i can use 0xff as a signal for second set of commands and send another for which in the second set.

Kind of like Bank Selectoin (RP0)
AtomSoft is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
password recovery theboss85 Feedback/Comments 6 9th May 2007 08:46 PM
cannot reset password theboss85 Feedback/Comments 7 2nd May 2007 12:16 AM
Computer password mahinda jayasingh General Electronics Chat 19 27th March 2006 04:03 PM
devices password programming Mel_noypi Micro Controllers 7 16th March 2006 09:12 AM
password electromaniac Micro Controllers 4 6th July 2003 11:34 PM



All times are GMT. The time now is 04:52 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.