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:
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