Switch and LEDs
SingleLEDblinking
ORG 00H;
AGAIN:SETB P2.0;
ACALL DELAY;
CLR P2.0;
ACALL DELAY;
SJMP AGAIN;
DELAY:MOV R5,#0FFH;
REPEAT:MOV R6,#0FFH;
DJNZ R6,$;
DJNZ R5,REPEAT;
RET;
END;
Blink of Alternative LEADs
org 00h;
again:mov p2,#0aah;
acall delay;
mov p2,#55h;
acall delay;
sjmp again;
delay:mov r3,#0ffh;
back:mov r4,#0ffh;
djnz r4,$;
djnz r3,back;
ret;
end;
SingleSwitchandSingleLED
org 00h;
mov p2,#00h;
again1:clr p2.0;
again2:jnb p1.0,glow;
sjmp again1;
glow:setb p2.0;
sjmp again2;
end;
eightLEDswithSwitchs
org 00h;
mov p2,#00h;
again:mov a,p1;
mov p2,a;
sjmp again;
end;
LED Interfacing
ORG 00H;
MOV DPTR,#CMD;
BACK:CLR A;
MOVC A,@A+DPTR;
JZ NEXT;
ACALL COMMAND;
INC DPTR;
SJMP BACK;
COMMAND:CLR P3.4;
SETB P3.5;
MOV P0,A;
ACALL DELAY;
CLR P3.5;
RET;
NEXT:MOV DPTR,#MSG;
BACK1:CLR A;
MOVC A,@A+DPTR;
JZ STOP;
ACALL SOURCE;
INC DPTR;
SJMP BACK1;
SOURCE:SETB P3.4;
SETB P3.5;
MOV P0,A;
ACALL DELAY;
CLR P3.5;
RET;
DELAY:MOV R4,#0FFH;
XX:MOV R3,#0FFH;
DJNZ R3,$;
DJNZ R4,XX;
RET;
STOP:SJMP STOP;
CMD:DB 38H,01H,0EH,06H,0c0H,0;
MSG:DB "Welcome ECE",0;
END;
Serial Transmission
ORG 00H;
MOV TMOD,#20H;
MOV SCON,#50H;
MOV TH1,#0FDH;
MOV DPTR,#MSG;
BACK: CLR A;
MOVC A,@A+DPTR;
JZ NEXT;
ACALL TRANSMIT;
INC DPTR;
SJMP BACK;
NEXT:SJMP NEXT;
TRANSMIT: SETB TR1;
MOV SBUF,A;
JNB TI,$;
CLR TI;
RET;
MSG: DB "WELCOME,ECE,MCI,LAB",0;
END;
Serial Reception(TERA TERM)
MOV TMOD,#20H;
MOV SCON,#50H;
MOV TH1,#0FDH;
AGAIN:CLR A;
ACALL RECEIVE;
MOV P2,A;
SJMP AGAIN;
RECEIVE:SETB TR1;
JNB RI,$;
CLR RI;
MOV A,SBUF;
RET;
END;
Keypad program
EN equ P3.5
RS equ P3.4
mov A,#38H ; Setting Up the LCD
lcall command
mov A,#0EH ; Display On
lcall command
mov A,#06H ; Entry Mode
lcall command
mov a,#80H
lcall command
;lcall disp ; Function Disp Called
;mov a,#02H ; Setting DDRAM Address to Home position
;lcall command
;lcall delay1; Displays BOTSKOOL SHOBHIT ON FIRST LINE OF LCD
;mov a,#'K'
;lcall datw
;NOP
;mov a,#'E'
;lcall datw
;NOP
;mov a,#'Y'
;lcall datw
;mov a,#'T'
;lcall datw
;NOP
;mov a,#'E'
;lcall datw
;NOP
;mov a,#'X'
;lcall datw
;NOP
;mov a,#'T'
;lcall datw
;NOP
MOV A,#255 ; Moving Value 255 to PORT 3
MOV P1,A; Keypad Scan Begins
sd:
lcall delay1
lcall key1
lcall delay1
lcall key2
lcall delay1
lcall key3
lcall delay1
lcall key4
lcall delay1
lcall sd; Function to Send Commands to LCD
command:
clr RS
setB EN
MOV P0,A
lcall delay
clr EN
RET; Function to Clear the DDRAM Content
;clear:
;mov A,#01H
;lcall command
;lcall delay
;mov A,#02H ; Set The DDRAM Address to Home Position
;lcall command
;lcall delay
;RET; Function to Display Data on LCD Screen
datw:
SETB RS
SETB EN
MOV P0,A
lcall delay
clr EN
RET; Function to Display The Key Pressed
datw1:
lcall delay1
lcall disp
lcall delay1
MOV A,R7
lcall datw
RET; Generating Small Delay
delay:
mov r0,#255
loop:DJNZ r0,loop;
RET;Generating a Bigger Delay
delay1:
mov r1,#255
loop1:
mov r3,#120
loop2:
djnz r3,loop2
djnz r1,loop1
RET; Checking for Key Press on The First Column of 4x4 Matrix
KEY1:
;MOV A,r5
;MOV r6,A
clr p1.4
MOV A,p1
ANL A,#0FH
MOV r2,A
cjne r2,#14,n1
MOV r7,#'1'
lcall datw1
lcall delay1
n1:cjne r2,#13,n2
mov r7,#'5'
lcall datw1
lcall delay1
n2:cjne r2,#11,n3
mov r7,#'9'
lcall datw1
lcall delay1
n3:cjne r2,#7,n4
mov r7,#'D'
lcall datw1
lcall delay1
n4:lcall delay1
SETB P1.4
RET; Checking for Key Press on the Second Column of 4x4 Matrix
KEY2:
clr p1.5
MOV A,p1
ANL A,#0FH
MOV r2,A
cjne r2,#14,q1
mov r7,#'2'
lcall datw1
lcall delay1
q1:cjne r2,#13,q2
mov r7,#'6'
lcall datw1
lcall delay1
q2:cjne r2,#11,q3
mov r7,#65; A=65
lcall datw1
lcall delay1
q3:cjne r2,#7,q4
mov r7,#'E'
lcall datw1
lcall delay1
q4:lcall delay
SETB p1.5
RET; Checking for Key Press On The Third Column of 4x4 Matrix
KEY3:
clr p1.6
MOV A,p1
ANL A,#0FH
MOV r2,A
cjne r2,#14,w1
mov r7,#'3'
lcall datw1
lcall delay1
w1:cjne r2,#13,w2
mov r7,#'7'
lcall datw1
lcall delay1
w2: cjne r2,#11,w3
mov r7,#'B'
lcall datw1
lcall delay1
w3: cjne r2,#7,w4
mov r7,#'F'
lcall datw1
lcall delay1
w4: lcall delay1
SETB p1.6
RET; Checking for Key Press on the Fourth Column of 4x4 Matrix
KEY4:
clr p1.7
MOV A,p1
ANL A,#0FH
MOV r2,A
cjne r2,#14,e1
mov r7,#'4'
lcall datw1
lcall delay1
e1:cjne r2,#13,e2
mov r7,#'8'
lcall datw1
lcall delay1
e2: cjne r2,#11,e3
mov r7,#'C'
lcall datw1
lcall delay1
e3: cjne r2,#7,e4
mov r7,#'G'
lcall datw1
lcall delay1
e4: lcall delay1
SETB p1.7
RET
disp:
mov a,#0c0H ; Setting DDRAM Address on Second Line
lcall command; Clearing the Previous Key Pressed Information from Screen
mov a,#' '
lcall datw
mov a,#' '
lcall datw
mov a,#' '
lcall datw
mov a,#' '
lcall datw
mov a,#' '
lcall datw
mov a,#' '
lcall datw
mov a,#0c3H ; Setting DDRAM Address on Second Line To Display “Key Pressed”
lcall command
RET
END
Seven Segment Display
org 00h;
mov p0,#00h;
back:setb p3.5;
mov p0,#86h;
acall delay;
clr p3.5;
setb p3.4;
mov p0,#0c6h;
acall delay;
clr p3.4;
setb p3.3;
mov p0,#86h;
acall delay;
clr p3.3;
sjmp back;
delay:mov r4,#255;
back1:mov r5,#255;
djnz r5,$;
djnz r4,back1;
ret;
End;
DOOR SENSOR BUZZER
org 00h;
mov p2,#00h;
again1:clr p2.7;
again2:jnb p1.0,buz;
sjmp again1;
buz:setb p2.7;
sjmp again2;
end;
Elevator Interfacing
ORG 0H
sjmp 30h
org 30h
START:
CLR A
MOV R0,A /*Elevator at Ground Floor*/
MOV R1,A
LOOP1:
MOV A,R1
ORL A,#0F0H /*Clear all requests by clearing the flipflops*/
mov P0,a
MOV DPTR,#FLOOR /*move the floors look up table into DPTR*/
LOOP2:
MOV A,P1 /*Get the status of request switches by reading P1*/
ORL A,#0F0H /*Since the No.of Floors are 4*/
MOV R2,A /*it checks for only lower nibble*/
INC A
JZ LOOP2 /*Any request?No,loop back.*/
LOOP3:
MOV A,R2 /* Find the Floor number using Look up table*/
RRC A
MOV R2,A
JNC DECIDE
INC DPTR
SJMP LOOP3
DECIDE:
acall DELAY /*Get the floor number*/
CLR A
MOVC A,@A+DPTR
CJNE A,1,L1 /*Compare with current floor number*/
SJMP RESET /*if equal reset the request*/
L1:
JC DOWN /*other wise if lower elevator goes down*/
UP:
INC R1 /* if higher Elevator goes up*/
MOV A,R1
ORL A,#0F0H /*Elev moving Direction indicaton*/
mov P0,a /*on LEDs*/
SJMP DECIDE
DOWN:
DEC R1 /*Elevator goes down*/
MOV A,R1
ORL A,#0F0H /*Direction indication */
mov P0,a /*on LEDs*/
SJMP DECIDE
RESET:
MOV A,#05H /*Turn off Corresponding request*/
ADD A,dpl /*indication LED */
MOV dpl,A /*Get the corresponding code from look up table */
CLR A /*to turn off the LED*/
MOVC A,@A+DPTR
mov P0,a
SJMP LOOP1
DELAY:
mov r3,#0ffh
decr:
mov r4,#0ffh
djnz r4,$
djnz r3,decr
ret /*Look up table for corresponding floors*/
FLOOR:
DB 00H,03H,06H,09H,00H,0E0H,0D3H,0B6H,79H
END
No comments:
Post a Comment