Thursday, February 28, 2008

Good Programs

WRITE A PROGRAM TO PUT THE NUMBER 8DH IN RAM LOCATIONS 30H TO 34H WITH THREE DIFFERENT METHOD.

; FIRST METHOD

ORG 0000H

MOV 30H, #8DH
MOV 31H, #8DH
MOV 32H, #8DH
MOV 33H, #8DH
MOV 34H, #8DH

END

; SECOND METHOD

ORG 0000H
MOV A, #8DH
MOV 30H, A
MOV 31H, A
MOV 32H, A
MOV 33H, A
MOV 34H, A

END

; THIRD METHOD


ORG 0000H
MOV SP, #30H
MOV 30H, #8DH
PUSH 30H
PUSH 30H
PUSH 30H
PUSH 30H
END
WRITE A PROGRAM WHICH DOUBLE THE NUMBER IN R2 AND PUT THE RESULT IN REGISTER R3 (LSB) AND R4 (MSB).

ORG 0000H

MOV R2, #04H ; STORE SAMPLE DATA IN R2
MOV A, R2
MOV B, #02H
MUL AB
MOV R3,A
MOV R4,B

END


DIVIDE THE DATA IN RAM LOCATION 1FH BY THE NUMBER 09H AND PLACE THE QUOTIENT IN R4 AND REMAINDER IN R5.


ORG 0000H
MOV 1FH, #04H ; STORE SAMPLE DATA IN 1FH
MOV A, 1FH
MOV B, #09H
DIV AB
MOV R4,A
MOV R5, B
END


WRITE A PROGRAM WHICH READS UNSIGNED NUMBER FROM PORT 2 AND MULTIPLIES IT WITH THE NUMBER IN R3 AND PUT THE RESULT IN EXTERNAL RAM LOCATION 10H(MSB) AND 11H(LSB).

ORG 0000H

MOV P2, #0FFH
MOV A, P2
MOV B, R3
MUL AB

MOV DPTR, #0011H
MOVX @DPTR, A

MOV DPTR, #0010H
MOV A, B
MOVX @DPTR, A

END


WRITE A PROGRAM THAT ADD THE UNSIGNED NUMBERS FOUND IN INTERNAL RAM LOCATION 25H, 26H AND 27H TOGETHER AND PUT THE RESULT IN RAM LOCATIONS 31H(LSB) AND 30(MSB).

ORG 0000H

MOV 25H, #0F0H
MOV 26H, #0FH
MOV 27H, #01H

MOV 30H, #00H
MOV 31H, #00H

MOV A, 25H
ADD A, 26H
JNC NEXT
INC 30H
NEXT:
ADD A, 27H
MOV 31H,A
JNC STOP
INC 30H

STOP:
AJMP STOP



WRITE A PROGRAM TO GET THE CONTENTS OF THE DPTR TO PC


ORG 0000H
MOV DPTR, #1234H ;STORE SAMPLE DATA IN DPTR
PUSH DPL
PUSH DPH
RET

END



WRITE A PROGRAM TO PUT A RANDOM NUMBER AT 3CH AND INCREMENT IT UNTILL IT EQUALS 2AH.

ORG 0000H

MOV 3CH, #04H ;STORE SAMPLE DATA IN 3CH

MAIN: INC 3CH
MOV A, 3CH
CJNE A, #2AH, MAIN

END



WRITE A PROGRAM THAT SWAP THE NIBBLES OF R0 AND R1 SO THAT THE LOW NIBBLES OF R0 SWAPS WITH THE HIGH NIBBLES OF R1 AND HIGH NIBBLE OF R0 SWAPS WITH THE LOW NIBBLE OF R1.


ORG 0000H

MOV R0, #12H ; STORE SAMPLE DATA IN R0
MOV R1, #34H ; STORE SAMPLE DATA IN R1

MOV 30H, R0
MOV 31H, R1

MOV A,30H
SWAP A
MOV R1, A

MOV A, 31H
SWAP A
MOV R0, A

END



WRITE A PROGRAM OF 8051 TO MAKE OR OPERATION OF TWO BYTES FROM ARRRAYS STARTING FROM EXTERNAL RAM LOCATION 4000H TO 4009H AND 5000H TO 5009H. STORE RESULT AT EXTERNAL RAM LOCATION 6000H TO 6009H. MAKE OR OPRATION WITHOUT ORL INSTRUCTION.

ORG 0000H
MOV R0, #00H
MAIN:
MOV DPL, R0
MOV DPH, #40H
MOVX A, @DPTR
CPL A
MOV 40H, A

MOV DPH, #50H
MOVX A, @DPTR
CPL A

ANL A, 40H
CPL A
MOV DPH, #60H
MOVX @DPTR, A

INC R0
CJNE R0, #0AH, MAIN

END


CONVERT A SERIES OF PACKED BCD NUMBERS LOCATED IN ROM LOCATION STARTING FROM 0300H TO 0304H INTO ASCII CODE. STORE RESULT AT INTERNAL RAM LOCATION STARTING FROM 40H.

ORG 0000H
MOV DPTR, #0300H
MOV R1,#40H

MAIN: MOV A, #00H
MOVC A, @A+DPTR
MOV R0, A
ANL A, #0FH
ADD A,#30H
MOV @R1,A

MOV A,R0
SWAP A
ANL A,#0FH
ADD A, #30H
INC R1
MOV @R1, A

INC R1
INC DPTR

CJNE R1, #4AH, MAIN

PASS: AJMP PASS

END


MAKE PROGRAM WHERE LOOPS RUN SO LED L1 IS "ON", WHEN SWITCH S1 IS PRESS AND LED L2 IS "ON" WHEN SWITCH S2 IS PRESS.

ORG 0000H

SETB P3.0
SETB P3.1

START: MOV C, P3.0
MOV P2.0, C
MOV C, P3.1
MOV P2.1, C
AJMP START

END



INTERFACE ONE COMMON CATHODE TYPE SEVEN SEGMENT DISPLAY WITH PORT 1 AND DRAW THE NECESSARY HARDWARE DIAGRAM. THEN WRITE A PROGRAM THAT DISPLAYS PATTERN 'E' FOR 1 SECOND AND OFF FOR 1 SECOND ALSO, CONTINUOUSLY.

ORG 0000H

MAIN:

MOV P2, #01111001b
ACALL DELAY

MOV P2, #00000000b
ACALL DELAY

AJMP MAIN


DELAY: MOV R1, #07H ; 1 Second delay loop
LOOP3: MOV R2, #00H
LOOP2: MOV R3, #00H
LOOP1: DJNZ R3, LOOP1
DJNZ R2, LOOP2
DJNZ R1, LOOP3
RET

END



USING SOFTWARE POLLED TIMER APPROACH WRITE A PROGRAM WHICH BLINKS LED CONNECED AT BIT 0 OF PORT 1. LED SHOULD REMAIN ON FOR 500MS AND OFF FOR 500MS. USE TIMER 0 TO GENERATE BASIC 1MS DELAY.


ORG 0000H


MOV TMOD,#01H ; 65536-1000=64536(FC18H)
MOV TL0, #18H ;ASSUME 12MHZ CRYSTAL FR. MOV TH0, #0FCH
SETB TR0

MOV DPTR,#000CH ;200H=512D

MAIN:
JNB TF0, MAIN
MOV TL0, #18H
MOV TH0, #0FCH
CLR TF0

INC DPTR
MOV A, DPH
CJNE A, #02H, MAIN
CPL P1.0
MOV DPTR, #000CH
AJMP MAIN

END


WRITE A PROGRAM USING INTERRUPTS TO GENERATE A SQUARE WAVE OF 2KHZ ON PIN P1.5. USE TIMER 0 AND MODE 1.

;ASSUME 12MHZ CRYSTAL FREQUENCY
;1/2KHZ=0.5MS
; 65536-250 =65286 (FF06H)

ORG 0000H
MOV TMOD,#01H
SETB TR0

START: MOV TL0, #06H
MOV TH0, #0FFH

HERE: JNB TF0, HERE
CPL P1.5
AJMP START

END


ORG 0000H

MAIN:
MOV TMOD,#10H
ACALL DELAY

PASS: AJMP PASS

DELAY:
;MC =3+3R1+2R1R2
MOV R1, #0C8H ;R1=200, R2=11
L2: MOV R2, #0BH
L1: DJNZ R2, L1
DJNZ R1, L2
RET
END

WRITE A PROGRAM TO USE TIMER 1 TO INTERRUPT THE PROGRAM AFTER A DELAY OF 2 MS. (CRYSTAL FREQUENCY = 10 MHZ).

ORG 0000H
AJMP MAIN ; 2000/1.2=1667,65536-1667=63869 (F97DH)

ORG 001BH
MOV TL1,#7DH
MOV TH1, #0F9H
RETI

MAIN: MOV IE, #88H
MOV TMOD,#10H
MOV TL1, #7DH
MOV TH1, #0F9H
SETB TR1

TIMEPASS: LJMP TIMEPASS

END


WRITE AN ASEMBLY LANGUAGE PROGRAM TO MEASURE AN UNKNOWN FREQUENCY CONNECTED ON PIN P3.4(T0). USE TIMER 0 IN COUNTER MODE.

ORG 0000H


MAIN: MOV TMOD,#05H ; TIMER-0 IN MODE-1 AS COUNTER
MOV TL0, #00H
MOV TH0, #00H
SETB TR0

ACALL DELAY ;5+3R3+3R3R4+2R3R4R5
CLR TR0
MOV R0,TL0
MOV R1,TH0

AJMP MAIN

DELAY: MOV R3, #08H
LOOP3: MOV R4, #00H
LOOP2: MOV R5, #004H
LOOP1: DJNZ R5, LOOP1
DJNZ R4, LOOP2
DJNZ R3, LOOP3
RET

END



WRITE A PROGRAM WHICH CONTINUOUSLY READS FROM P0 AND SEND IT TO P1, WHILE SIMULTANEOUSLY CREATING SQUAREWAVE OF 5 KHZ ON PIN 2.1. USE TIMER 0 INTERRUPT SERVICE ROUTINE. INTIALIZE TIMER 0 IN MODE-2.


ORG 0000H
AJMP MAIN ;ASSUME 12MHZ CRYSTAL FR.
;1/5KHZ=0.2MS
; 256-100 =156 (9CH)

ORG 000BH
CPL P2.1
RETI

MAIN: MOV IE, #82H
MOV TMOD,#02H
MOV TH0, #9CH
SETB TR0

SEND: MOV P0, #0FFH
MOV A, P0
MOV P1, A
AJMP SEND

END



WRITE AN ALP USING INTERRUPTS TO DO FOLLOWING TASK,(1) MAKE TIMER TO GENERATE A SQUAREWAVE OF 4KHZ FREQUNCY ON P2.0, (2) ASSUME THAT INT1 PIN IS CONNECTED TO A SWITCH THAT IS NORMALLY HIGH, WHWNEVER IT GOES LOW, IT SHOULD READ PORT P1, COMPLEMENT THE DATA AND SEND IT TO PORT P2.

ORG 0000H
AJMP MAIN

ORG 000BH
CPL P2.0
RETI

ORG 0013H
AJMP IN_EXT

MAIN:
MOV IE, #86H
MOV IP, #04H

MOV TMOD,#0AH
MOV TH0, #83H
SETB TR0

;ASSUME 12MHZ CRYSTAL FREQUENCY
;1/4KHZ=0.25MS, 125US FOR HALF PERID
; 256-125 =131 (83H)


PASS: AJMP PASS


IN_EXT: MOV P1, #0FFH
MOV A, P1
CPL A
MOV P2, A
RETI
END
MENTION THE STEPS IN PROGRAMMING THE 8051 TO TRANSFER CHARACTER BYTES SERIALLY BY METHOD OF POLLING. THEN WRITE A PROGRAM TO TRANSMITT "NGU" SERIALLY AT 2400 BAUDRATE. USE TIMER 1 TO SET BAUD RATE.

ORG 0000H

MOV TMOD,#20H
MOV SCON,#50H
MOV TH1,#0F4H
SETB TR1

MOV A, #'N'
ACALL SEND_PC
MOV A, #'G'
ACALL SEND_PC
MOV A, #'U'
ACALL SEND_PC

PASS: AJMP PASS

SEND_PC: MOV SBUF, A
HERE: JNB TI, HERE
CLR TI
RET

END



WRITE A PROGRAM WITH TWO ISRS FOR INT0 AND INT1 RESPECTIVELY SATISFYING FOLLOWING CONDITIONS. WHEN THERE IS NO INTERRUPT, MAINLINE PROGRAM SHOULD BLINK GREEN LED THROUGH PORT PIN P1.0 FOR 1 SECOND ON AND 1 SCOND OFF CONTINUOUSLY. WHEN EDGE TRIGGER INTERRUPT WILL COME AT INT0, GLOW RED LED THROUGH PORT PIN P1.1 FOR 1 SECOND, THEN TURN IT OFF AND RETURN TO MAINLINE. WHEN EDGE TRIGGER INTERRUPT WILL COME AT INT1, GLOW YELLOW LED THORUGH PORT PIN P1.2 FOR 1 SECOND, THEN TURN IT OFF AND RETURN TO MAINLINE PROGRAM. DRAW NECESSARY HARDWARE.


ORG 0000H
AJMP MAIN

GREEN EQU P1.0
RED EQU P1.1
YELLOW EQU P1.2

ORG 0003H
AJMP ISR_IN0

ORG 0013H
AJMP ISR_IN1


MAIN: MOV IE,#85H
MOV TCON,#05H
MOV P1, #00H

LOOP: SETB GREEN
ACALL DELAY
CLR GREEN
ACALL DELAY
AJMP LOOP

ISR_IN0:
SETB RED
ACALL DELAY
CLR RED
RETI

ISR_IN1:
SETB YELLOW
ACALL DELAY
CLR YELLOW
RETI


DELAY: ; 1 SECOND DELAY
MOV R1, #08H ; 5+3R1+3R1R2+2R1R2R3
LOOP3: MOV R2, #00H
LOOP2: MOV R3, #00H
LOOP1: DJNZ R3, LOOP1
DJNZ R2, LOOP2
DJNZ R1, LOOP3
RET


END



EXPLAIN WITH THE HELP OF DIAGRAM THE NECESSARY CIRCUIT TO INTERFACE 4X4 KEYPAD WITH 8051. DISCUSS THE LOGICAL STEPS TO DETECT THE KEY PRESSED AND ENCODE IT. WRITE AN ALPTO DISPLAY THE DETECTED KEY ON ONE 7-SEGMENT DISPLAY.

ORG 0000H



FIND_ROW:

MOV P3, #0FH

MOV R0,#00H
JNB P3.0, FIND_COLUMN
MOV R0,#01H
JNB P3.1, FIND_COLUMN
MOV R0,#02H
JNB P3.2, FIND_COLUMN
MOV R0,#03H
JNB P3.3, FIND_COLUMN
AJMP FIND_ROW



FIND_COLUMN:
MOV P3, #0F0H

MOV R1,#00H
JNB P3.4, CALULATE_KEY
MOV R1,#01H
JNB P3.5, CALULATE_KEY
MOV R1,#02H
JNB P3.6, CALULATE_KEY
MOV R1,#03H
JNB P3.7, CALULATE_KEY
AJMP FIND_ROW


CALULATE_KEY:

MOV A, R0
RL A
RL A
ADD A, R1
ACALL CONVERT
MOV P2, A
AJMP FIND_ROW

CONVERT:
INC A
MOVC A, @A+PC
RET

DB 00111111B
DB 00000110B
DB 01011011B
DB 01001111B
DB 01100110B
DB 01101101B
DB 01111101B
DB 00000111B
DB 01111111B
DB 01101111B
DB 01110111B
DB 01111100B
DB 00111001B
DB 01011110B
DB 01111001B
DB 01110001B

END


INTERFACE LCD AND WRITE A PROGRAM TO DIPLAY “Hello India”.

ORG 0000H

MOV A, #3CH
ACALL COMNWRT

MOV A, #01H
ACALL COMNWRT

MOV A, #0EH
ACALL COMNWRT



MOV A, #06H
ACALL COMNWRT

MOV A, #84H
ACALL COMNWRT





MOV A, #'H'
ACALL DATAWRT


MOV A, #'E'
ACALL DATAWRT

MOV A, #'L'
ACALL DATAWRT

MOV A, #'L'
ACALL DATAWRT

MOV A, #'O'
ACALL DATAWRT

MOV A, #0C4H
ACALL COMNWRT


MOV A, #'I'
ACALL DATAWRT

MOV A, #'N'
ACALL DATAWRT

MOV A, #'D'
ACALL DATAWRT

MOV A, #'I'
ACALL DATAWRT

MOV A, #'A'
ACALL DATAWRT


MAIN:AJMP MAIN

COMNWRT:
ACALL READY
MOV P2, A
CLR P1.5 ;RS
CLR P1.6 ;R/W
SETB P1.7 ;E
NOP
NOP
NOP
NOP
CLR P1.7 ;E
RET

DATAWRT:
ACALL READY
MOV P2, A
SETB P1.5 ;RS
CLR P1.6 ;R/W
SETB P1.7 ;E
NOP
NOP
NOP
NOP
CLR P1.7 ;E
RET

READY:
SETB P2.7
CLR P1.5 ;RS
SETB P1.6 ;R/W
REPEAT: CLR P1.7 ;E
NOP
NOP
NOP
NOP
SETB P1.7 ;E
JB P2.7, REPEAT
CLR P1.7 ;E
RET

END

No comments: