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.

Password/USART/CFSEQ

Status
Not open for further replies.

AtomSoft

Well-Known Member
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:
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:
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:
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.
 
Hope you dont mind i had the below alread in my code so reusing it. :D

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!
 
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.
 
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    ;[b] Happened when i added this line [/b]
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
      ;[b]
Reject
		movlw	stringf
		call	strsend  		;Send Login text
                ; [/b]
		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. [b]

		movlw	menu			;send menu
		call	strsend                 ; [/b]

Is it possible i have too many db things?
 
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.
 
Good to hear it's working.

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

Mike.
 
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
 
We are having kind of an electronic pijama party here....:D
 
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)
 
I see what you mean. Reprinting the login string tells the person when the password is wrong. Your solution clears up that problem.

May I suggect a slightly more elegent way to implement your password code using a bit as a true/false variable.
Code:
Reject
		movlw	stringf
		call	strsend		;Send Login text

		bsf	temp3,0		;set password true
		call	rs_recv
		xorlw	'P'
		btfss	STATUS,Z
		bcf	temp3,0		;password=false
		call	rs_recv
		xorlw	'a'
		btfss	STATUS,Z
		bcf	temp3,0		;password=false
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		bcf	temp3,0		;password=false
		call	rs_recv
		xorlw	's'
		btfss	STATUS,Z
		bcf	temp3,0		;password=false

		btfsc	temp3,0
		goto	ShowMem

		movlw	nogo		;send incorrect info
		call	strsend
		goto	Reject
		
ShowMen

As for your string problem, have you looked at how the TBLRD instructions work.

Mike.
 
Hi AtomSoft,

Did you know there are ansi sequences your PIC can send to Hyperterminal to home the cursor and clear the screen, or clear a line from the cursor to the end-of-line, or to move the cursor to X (htab) and Y (vtab) coordinates?

Your input routine might send an asterisk to Hyperterminal for visual feedback each time the user types in a character. Then you might also want to trap <backspace> or <left arrow> characters when they're typed in and act on those accordingly (send a <backspace> char and clear to end-of-line).

There are also various methods for storing your string tables in line with your code that you may want to study.

Food for thought. Have fun.

Mike

Code:
        rcall   home            ; home cursor, clear screen
        putstr  "AtomSoft's Serial Monitor Program\r\n"

password
        bsf     passtrue        ; password true
        gotoXY  02,04           ; htab 2, vtab 4
        rcall   clearEOL        ; clear to end-of-line
        putstr  "Please enter password: "
        rcall   get232          ; get Rx char
        movwf   rxchar          ; save temporarily
        movlw   a'*'            ;
        rcall   put232          ; echo '*' char
        movf    rxchar,W        ; retrieve rx char
        xorlw   'P'             ; 1st char match?
        skpz                    ; yes, skip, else
        bcf     passtrue        ; indicate false
~~~~~
        btfsc   passtrue        ; good password?
        bra     showmenu        ; yes, branch, else
        beep                    ; send 'error' beep
        gotoXY  02,06           ; htab 2, vtab 6
        rcall   beep            ; send attention beep
        putstr  "Incorrect password, press a key to try again "
        rcall   get232          ; wait for a key press
        gotoXY  02,06           ; htab 2, vtab 6
        rcall   clearEOL        ; clear the line
        bra     password        ; start over
showmenu
 
A useful tip might be to use the FSR/INDF Indirect Addressing to implement a stack for storing the password data. Whenever the PIC gets an ASCII value, you can set it up to store it in the first value you have set aside for a stack, and then increment FSR so it points to the next value. Whenever you get done parsing the sent text, you can just reset the value of FSR to the first value you used, and you don't really have to worry about clearing the values because they'll all have to be overwritten to initiate the parse function anyways, right?
 
thanks guys looks a bit over complicated to me. I have a ASCII table here i printed. It shows alot of info.
 

Attachments

  • asciifull.gif
    asciifull.gif
    27.3 KB · Views: 155
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top