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.

LCD & CHECK CODE (facing problem)

Status
Not open for further replies.

smileguitar

New Member
Hi, recently I'm doing a project about the infrared security system, which is using keypad(4X3) to key-in the passward and send to the receiver part by infrared. My task is when I recieve the passward, "*" will display on LCD screen one code by code. Also, I've to compare the passward with the original passward that has been set initially. If the codes are correct, it'll call "Correct Code"; on the other hand, if the codes are wrong, it'll "Wrong Code".

I have created coding to receive the key-in passward and check the passward, but it's not work what I want. At first, I test the coding by pressing button, if the button is being pressed, "*" will display out, and if correct, "Correct Code" will display out at the second line. However, when I test on the bread board, is not like that. The "*" and "Correct Code" came out together after the LCD flashing. Sometime, LCD will display wrongly like "Correct Cede*".

Why it be like that? How can I improve it?

My coding is shown below:
Code:
	LIST P=16F877
	#INCLUDE <P16F877.INC>
	errorlevel -302
	errorlevel -207
	__CONFIG _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF
	
			CBLOCK	0X20
				CODE1		;FOR NUMBER
				CODE2		;FOR NUMBER
				CODE3		;FOR NUMBER
				CODE4		;FOR NUMBER
				D1
				D2
				D3
				D4
			ENDC
				
			ORG	0X00
			GOTO	START

WRONG		CALL	LCD_INIT
			CALL	LCD_LINE2
			BSF	PORTC,2		;R/S SET TO '1'
			MOVLW	H'57'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'72'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'6F'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'6E'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'67'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'20'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'43'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'6F'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'64'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'65'
			MOVWF	PORTD
			CALL	CLOCK_E
			RETURN

CORRECT		CALL	LCD_INIT
			CALL	LCD_LINE2
			BSF	PORTC,2		;R/S SET TO '1'
			MOVLW	H'43'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'6F'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'72'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'72'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'65'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'63'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'74'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'20'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'43'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'6F'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'64'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'65'
			MOVWF	PORTD
			CALL	CLOCK_E
			RETURN

SECRET		CALL	LCD_INIT
			BSF	PORTC,2		;R/S SET TO '1'
			MOVLW	H'2A'
			MOVWF	PORTD
			CALL	CLOCK_E
			RETURN

START		MOVLW	D'1'
			MOVWF	CODE1

SETPORTS	BSF		STATUS,RP0
			MOVLW	B'00000001'
			MOVWF	TRISB
			MOVLW	B'00000000'
			MOVWF	TRISC
			MOVLW	B'00000000'
			MOVWF	TRISD
			BCF	STATUS,RP0
			CLRF	PORTA
			CLRF	PORTD
			
CODE1CHK	BTFSS	PORTB,0			;I test one code
			GOTO	CODE1CHK
			CALL	SECRET

CHECK		MOVF	CODE1,W
			SUBLW	B'00000001'
			BTFSS	STATUS,Z
			GOTO	WRONGCHK
			GOTO	CORRECTCHK

WRONGCHK	CALL	WRONG

CORRECTCHK	CALL	CORRECT
			BSF	PORTC,0

LCD_INIT	BCF		PORTC,2
			MOVLW	B'00110000'
			MOVWF	PORTD			;FUNCTION SET: 8 BIT INTERFACE
			CALL	CLOCK_E
			MOVLW	B'00001100'
			MOVWF	PORTD		;DISPALY & CURSOR: SET TO DISPLAY ON; CURSOR UNDERLINE OFF; CURSOR BLINK OFF
			CALL	CLOCK_E
			MOVLW	B'00111000'
			MOVWF	PORTD			;FUNCTION SET: 8 BIT; 2 LINE MODE; 5X10 DOT FORMAT
			CALL	CLOCK_E
			MOVWF	B'00000001'
			MOVWF	PORTD		;CLEAR DISPLAY
			CALL	CLOCK_E
			MOVLW	B'00000110'
			MOVWF	PORTD			;CHARACTER ENTRY MODE: INCREMENT; DISPLAY SHIFT ON
			CALL	CLOCK_E
			RETLW	0X00

LCD_LINE2	BCF		PORTC,2		; R/S SET TO '0'
			MOVLW	B'11000000'
			MOVWF	PORTD		; JUMP TO 2ND LINE
			CALL	CLOCK_E
			RETLW	0X00

CLOCK_E		BSF		PORTC,1
			CALL	DELAY2
			BCF	PORTC,1
			RETLW	0X00

DELAY1		MOVLW	D'130'
			MOVWF	D2
			MOVLW	D'221'
			MOVWF	D1
LOOP1		DECFSZ	D1,1
			GOTO	LOOP1
			DECFSZ	D2,1
			GOTO	LOOP1
			RETLW	0X00

DELAY2		MOVLW	D'13'		;DELAY 10ms
			MOVWF	D4
			MOVLW	D'251'
			MOVWF	D3
LOOP2		DECFSZ	D3,1
			GOTO	LOOP2
			DECFSZ	D4,1
			GOTO	LOOP2
			RETLW	0X00

			END
 
Nigel Goodwin said:
You might try checking my keypad code in the tutorials, one does just such a password check.

I had try your tutorial, Tutorial9, but is quite confusing :confused: I couldn't understand.

Also, my part is not connecting with keypad, should I need to check and scan key?
 
smileguitar said:
I had try your tutorial, Tutorial9, but is quite confusing :confused: I couldn't understand.

Also, my part is not connecting with keypad, should I need to check and scan key?

Obviously if you're not scanning a keypad, you don't need to use that part - just check the password testing routine.
 
Nigel Goodwin said:
Obviously if you're not scanning a keypad, you don't need to use that part - just check the password testing routine.


From your tutorial, your check code is like below:
Code:
Chk_Code	movf	code1, w		;test first digit
		subwf	key1, w
		btfss	STATUS, Z
		goto	Wrong

Mine check code is like below:
Code:
CHECK		MOVF	CODE1,W   ;I set CODE1 as one
			SUBLW	B'00000001'
			BTFSS	STATUS,Z
			GOTO	WRONGCHK

You use subwf, I use sublw; is my coding wrong?
 
My checking code has no problem, but the displayment got a bit problem.

I cannot clear the LCD after displaying characters. How could I make it after displaying due to my coding? I've been use B'00000001', but is not work.
 
Hi, now I'm almost done my part. My coding has been combined with my groupmate, which when I receive any code from transmitter through infrared, I'll check all the codes and display in LCD. But I need to improve my coding, which I can change code for the system. Does anyone can give me some idea?
 
smileguitar said:
Hi, now I'm almost done my part. My coding has been combined with my groupmate, which when I receive any code from transmitter through infrared, I'll check all the codes and display in LCD. But I need to improve my coding, which I can change code for the system. Does anyone can give me some idea?

Store the code in the data EEPROM area, this will allow you to update it from within the program, and still be kept save when power is lost.
 
Hi, I'm trying using the EEPROM coding, but I couldn't store the value in another location. My coding is showing below:

Code:
list p=16f877,f=inhX32, x=off
 include <p16f877.inc>
 


	__CONFIG _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF 

	ERRORLEVEL -302 ;Suppress bank warning

			CBLOCK	0X20
					COUNT
					ADDR
					VALUE
			ENDC
					
			ORG		2100H
			DE		00H
			ORG		0X00
			GOTO	START

READ		BSF 	STATUS, RP1 
			BCF 	STATUS, RP0 	
			MOVF 	ADDR, W 		
			MOVWF 	EEADR 		
			BSF	 STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, RD 
			BCF 	STATUS, RP0 	
			MOVF	EEDATA, W 	
			RETURN

WRITE		BSF 	STATUS, RP1 
			BSF 	STATUS, RP0 	
			BTFSC 	EECON1, WR 		
			GOTO 	$-1 			
			BCF 	STATUS, RP0 	
			MOVF 	ADDR, W 		
			MOVWF 	EEADR 			
			MOVF 	VALUE, W 		
			MOVWF 	EEDATA 			
			BSF 	STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, WREN 	
			MOVLW 	0x55 			
			MOVWF 	EECON2 			
			MOVLW 	0xAA 			
			MOVWF 	EECON2 			
			BSF 	EECON1, WR 		
			BCF 	EECON1, WREN 	
			RETURN

START		BSF		STATUS,RP0
			MOVLW	B'00000000'
			MOVWF	TRISB
			BCF		STATUS,RP0
			CLRF	PORTB

			MOVLW	.2
			MOVWF	ADDR
			MOVLW	.4
			MOVWF	VALUE
			CALL	WRITE

			MOVLW	.3
			MOVWF	ADDR
			MOVLW	.3
			MOVWF	VALUE
			CALL	WRITE
			CALL	READ
			END

As the coding showing above, I want to store the first value of 4 in location 0x01 and the second value of 3 in 0x03. But the simulated result is not like want I expected. It's overwrite the first number in location 0x01. How I use EEPROM to store the values in different location?

Thanks in advanced.
 
You are accessing your variables that are in bank 0 whilst you are in banks 2 & 3. The simplest way to fix this would be to move your variables to 0x70, the common area.

Mike.
 
Pommie said:
You are accessing your variables that are in bank 0 whilst you are in banks 2 & 3. The simplest way to fix this would be to move your variables to 0x70, the common area.

Mike.

Thanks for the comment. But I'm not really clear about the common area. Any other suggestion?
 
Just change cblock 0x20 to cblock 0x70 and your code should work. Once you get it working, study the data sheet and try and work out why that made it work.

Mike.
 
Can I use the method shown as asm code below for storing codes in 2 different locations?

Code:
list p=16f877,f=inhX32, x=off
 include <p16f877.inc>
 


	__CONFIG _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF 

	ERRORLEVEL -302 ;Suppress bank warning

			CBLOCK	0X20
					COUNT
					ADDR
					ADDR1
					VALUE
					VALUE1
					VALUE2
			ENDC
					
			ORG		2100H
			DE		00H
			ORG		0X00
			GOTO	START

READ		BSF 	STATUS, RP1 
			BCF 	STATUS, RP0 	
			MOVF 	ADDR, W 		
			MOVWF 	EEADR 			
			BSF	 	STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, RD 		
			BCF 	STATUS, RP0 	
			MOVF	EEDATA, W 		
			RETURN

READ1		BSF 	STATUS, RP1 
			BCF 	STATUS, RP0 	
			MOVF 	ADDR1, W 		
			MOVWF 	EEADR 			
			BSF	 	STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, RD 		
			BCF 	STATUS, RP0 	
			MOVF	EEDATA, W 		
			RETURN

WRITE		BSF 	STATUS, RP1 
			BSF 	STATUS, RP0 	
			BTFSC 	EECON1, WR 		
			GOTO 	$-1 			
			BCF 	STATUS, RP0 	
			MOVF 	ADDR, W 		
			MOVWF 	EEADR 			
			MOVF 	VALUE, W 		
			MOVWF 	EEDATA 			
			BSF 	STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, WREN 	
			MOVLW 	0x55 			
			MOVWF 	EECON2 			
			MOVLW 	0xAA 			
			MOVWF 	EECON2 			
			BSF 	EECON1, WR 		
			BCF 	EECON1, WREN 	
			RETURN

WRITE1		BSF 	STATUS, RP1 
			BSF 	STATUS, RP0 	
			BTFSC 	EECON1, WR 		
			GOTO 	$-1 			
			BCF 	STATUS, RP0 	
			MOVF 	ADDR1, W 		
			MOVWF 	EEADR 			
			MOVF 	VALUE1, W 		
			MOVWF 	EEDATA 			
			BSF 	STATUS, RP0 	
			BCF 	EECON1, EEPGD 	
			BSF 	EECON1, WREN 	
			MOVLW 	0x55 			
			MOVWF 	EECON2 			
			MOVLW 	0xAA 			
			MOVWF 	EECON2 			
			BSF 	EECON1, WR 		
			BCF 	EECON1, WREN 	
			RETURN

START		BSF		STATUS,RP0
			MOVLW	B'00000000'
			MOVWF	TRISB
			BCF		STATUS,RP0
			CLRF	PORTB

			MOVLW	.2
			MOVWF	ADDR
			MOVLW	.4
			MOVWF	VALUE
			CALL	WRITE
			CALL	READ

			MOVLW	.3
			MOVWF	ADDR1
			MOVLW	.3
			MOVWF	VALUE1
			CALL	WRITE1
			CALL	READ1
			END
 
No matter how you write it,
Code:
READ	BSF 	STATUS, RP1     ;bank 2 or 3
	BCF 	STATUS, RP0     ;now bank 2	
	MOVF 	ADDR, W 	         ;ADDR is in bank 0
This will access location 0x121. You wrote to location 0x020.

Read up on how the bank switching works on pics.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top