0% found this document useful (0 votes)
50 views

Microcontroller

The document contains 4 programs written by ashish KUMAR to generate different square waveforms using timers 0, 1 and counters of the 8051 microcontroller. Each program includes the calculations, code, and simulation output to generate a 500Hz signal using timer 0, a 2KHz signal using timer 1, combined signals using timer 0, and a program using counter 1 and timer 0 to generate a delay after 10 counts.

Uploaded by

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

Microcontroller

The document contains 4 programs written by ashish KUMAR to generate different square waveforms using timers 0, 1 and counters of the 8051 microcontroller. Each program includes the calculations, code, and simulation output to generate a 500Hz signal using timer 0, a 2KHz signal using timer 1, combined signals using timer 0, and a program using counter 1 and timer 0 to generate a delay after 10 counts.

Uploaded by

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

NAME : ashish KUMAR

REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

DIGITAL ASSIGNMENT 03

TITLE : BASIC 8051 PROGRAMS

NAME : ashish KUMAR


REGISTRATION NO. : 21BEC2017
SLOT : L33+L34
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

QUESTION_01: Write a program using timer 0 to generate a 500 Hz square wave


frequency on one of the pins of P1.0 . Then examine the frequency using the KEIL IDE
inbuilt Logic Analyzer, using mode 1.

CALCULATION:
Given,

Time period,

Therefore,

Delay =

( ) ( )

PROGRAM: ORG 0000H


MOV TMOD, #01H ; TIMER 0 MODE 1
HERE:MOV TL0, #65H
MOV TH0, #0FCH
CPL P1.0
ACALL DELAY
SJMP HERE
DELAY: SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TR0
CLR TF0
RET
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

SIMULATION:

OBSERVATION:
The following program generated a square waveform nearing to 500Hz on pin P1.0
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

QUESTION_02: Use timer 1 in mode 2 and generate a square waveform of 2 KHz at


P2.0.

CALCULATION:
Given,

Time period,

Therefore,

Delay =

( ) ( )

PROGRAM: ORG 0000H


MOV TMOD, #20H ; TIMER 1 MODE 2
MOV TH1, #19H
HERE: CPL P2.0
ACALL DELAY
SJMP HERE
DELAY: SETB TR1
AGAIN: JNB TF1, AGAIN
CLR TR1
CLR TF1
RET
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

SIMULATION:

OBSERVATION:
The following program generated a square waveform of 2KHz on pin P2.0.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

QUESTION_03: Develop an 8051 ALP program to generate square waves as shown


below. Examine the same using the KEIL IDE inbuilt Logic Analyzer.

CALCULATION:
Given, Delay

( ) ( )

PROGRAM: ORG 0000H


MOV TMOD, #01H ;Timer 0, Mode 1
YY: CPL P2.0
ACALL DELAY
CPL P1.0
ACALL DELAY
SJMP yy
DELAY: MOV TH0, #0DCH
MOV TL0, #00H
SETB TR0
XX: JNB TF0, XX
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS


CLR TR0
CLR TF0
RET
END

SIMULATION:

OBSERVATION:
Required Square wave was generated.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

QUESTION_04: Use Counter 1 in mode 2 and after 10 number of counts on TL1,


generate a delay of period of 10 msec on P1.2 by using Timer 0 in mode 1, show the counts
in TL1 on port 2.

CALCULATION:
Given, Delay

( ) ( )

PROGRAM: ORG 0000H


SETB P3.5 ; declaring timer 1 pin as i/p pin
MOV TMOD, #01100001B ;Counter 1, Mode 2 & Timer 0, Mode 1
ZZ: MOV TH1, #00H
MOV TH0, #0EEH
MOV TL0, #00H
SETB TR1
MOV A, TL1
MOV P2, A
XX: CJNE A, #0AH, XX
CLR TR1
SETB P1.2
SETB TR0
YY: JNB TF0, YY
CLR TR0
CLR TF0
CLR P1.2
SJMP ZZ
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

SIMULATION:
 Before Reaching 10 :-

 After Reaching 10 :-
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

OBSERVATIONS:
This code initializes Timer 1 in mode 2 and Timer 0 in mode 1, and sets up Port 1.2 as the
output for the delay. The program enters a loop that increments a counter and displays its
value on Port 2. Once the counter reaches 10, the program sets up Timer 0 to generate a 10ms
delay, clears Port 1.2 to begin the delay, and waits for the delay to complete before looping
back to the start of the counting loop.

You might also like