Pages

Wednesday, April 1, 2009

A Completion of Project

Today, we have done another project. Microcontroller 8051.

The task is to make a password system. Turn on switch 1, it will show three digits on the 7 segment display. Then turn on switch 2, we need to enter the three digits correctly.

If the password is wrong, it will display a 'H' at the seven segment display. If it is correct, the LED need to blink five times.

So much for a credit of Microcontroller 8051.

Khinhooi
P.S. Here are the language
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; NG KHIN HOOI
; MARCH 06, 2009
; PROJECT FOR MICROCONTROLLER
; SECOND VERSION
;
; DIP SWITCH BUFFER 4000, PORT0
; KEYPAD BUFFER 4000,
; LED LATCH 6000, PORT2
; 7SEGMENT PORT1
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ORG 2200H
CODE_1 EQU 0F9H ; HEXADECIMAL FOR NUM '1' COMMON ANODE
CODE_2 EQU 0A4H ; HEXADECIMAL FOR NUM '2' COMMON ANODE
CODE_3 EQU 099H ; HEXADECIMAL FOR NUM '4' COMMON ANODE
BUFFER EQU 4000H ; ADDRESS FOR BUFFER
LATCH EQU 6000H ; ADDRESS FOR LATCH

INITIAL: MOV R3,#00H ; FIRST CODE
MOV R4,#00H ; SECOND CODE
MOV R5,#00H ; THIRD CODE

MOV R6,#0FFH ; ENTER 0

MOV DPTR,#BUFFER ; TO READ THE BUFFER

READ_1: MOVX A,@DPTR ; READ THE DIP SWITCH
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JB ACC.0,DISP_CODE ; DISPLAY CODE IS SWITCH '1' IS ON
SJMP READ_1 ; KEEPS DETECTING SWITCH '1'

READ_2: MOVX A,@DPTR ; READ THE DIP SWITCH
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JB ACC.1,ENTER_CODE; ENTER CODE MODE
SJMP READ_2 ; KEEP READING SWITCH '2'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE SECTION FOR DISPLAY CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DISP_CODE: MOV P1,#CODE_1
LCALL DELAY

MOV P1,#CODE_2
LCALL DELAY

MOV P1,#CODE_3
LCALL DELAY

MOV P1,#0FFH

SJMP READ_2

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE SECTION FOR GET CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ENTER_CODE: NOP
ENTER_1: MOV DPTR, #BUFFER ; TO READ THE BUFFER
MOVX A,@DPTR ; GET THE KEYPAD INPUT
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JNB ACC.3, ENTER_1 ; KEEP READING UNTIL DV IS ON
LCALL DELAY
MOVX A,@DPTR ; IF DV IS ON, READ THE DATA AGAIN
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER
LCALL SWAPPING ; BRING THE HIGHER-4 BIT DOWN

MOV DPTR,#TABLE ; TO GET THE DEFINED BYTES
MOVC A,@A+DPTR ; GET THE CORESPONDING HEXADECIMAL

MOV P1,A ; DISPLAY THE ENTERED NUMBER

MOV R3,A ; STORE THE NUMBER IN REGISTER

MOV DPTR,#LATCH ; TO DISPLAY AT LATCH
MOV A,#01H ; DISPLAY ONE LED
MOVX @DPTR,A ; DISPLAY ONE LED
;MOV P2,A ; SIMULATION ONLY FOR LATCH

ENTER_2: MOV DPTR, #BUFFER ; TO READ THE BUFFER
MOVX A,@DPTR ; GET THE KEYPAD INPUT
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JNB ACC.3, ENTER_2 ; KEEP READING UNTIL DV IS ON
LCALL DELAY
MOVX A,@DPTR ; IF DV IS ON, READ THE DATA AGAIN
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER
LCALL SWAPPING ; BRING THE HIGHER-4 BIT DOWN

MOV DPTR,#TABLE ; TO GET THE DEFINED BYTES
MOVC A,@A+DPTR ; GET THE CORESPONDING HEXADECIMAL

MOV P1,A ; DISPLAY THE ENTERED NUMBER

MOV R4,A ; STORE THE NUMBER IN REGISTER

MOV DPTR,#LATCH ; TO DISPLAY AT LATCH
MOV A,#03H ; DISPLAY TWO LED
MOVX @DPTR,A ; DISPLAY TWO LED
;MOV P2,A ; SIMULATION ONLY FOR LATCH

ENTER_3: MOV DPTR, #BUFFER ; TO READ THE BUFFER
MOVX A,@DPTR ; GET THE KEYPAD INPUT
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JNB ACC.3, ENTER_3 ; KEEP READING UNTIL DV IS ON
LCALL DELAY
MOVX A,@DPTR ; IF DV IS ON, READ THE DATA AGAIN
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER
LCALL SWAPPING ; BRING THE HIGHER-4 BIT DOWN

MOV DPTR,#TABLE ; TO GET THE DEFINED BYTES
MOVC A,@A+DPTR ; GET THE CORESPONDING HEXADECIMAL

MOV P1,A ; DISPLAY THE ENTERED NUMBER

MOV R5,A ; STORE THE NUMBER IN REGISTER

MOV DPTR,#LATCH ; TO DISPLAY AT LATCH
MOV A,#07H ; DISPLAY THREE LED
MOVX @DPTR,A ; DISPLAY THREE LED
;MOV P2,A ; SIMULATION ONLY FOR LATCH

ENTER_0: MOV DPTR, #BUFFER ; TO READ THE BUFFER
MOVX A,@DPTR ; GET THE KEYPAD INPUT
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER

JNB ACC.3, ENTER_0 ; KEEP READING UNTIL DV IS ON
LCALL DELAY
MOVX A,@DPTR ; IF DV IS ON, READ THE DATA AGAIN
;MOV A,P0 ; SIMULATION ONLY FOR BUFFER
LCALL SWAPPING ; BRING THE HIGHER-4 BIT DOWN

CJNE A,#09H,ENTER_0
SJMP CHECK

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE SECTION FOR CHECKING THE CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CHECK: CLR A ; CLEAR A FOR CHECKING

CHECK_1: CJNE R3,#CODE_1,CHECK_2 ; IF CODE ENTERED IS CORRECT
SETB ACC.0 ; THEN SET BIT
SJMP CHECK_2 ; ELSE CHECK SECOND NUMBER

CHECK_2: CJNE R4,#CODE_2,CHECK_3 ; IF CODE ENTERED IS CORRECT
SETB ACC.1 ; THEN SET BIT
SJMP CHECK_3 ; ELSE CHECK THIRD NUMBER

CHECK_3: CJNE R5,#CODE_3,AND_GATE ; IF CODE ENTERED IS CORRECT
SETB ACC.2 ; THEN SET BIT
SJMP AND_GATE ; ELSE AND WITH 7

AND_GATE: ANL A,#00000111B ; ONLY CORRECT BITS WILL PRODUCE 7
CJNE A,#00000111B,HASH ; ONLY 7 IN A WILL MAKE LED BLINK
SJMP BLINK

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE SECTION FOR SHOWING THE RESULT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

BLINK: MOV DPTR,#LATCH
MOV P1,#0FFH ; CLEAR THE PORT 1 OF ANY DIGIT
MOV R7,#05H ; BLINK 5 TIMES
ROTATE: MOV A,#0FFH ; LED HIGH
MOVX @DPTR,A ; SHOW AT LED
;MOV P2,A ; SIMULATION ONLY FOR LATCH
LCALL DELAY

MOV A,#00H ; LED LOW
MOVX @DPTR,A ; TURNS OFF LED
;MOV P2,A ; SIMULATION ONLY FOR LATCH
LCALL DELAY

DJNZ R7,ROTATE ; ROTATE UNTIL 5 TIMES IS OVER

ENDING: MOV A,#00H ; MAKE IT END HERE
MOVX @DPTR,A
;MOV P2,A ; SIMULATION ONLY FOR LATCH
SJMP ENDING


HASH: MOV DPTR,#LATCH
MOV A,#00H ; CLEAR THE LED OF ANY LIGHTS
MOVX @DPTR,A
MOV P2,A

ENDING_2: MOV P1,#089H ; DISPLAY THE WORD 'H'
LCALL DELAY
MOV P1,#0FFH ; DISPLAY NOTHING
LCALL DELAY
SJMP ENDING_2 ; KEEPS LOOPING



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE SECTION FOR SUBROUTINES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SWAPPING: SWAP A
ANL A,#0FH
RET

DELAY: MOV R0,#05 ; 0FFH FOR SIMULATION 5 FOR REAL
MOV R1,#0150 ; 0FFH FOR SIMULATION 150 FOR REAL
MOV R2,#05 ; 0FFH FOR SIMULATION 5 FOR REAL
L1: DJNZ R0,L1 ; DJNZ-DEC AND JUMP TO 'L1 IF 'R0' IS NOT ZERO
DJNZ R1,L1 ; DJNZ-DEC AND JUMP TO 'L1 IF 'R1' IS NOT ZERO
DJNZ R2,L1 ; DJNZ-DEC AND JUMP TO 'L1 IF 'R2' IS NOT ZERO
RET ;

TABLE: DB 0F9H,0A4H,0B0H,8EH,99H,92H,82H,86H,0F8H,80H,98H,0C0H,88H,0C0H,80H,0C6H

END

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THIS IS THE END OF THE PROGRAM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
How amazing it is to know different kind of 'language'
And copyright NG KHIN HOOI.

1 comment:

BabySiiaOzz said...

swt.. so confusing.. btw, uu can help me make header out of my pic? TT.....