0% found this document useful (0 votes)
121 views26 pages

8051 Microcontroller

The document provides details about 10 experiments that can be performed using an 8051 microcontroller. Experiment 4 discusses interfacing an LCD module with the microcontroller. It includes the objective, required materials, theory, and code to send alphanumeric characters and numbers to the LCD one by one with a delay between each character. The code initializes the LCD, defines the data to send, and uses a loop to repeatedly send each character from memory and increment the pointer until reaching the end of data marker.

Uploaded by

Abhinav Baghel
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)
121 views26 pages

8051 Microcontroller

The document provides details about 10 experiments that can be performed using an 8051 microcontroller. Experiment 4 discusses interfacing an LCD module with the microcontroller. It includes the objective, required materials, theory, and code to send alphanumeric characters and numbers to the LCD one by one with a delay between each character. The code initializes the LCD, defines the data to send, and uses a loop to repeatedly send each character from memory and increment the pointer until reaching the end of data marker.

Uploaded by

Abhinav Baghel
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/ 26

S.no Program Page No.

1 Binary pattern on the port 1 LEDs 2


2 Echoing the switches to the LEDs 3
3 Multiplexing the seven-segment display 4-5
4 LCD module in assembly 6-9
5 Ramp signal on the DAC output 10-11
6 Taking samples from the ADC and displaying them 12-14
on the scope via the DAC
7 Scanning the keyboard 15-17
8 Transmitting data on the 8051 serial port 18-19
9 Receiving data on the 8051 serial port 20-21
10 The Motor 22-25

INDEX

1
EXPERIMENT:-1

 OBJECTIVE: Binary Pattern on the Port 1 LEDs


 Material required: microcontroller, crystal oscillator of desire
frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF, keil
compiler software version-(4 or 5), microcontroller burner & their drivers.
 Theory: This program displays the binary pattern from 0 to 255 (and back to 0) on the
LEDs interfaced with port 1.A (1) in the pattern is represented by the LED on,while a
0 in the pattern is represented by the LED off. However, logic 0 on a port 1 pin turns
on the LED, therefore it is necessary to write the inverse of the pattern to the LEDs.
The easiest way to do this is to send the data FFH to 0 (and back to FFH) to the
LEDs.Since port 1 is initially at FFH all we need to do is continuously decrement port
1.

 Code:
start:
DEC P1 ; decrement port 1
JMP start ; and repeat
Outputs:

1.1 1.2

Result: -

The given experiment is verified.

Precaution: -

1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

2
EXPERIMENT:-2

 OBJECTIVE: Echoing the Switches to the LEDs –


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.
 Theory: This program very simply echoes the switches on P2 to the LEDs on P1.
When a switch is closed a logic 0 appears on that P2 pin, which is then copied to that
P1 bit which turns on that LED.Therefore, a closed switch is seen as a lit LED and
vice versa.
 CODE:
start:
MOV P1, P2 ; move data on P2 pins to P1
JMP start ; and repeat

OUTPUT:

2.1

Result: -
The given experiment is verified.

Precaution: -

1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

3
EXPERIMENT:-3

 OBJECTIVE: Multiplexing the 7-segment Displays – 


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.
 Theory: This program multiplexes the number 1234,on the four 7-segment
displays.Note: a logic 0 lights a display segment.
 Code:
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, #20
DJNZ R0, $
RET

Output:

3.1

3.2

4
Result: -
The given experiment is verified.

Precaution: -
1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

5
EXPERIMENT:-4

 OBJECTIVE: LCD Module –


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.

 Theory: This program sends the alphabets or number on the LCD module one by
one with the delay that can be change by the user according to the need of the user.
This program can be used to display different on the public places like railway station,
bus stand, malls etc.
 Code:
Start:; put data in RAM
MOV 30H, #'A'
MOV 31H, #'B'
MOV 32H, #'C'
MOV 33H, #0 ; end of data marker
; initialise the display
; see instruction set for details
CLR P1.3 ; clear RS - indicates that instructions are being sent to the
module

; function set
CLR P1.7 ;|
CLR P1.6 ;|
SETB P1.5 ;|
CLR P1.4 ; | high nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear


; function set sent for first time - tells module to go into
4-bit mode
; Why is function set high nibble sent twice? See 4-bit operation on pages 39 and 42 of
HD44780.pdf.

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E
; same function set high nibble sent a second time

SETB P1.7 ; low nibble set (only P1.7 needed to be changed)


6
SETB P1.2 ;|
CLR P1.2 ; | negative edge on E
; function set low nibble sent
CALL delay ; wait for BF to clear
; entry mode set
; set to increment with no shift
CLR P1.7 ;|
CLR P1.6 ;|
CLR P1.5 ;|
CLR P1.4 ; | high nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

SETB P1.6 ;|
SETB P1.5 ; |low nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear


; display on/off control
; the display is turned on, the cursor is turned on and blinking is turned on
CLR P1.7 ;|
CLR P1.6 ;|
CLR P1.5 ;|
CLR P1.4 ; | high nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

SETB P1.7 ;|
SETB P1.6 ;|
SETB P1.5 ;|
SETB P1.4 ; | low nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear

; send data
SETB P1.3 ; clear RS - indicates that data is being sent to module
MOV R1, #30H ; data to be sent to LCD is stored in 8051 RAM, starting at
location 30H
loop:
MOV A, @R1 ; move data pointed to by R1 to A
JZ finish ; if A is 0, then end of data has been reached - jump out
of loop
CALL sendCharacter ; send data in A to LCD module
7
INC R1 ; point to next piece of data
JMP loop ; repeat

finish:
JMP $
sendCharacter:
MOV C, ACC.7 ;|
MOV P1.7, C ;|
MOV C, ACC.6 ;|
MOV P1.6, C ;|
MOV C, ACC.5 ;|
MOV P1.5, C ;|
MOV C, ACC.4 ;|
MOV P1.4, C ; | high nibble set
SETB P1.2 ;|
CLR P1.2 ; | negative edge on E
MOV C, ACC.3 ;|
MOV P1.7, C ;|
MOV C, ACC.2 ;|
MOV P1.6, C ;|
MOV C, ACC.1 ;|
MOV P1.5, C ;|
MOV C, ACC.0 ;|
MOV P1.4, C ; | low nibble set

SETB P1.2 ;|
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear

delay:
MOV R0, #50
DJNZ R0, $
RET

OUTPUT:

4.1.

8
4.2

4.3

Result: -
The given experiment is verified.

Precaution: -
1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

9
EXPERIMENT:-5

 OBJECTIVE: Ramp Signal on the DAC Output


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.

 Theory: This program generates a ramp on the DAC output. You can try adding
values other than 8 to the accumulator to see what this does to the ramp signal.
 Code:
CLR P0.7 ; enable the DAC WR line
loop:
MOV P1, A ; move data in the accumulator to the ADC inputs (on
P1)
ADD A, #4 ; increase accumulator by 4
JMP loop ; jump back to loop

OUTPUT:

5.1

10
5.2

5.3

Result: -
The given experiment is verified.

Precaution: -
1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

11
EXPERIMENT:-6

 OBJECTIVE: Taking Samples from the ADC and Displaying them on the Scope
via the DAC -
 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.

 Theory: This program reads the analogue input voltage on the ADC and displays it
on the scope via the DAC.A sample is taken from the ADC every 50 us This is
achieved by setting timer 0to interrupt the main program every 50 us.The timer 0 ISR
then initiates an ADC conversion.When the conversion is complete the ADC interrupt
line goes low. This line is interfaced with the 8051 external 0 interrupt line. The
external 0 ISR therefore takes the reading from the ADC on P2 and passes it to the
DAC on P1.Therefore, while the program is running,the scope voltage level should be
the same as the ADC input voltage. However, when a change is made to the ADC
input voltage it will take some time for the scope to update (ie; until the next timer 0
interrupt).Note: when running this program make sure the ADC is enabled (not the
comparator).

 Code:
ORG 0 ; reset vector
JMP main ; jump to the main program

ORG 3 ; external 0 interrupt vector


JMP ext0ISR ; jump to the external 0 ISR

ORG 0BH ; timer 0 interrupt vector


JMP timer0ISR ; jump to timer 0 ISR

ORG 30H ; main program starts here


main:
SETB IT0 ; set external 0 interrupt as edge-activated
SETB EX0 ; enable external 0 interrupt
CLR P0.7 ; enable DAC WR line
MOV TMOD, #2 ; set timer 0 as 8-bit auto-reload interval timer

MOV TH0, #-50 ; | put -50 into timer 0 high-byte - this reload value,

12
; | with system clock of 12 MHz, will result in a timer 0
overflow every 50 us

MOV TL0, #-50 ; | put the same value in the low byte to ensure the timer starts
counting from
; | 236 (256 - 50) rather than 0

SETB TR0 ; start timer 0


SETB ET0 ; enable timer 0 interrupt
SETB EA ; set the global interrupt enable bit
JMP $ ; jump back to the same line (ie; do nothing)

; end of main program

; timer 0 ISR - simply starts an ADC conversion


timer0ISR:
CLR P3.6 ; clear ADC WR line
SETB P3.6 ; then set it - this results in the required positive edge to
start a conversion
RETI ; return from interrupt

; external 0 ISR - responds to the ADC conversion complete interrupt


ext0ISR:
CLR P3.7 ; clear the ADC RD line - this enables the data lines
MOV P1, P2 ; take the data from the ADC on P2 and send it to the
DAC data lines on P1
SETB P3.7 ; disable the ADC data lines by setting RD
RETI ; return from interrupt

OUTPUT:

6.2

6.3

13
Result: -
The given experiment is verified.

Precaution: -
1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.
2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

14
EXPERIMENT:-7

 OBJECTIVE: Scanning the Keypad -


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.
 Theory: This program scans the keypad.While no key is pressed the program scans
row0, row1, row2, row3 and back to row0, continuously.When a key is pressed the
key number is placed in R0.For this program, the keys are numbered as:
+----+----+----+
| 11 | 10 | 9 | row3
+----+----+----+
| 8| 7| 6| row2
+----+----|----+
| 5| 4| 3| row1
+----+----+----+
| 2| 1| 0| row0
+----+----+----+
col2 col1 col0

The pressed key number will be stored in R0. Therefore, R0 is initially cleared.Each key is
scanned, and if it is not pressed R0 is incremented. In that way,when the pressed key is
found, R0 will contain the key's number.The general purpose flag, F0, is used by the column-
scan subroutine to indicate whether or not a pressed key was found in that column. If, after
returning from colScan, F0 is\ set, this means the key was found.
 Code:
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
15
; | (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

16
OUTPUT:

7.1

Result: -

The given experiment is verified.

Precaution: -

1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

17
EXPERIMENT:-8

 OBJECTIVE: Transmitting Data on the 8051 Serial Port - 


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.

 Theory: This program sends the text abc down the 8051 serial port to the external
UART at 4800 Baud.To generate this baud rate, timer 1 must overflow every 13 us
with SMOD equal to 1 (this is as close as we can get to 4800 baud at a system clock
frequency of 12 Mz).See the notes on the serial port for more information.The data is
sent with even parity,therefore for it to be received correctly the external UART must
be set to Even Parity
 Code:
CLR SM0 ;|
SETB SM1 ; | put serial port in 8-bit UART mode

MOV A, PCON ;|
SETB ACC.7 ;|
MOV PCON, A ; | set SMOD in PCON to double baud rate

MOV TMOD, #20H ; put timer 1 in 8-bit auto-reload interval


timing mode
MOV TH1, #243 ; put -13 in timer 1 high byte (timer will overflow
every 13 us)
MOV TL1, #243 ; put same value in low byte so when timer is first
started it will overflow after 13 us
SETB TR1 ; start timer 1

MOV 30H, #'a' ;|


MOV 31H, #'b' ;|
MOV 32H, #'c' ; | put data to be sent in RAM, start address 30H

MOV 33H, #0 ; null-terminate the data (when the accumulator


contains 0, no more data to be sent)
MOV R0, #30H ; put data start address in R0
again:
MOV A, @R0 ; move from location pointed to by R0 to the
accumulator
JZ finish ; if the accumulator contains 0, no more data to be sent,
jump to finish
MOV C, P ; otherwise, move parity bit to the carry
MOV ACC.7, C ; and move the carry to the accumulator MSB
MOV SBUF, A ; move data to be sent to the serial port
INC R0 ; increment R0 to point at next byte of data to be sent
18
JNB TI, $ ; wait for TI to be set, indicating serial port has finished
sending byte
CLR TI ; clear TI
JMP again ; send next byte
finish:
JMP $ ; do nothing

OUTPUT:

8.1

Result: -

The given experiment is verified.

Precaution: -

1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

19
EXPERIMENT:-9

 OBJECTIVE: Receiving Data on the Serial Port - 


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.

 Theory: This program receives data on the 8051 serial port. Once the
program'sinitialisation is complete, it waits for data arriving on the RXD line (data
that was transmitted by the external UART).Any text typed in the external UART is
sent once the Tx Send button is pressed. As each character is transmitted fully,it
disappears from the Tx window.The data is appended with the return character (0D
HEX).The default external UART baud rate is 19,200. To generate this baud rate,
TH1 must be set to -3. If the system clock is 12 MHz, the error when attempting to
generate such a high baud rate such that very often garbage is received. Therefore, for
19,200 Baud, the system clock should be set to 11.059 HMz.See the notes on the
serial port for more information.The program is written using busy-waiting.It
continuously tests the RI flag. Once this flag is set by the 8051 hardware (a byte has
been received) the program clears it and then moves the byte from SBUF to A.The
received byte's value is checked to see if it is the terminating character (0D HEX).If it
is the program jumps to the finish,otherwise it moves the byte to data memory and
returns to waiting for the next byte.
 Code:
CLR SM0 ;|
SETB SM1 ; | put serial port in 8-bit UART mode

SETB REN ; enable serial port receiver

MOV A, PCON ;|
SETB ACC.7 ;|
MOV PCON, A ; | set SMOD in PCON to double baud rate

MOV TMOD, #20H ; put timer 1 in 8-bit auto-reload interval timing mode
MOV TH1, #0FDH ; put -3 in timer 1 high byte (timer will overflow every
3 us)
MOV TL1, #0FDH ; put same value in low byte so when timer is first
started it will overflow after approx. 3 us
SETB TR1 ; start timer 1
20
MOV R1, #30H ; put data start address in R1
again:
JNB RI, $ ; wait for byte to be received
CLR RI ; clear the RI flag
MOV A, SBUF ; move received byte to A
CJNE A, #0DH, skip ; compare it with 0DH - it it's not, skip next instruction
JMP finish ; if it is the terminating character, jump to the end of
the program
skip:
MOV @R1, A ; move from A to location pointed to by R1
INC R1 ; increment R1 to point at next location where data will
be stored
JMP again ; jump back to waiting for next byte
finish:
JMP $ ; do nothing

Output:

9.1

Result: -

The given experiment is verified.

Precaution: -
1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

21
EXPERIMENT:-10

 OBJECTIVE: The Motor - 


 Material required: EdSim51 simulator, microcontroller, crystal oscillator of
desire frequency ,two(2)load capacitor, register 10kohm & 1 polar capacitor 10μF,
keil compiler software version-(4 or 5), microcontroller burner & their drivers.
 Theory: This program exercises the motor.The motor is rotated in a clockwise
direction and the number of revolutions is displayed on Display 0 (the 7-segment
display). The display only shows up to nine revolutions and then resets.

The motor sensor is connected to P3.5,which is the external clock source for timer 1.
Therefore, timer 1 is put into event counting mode. In this way, the timer increments once
every motor revolution.The value in timer 1 low byte is moved to A and this value together
with the data pointer (DPH and DPL) are used to get the 7-segment code from program

memory.The code is then sent to P1 to put the appropriate number on the Display 0.

The motor can be changed from clockwise to anti-clockwise by pressing SW0 (on P2.0).The
motor direction is stored in F0 (1 for clockwise, 0 for anti-clockwise). The value in F0 is sent
to Display 0's decimal point (P1.7).
This indicates the motor's direction - if the decimal point is lit, the motor is rotating anti-
clockwise, while if it is not lit the motor is rotating clockwise.

The value in F0 is compared with the value of SW0. If they are the same the motor direction
does not need to be changed. If they are not the same it means the user has pressed SW0 and
the motor direction must be reversed. When this happens the new motor direction is then
stored in F0.

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

22
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


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

10.1

24
10.2

Result: -

The given experiment is verified.

Precaution: -

1.Back up your files: Always make sure to back up your project files, source code, and other
important data before making any changes to your project or using the simulator.

2.Use the latest version: Use the latest version of the software to ensure that you have access
to the latest bug fixes and security updates.

25
26

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy