0% found this document useful (0 votes)
25 views14 pages

Microprocessor Observation 6,7,8,9,10

The document describes an assembly language program to generate square waves using a timer/counter for different frequencies. It explains the aim is to write an ALP to generate square waves using a timer/counter. It also provides the working procedure which involves connecting pins and using a timer/counter to toggle the pin for square wave generation at different frequencies.

Uploaded by

abirami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views14 pages

Microprocessor Observation 6,7,8,9,10

The document describes an assembly language program to generate square waves using a timer/counter for different frequencies. It explains the aim is to write an ALP to generate square waves using a timer/counter. It also provides the working procedure which involves connecting pins and using a timer/counter to toggle the pin for square wave generation at different frequencies.

Uploaded by

abirami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

EX NO:6 ALP-INTERFACING SUBROUTINE

AIM:
To interface subroutine using assembly language program

PROGRAM:

start:

MOV R0, #0 ; clear R0 - the first key is key0

; scan row0
SETB P0.3 ; set row3
CLR P0.0 ; clear row0
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row1
SETB P0.0 ; set row0
CLR P0.1 ; clear row1
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row2
SETB P0.1 ; set row1
CLR P0.2 ; clear row2
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row3
SETB P0.2 ; set row2
CLR P0.3 ; clear row3
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)

JMP start ; | go back to scan row 0


; | (this is why row3 is set at the start of the program
; | - when the program jumps back to start, row3 has just
been scanned)

finish:
JMP $ ; program execution arrives here when key is found - do
nothing

; column-scan subroutine
colScan:
JNB P0.4, gotKey ; if col0 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.5, gotKey ; if col1 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.6, gotKey ; if col2 is cleared - key found
INC R0 ; otherwise move to next key
RET ; return from subroutine - key not found
gotKey:
SETB F0 ; key found - set F0
RET ; and return from subroutine
Output:

RESULT:
Thus ALP- to implement subroutine concept was completed successfully.
EX NO: 7 ALP- INTERFACING MATRIX KEYBOARD

AIM:
To interface matrix keyboard using assembly language program.

ALGORITHM:
1. Start the program
2. Set a row and column list
3. Each and every press scan all rows and column
4. Make the row and column of the pressed key and others as one
5. Show the result in R0
6. Stop the program

PROGRAM:

MOV TMOD, #50H ; put timer 1 in event counting mode


SETB TR1 ; start timer 1

MOV DPL, #LOW(LEDcodes) ; | put the low byte of the start address of the
; | 7-segment code table into DPL

MOV DPH, #HIGH(LEDcodes) ; put the high byte into DPH

CLR P3.4 ;|
CLR P3.3 ; | enable Display 0
again:
CALL setDirection ; set the motor's direction
MOV A, TL1 ; move timer 1 low byte to A
CJNE A, #10, skip ; if the number of revolutions is not 10 skip next
instruction
CALL clearTimer ; if the number of revolutions is 10, reset timer 1
skip:
MOVC A, @A+DPTR ; | get 7-segment code from code table - the
index
into the table is
; | decided by the value in A
; | (example: the data pointer points to the start of
the
; | table - if there are two revolutions, then A will
contain two,
; | therefore the second code in the table will be
copied to A)

MOV C, F0 ; move motor direction value to the carry


MOV ACC.7, C ; and from there to ACC.7 (this will ensure
Display 0's decimal point
; will indicate the motor's direction)

MOV P1, A ; | move (7-seg code for) number of revolutions


and motor direction
; | indicator to Display 0
JMP again ; do it all again

setDirection:
PUSH ACC ; save value of A on stack
PUSH 20H ; save value of location 20H (first bit-addressable

; location in RAM) on stack


CLR A ; clear A
MOV 20H, #0 ; clear location 20H
MOV C, P2.0 ; put SW0 value in carry
MOV ACC.0, C ; then move to ACC.0
MOV C, F0 ; move current motor direction in carry
MOV 0, C ; and move to LSB of location 20H (which has
bit address 0)

CJNE A, 20H, changeDir ; | compare SW0 (LSB of A) with F0 (LSB of


20H)
; | - if they are not the same, the motor's direction

needs to be reversed

JMP finish ; if they are the same, motor's direction does not
need to be changed
changeDir:
CLR P3.0 ;|
CLR P3.1 ; | stop motor

CALL clearTimer ; reset timer 1 (revolution count restarts when


motor direction changes)
MOV C, P2.0 ; move SW0 value to carry
MOV F0, C ; and then to F0 - this is the new motor direction
MOV P3.0, C ; move SW0 value (in carry) to motor control bit
1
CPL C ; invert the carry
MOV P3.1, C ; | and move it to motor control bit 0 (it will
therefore have the opposite
; | value to control bit 1 and the motor will start
; | again in the new direction)
finish:
POP 20H ; get original value for location 20H from the
stack
POP ACC ; get original value for A from the stack
RET ; return from subroutine

clearTimer:
CLR A ; reset revolution count in A to zero
CLR TR1 ; stop timer 1
MOV TL1, #0 ; reset timer 1 low byte to zero
SETB TR1 ; start timer 1
RET ; return from subroutine

LEDcodes: ; | this label points to the start address of the 7-segment code table which is
; | stored in program memory using the DB command below

DB 11000000B, 11111001B, 10100100B, 10110000B, 10011001B, 10010010B, 10000010B,


11111000B, 10000000B, 10010000B

OUTPUT:
RESULT:
Thus ALP –to interface matrix keyboard was executed successfully.

EX NO: 8 ALP- INTERFACING 7- SEGMENT LED

AIM:
To interface 7- Segment LED using assembly language program.

PROGRAM:
start:
SETB P3.3 ;|
SETB P3.4 ; | enable display 3
MOV P1, #11111001B ; put pattern for 1 on display
CALL delay
CLR P3.3 ; enable display 2
MOV P1, #10100100B ; put pattern for 2 on display
CALL delay
CLR P3.4 ;|
SETB P3.3 ; | enable display 1
MOV P1, #10110000B ; put pattern for 3 on display
CALL delay
CLR P3.3 ; enable display 0
MOV P1, #10011001B ; put pattern for 4 on display
CALL delay
JMP start ; jump back to start

; a crude delay
delay:
MOV R0, #200
DJNZ R0, $
RET
Output:

RESULT:
Thus ALP - to interface 7-Segment LED was executed successfully.
EX NO: 9 ALP-To generate square wave using Timer/Counter for different
Frequencies.

Aim:

To write ALP to generate square wave using Timer/Counter for different Frequencies.

Working procedure for DAC:

1. Connect the 9 pin D typeconnector from the DAC module to the Mp/Mc kit.

2.Connect the 26-pin connector from the DAC module to Mp/Mc kit.

3.Connect the keyboard to the Mp/Mc kit.

4.Switch on the power supply.

5.Assemble your program.

6.Execute it and measure the output voltage/waveform at the front panel of the DAC module.

7.Vary the digital count,execute the program and measure the output analog voltage.

8.Take number of reading and if required draw the graph,DAC input counts Vs output voltage to
check the linearity.

9.Switch off the power supply and remove all the connections.

SQUARE WAVE GENERATION:

User can change the delay period in order to get the desired frequency of the wave
form.User can view the output at DAC O/P,through the CRO.
ADDRESS OP-CODE MNEMONICS COMMENTS

9000 74 80 mov a,#80 ;control word

9002 90 40 03 mov dptr,#4003 ;control register address

9005 F0 movx @dptr,a ;all ports as o\p

9006 74 80 mov a,#80 ;give the dig i\p as data-

9008 90 40 01 mov dptr,#4001 ;port b address

900B F0 movx @dptr,a ;digital data to port b

900C 12 91 00 lcall 9100 ;call delay routine

900F 74 FF mov a,#ff ;digital data

9011 F0 movx @dptr,a ;digital data to port B

9012 12 91 00 lcall 9110 ;call delay routine

9015 02 90 06 ljump 9006 ;jump to start

DELAY

ADDRESS OP-CODE MNEMONICS

9100 79 40 mov r1,#40

9102 74 FF mov a,#FF

9104 00 nop

9105 00 nop

9106 00 nop

9107 00 nop
9108 14 dec a

9109 70 F9 jnz 9104

910B D9 F5 djnz rl,9102

910D 22 ret

CALCULATION:

1 count (decimal) =VCC/256

=5/256

=0.0196v

RESULT:

Thus the program of ALP-To generate square wave using Timer/Counter for different
Frequencie was executed successfully.
EX NO: 10 INTERFACING STEPPER MOTOR WITH 8051
MICROCONTROLLER

AIM:

To write an Assembly Language Program to interface stepper motor with 8051


microcontroller.

APPARATUS REQUIRED:

8051 Trainer Kit, Power Cable.

PROGRAM:

ADDRESS OP-CODE LABEL MNEMONICS COMMENTS

ORG (16-bit)H
4100

4100 7C33 START: MOV R4,#33H Move the data 33 to R4

MOV DPTR,# Move the data pointer with


4102 904144 L2:
FORWARD value for forward.

4105 12411C LCALL L1 Call L1.

Decrement and jump on no


4108 DCF8 DJNZ R4,L2
Zero to L2.
410A 12413B LCALL DELAY Call the delay.

410D 7C33 L3: MOV R4,#33H Move the data 33 to R4


MOV DPTR,# Move the data pointer with
410F 904148
REVERSE the value for reverse.
4112 12411C LCALL L1
Decrement and jump on no
4115 DCF8 DJNZ R4,L3
Zero to L3.
4117 12413B LCALL DELAY Call the delay.

411A 80E4 SJMP START Jump to start.


411C 7804 L1 MOV R0,#04H Move the data 04 to R0

Move the value in data


411E EO LOOP: MOVX A,@DPTR
pointer to A.
Stack pointer is
411F C083 PUSH 83H
incremented by 1.
Stack pointer is
4121 C082 PUSH 82H
incremented by 1.
Move the value of data
4123 90FFC0 MOV DPTR,#OFF20H
pointer
4126 7A04 MOV R2,#04H Move R2 with 04

Move the data to the


4128 7905 L7: MOV R1,#05H
memory location 05H
Move the data to the
412A 7BFF L6: MOV R3,#0FFH
memory location 0FFH
Decrement and jump on no
412C DBFE L4: DJNZ R3,L4
Zero to L4.
Decrement and jump on to
412E D9FA DJNZ R1,L6
L6

4130 DAF6 DJNZ R2,L7 Decrement and jump to L7

Move the data in A to data


4132 F0 MOVX @DPTR,A
pointer.

Stack pointer is read and is


4133 D082 POP 82H
decremented by 1.

Stack pointer is read and is


4135 D083 POP 83H
decremented by 1.

4137 A3 INC DPTR Increment the data pointer.

Decrement and jump on no


4138 D8E4 DJNZ R0,LOOP
Zero to LOOP.

413A 22 RET Return.


Move the data to the
413B 7D01 DELAY: MOV R5,#01H
memory location 01H

Move the data to the


413D 7A05 L9: MOV R2,#05H
memory location 05H

Decrement and jump on no


413F DAFE L8: DJNZ R2,L8
zero to 8

Decrement and jump on no


4141 DDFA DJNZ R5,L9
Zero to LOOP.

4143 22 RET Return

4144 0905060A FORWARD: 09H,05H,06H,0AH

414B 0A060509 REVERSE: 0AH,06H,05H,09H

RESULT:
Thus the program to interface the stepper motor with 8051 was executed.

You might also like