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
 
Tools
Old 4th March 2008, 11:46 AM   #1
Default LCD & CHECK CODE (facing problem)

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
smileguitar is offline  
Old 4th March 2008, 11:55 AM   #2
Default

You might try checking my keypad code in the tutorials, one does just such a password check.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 4th March 2008, 01:34 PM   #3
Default

Quote:
Originally Posted by Nigel Goodwin
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 I couldn't understand.

Also, my part is not connecting with keypad, should I need to check and scan key?
smileguitar is offline  
Old 4th March 2008, 02:32 PM   #4
Default

Quote:
Originally Posted by smileguitar
I had try your tutorial, Tutorial9, but is quite confusing 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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 4th March 2008, 04:10 PM   #5
Default

Quote:
Originally Posted by Nigel Goodwin
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?
smileguitar is offline  
Old 4th March 2008, 04:31 PM   #6
Default

No, just that mine uses the password stored in registers, which makes it easier to change - your's uses a password hard coded in the source.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 7th March 2008, 10:45 AM   #7
Default

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.
smileguitar is offline  
Old 7th March 2008, 11:59 AM   #8
Default

You need to send the command to clear the display, and wait long enough for it to complete - details are in my tutorial, or on the datasheets.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 18th March 2008, 02:44 AM   #9
Default

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 is offline  
Old 18th March 2008, 10:39 AM   #10
Default

Quote:
Originally Posted by smileguitar
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 20th March 2008, 05:18 AM   #11
Default

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.
smileguitar is offline  
Old 20th March 2008, 06:31 AM   #12
Default

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 is offline  
Old 20th March 2008, 02:39 PM   #13
Default

Quote:
Originally Posted by Pommie
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?
smileguitar is offline  
Old 20th March 2008, 02:47 PM   #14
Default

Quote:
Originally Posted by smileguitar
Thanks for the comment. But I'm not really clear about the common area. Any other suggestion?
Consult the datasheet and read about it!, it's the simple answer to your mistake.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 20th March 2008, 02:52 PM   #15
Default

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.
Pommie is offline  
Reply

Tags
check, code, facing, lcd, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
LCD 2x16 Demo for the Unicorn (18F4550) blueroomelectronics Micro Controllers 25 13th January 2009 03:04 AM
Strange problem tkvenki Micro Controllers 1 3rd May 2007 12:40 PM
info about computes im facing some hardware problem salman007 Chit-Chat 6 29th March 2007 07:23 PM
Check my Timer code MrMikey83 Micro Controllers 7 17th January 2005 07:56 AM
pc keyboard interfacing problem econsyst Micro Controllers 0 8th November 2003 09:28 PM



All times are GMT. The time now is 09:15 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker