0% found this document useful (0 votes)
17 views24 pages

Eet 303 M5

Uploaded by

adhiladhu004
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)
17 views24 pages

Eet 303 M5

Uploaded by

adhiladhu004
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/ 24

EET 303 MODULE-5

SYLLABUS
8051 Timer/counter programming - Serial port programming - Interrupt programming in assembly
language and embedded C.
Interfacing –ADC - DAC and temperature sensor
5.18051 Timer/Counter

➢ 8051 has two 16-bit programmable UP timers/counters.


➢ They can be configured to operate either as timers or as event
counters. The names of the two counters are T0 and T1 respectively.
➢ TH0/TL0 is the 16-bit register of Timer 0 and TH1/TL1 is the 16-bit register of Timer 1.
➢ Timer S p e c i a l F u n c t i o n Registers are
o TCON TimerControl
o TMOD TimerMode

5.1.1Timer SFRs:

TCON

TCONSFRandits individualbits

- IT0/IT1:UsedfortimerInterrupts
- IE0/IE1:UsedforexternalInterrupts
- TR0/TR1:Timer 0/1 run control bit. Set to 1 to start the timer / counter.
- TF0/TF1:Timer0/1 overflow flag. It is set when timer rolls from all 1s to 0s

TMOD

TMODSFRanditsindividualbits

- M0/M1:setstheModeoftherespectivetimer

- C/T:ExternalCounter/InternalTimerselect
1=Counter,0= Timer
- Gate:Whenset(1),timerrunsonly whenrespectiveINTinputis high.
5.1.2 Timer O p e r a t i n g Modes:
Four operating modes are there:
- Mode 0:13 bittimer
- Mode 1:16-bittimer
- Mode 2:8-Bitautoreload
- Mode 3:Splittimermode
Timer Mode 0: (13 bit Mode)

➢ In this mode, the timer is used as a 13-bit UP counter as follows.

Fig. 4.6 Operation of Timer on Mode-0


➢ The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count. Upper 3 bits of TLX are
ignored.
➢ When the counter rolls over from all 0's to all 1's, TFX flag is set and an interrupt is generated.

Timer Mode1:(16-bit mode)


- All16 bitsof thetimer(TH0/TL0,TH1,TL1)areused.
- Maximumcountis65,536
- This mode is similar to mode-0 except for the fact that the Timer operates in 16-bit mode.

Fig Operation of Timer in Mode 1

Timer Mode-2: (Auto-Reload Mode)

➢ This is a 8 bit counter/timer operation.


➢ Counting is performed in TLX while THX stores a constant value.
➢ In this mode when the timer overflows i.e. TLX becomes FFH, it is fed with the value stored in
THX.
➢ For example if we load THX with 50H then the timer in mode 2 will count from 50H to FFH.
After that 50H is again reloaded.
Fig Operation of Timer in Mode 2

Timer Mode-3 (Split mode)

➢ Timer0 in mode-3 establishes TL0 and TH0 as two separate counters.


➢ Timer 1 in mode-3 simply holds its count.
➢ Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0).
➢ TR0 and TF0 are available to Timer-0 lower 8 bits(TL0).

Fig Operation of Timer in Mode 3

5.3 Timer / Counter Programming :

In order to program 8051 timers, it is important to know the calculation of initial count value
to be stored in the timer register. The calculations are as follows.

In any mode, Timer Clock Frequency. = Master Clock Frequency/12


Timer Clock period = 1/Timer Clock Frequency.

a) Mode 1 (16 bit timer/counter)

Value to be loaded in decimal, n = 65536 – (Delay Required/Timer clock period)


Convert the answer into hexadecimal and load onto THx and TLx register.
(65536D = FFFFH+1)

b) Mode 0 (13 bit timer/counter)

Value to be loaded in decimal = 8192 – (Delay Required/Timer clock period)


Convert the answer into hexadecimal and load onto THx and TLx register.
(8192D = 1FFFH+1)
c) Mode 2 (8 bit auto reload)

Value to be loaded in decimal = 256 – (Delay Required/Timer clock period)


Convert the answer into hexadecimal and load onto THx register. Upon starting the timer this
value from THx will be reloaded to TLx register.
(256D = FFH+1)
Steps for programming timers in 8051

Mode 1:
➢ Load the TMOD value register indicating which timer (0 or 1) is to be used and which timer
mode is selected.
➢ Load registers TL and TH with initial count values.
➢ Start the timer by the instruction “SETB TR0” for timer 0 and “SETB TR1” for timer 1.
➢ Keep monitoring the timer flag (TF) with the “JNB TFx,target” instruction to see if it is
raised. Get out of the loop when TF becomes high.
➢ Stop the timer with the instructions “CLR TR0” or “CLR TR1”, for timer 0 and timer 1,
respectively.
➢ Clear the TF flag for the next round with the instruction “CLR TF0” or “CLR TF1”, for timer
0 and timer 1, respectively.
➢ Go back to step 2 to load TH and TL again.

Mode 0:
The programming techniques mentioned here are also applicable to counter/timer mode 0.
The only difference is in the number of bits of the initialization value. (13 bits)

Mode 2:
➢ Load the TMOD value register indicating which timer (0 or 1) is to be used; select timer
mode 2.
➢ Load TH register with the initial count value. As it is an 8-bit timer, the valid range is from
00 to FFH.
➢ Start the timer.
➢ Keep monitoring the timer flag (TFx) with the “JNB TFx,target” instruction to see if it is
raised. Get out of the loop when TFx goes high.
➢ Clear the TFx flag.
➢ Go back to step 4, since mode 2 is auto-reload.

Example#1: Write a program to continuously generate a square wave of 2 kHz


frequency on pin P1.5 using timer 1. Assume the crystal oscillator frequency to be 12
MHz.

The period of the required square wave is T = 1/(2 kHz) = 500 µs.
Delay required for each half cycle = 250 µs.
Timer Clock frequency = Master Frequency/12
= 12MHz/12 =1 MHz
Timer Clock period = 1/ Timer Clock frequency = 1/1MHz = 1 µs.
Value to be loaded in decimal, n = 65536 – (Delay Required/Timer clock period)
Value to be loaded in decimal, n = 65536 – (250 µs /1 µs)
=65536 – (250) = 65286 = FF06h

TL = 06h and TH = 0FFh.

MOV TMOD,#10 ;Timer 1, mode 1


AGAIN: MOV TL1,#06h ;TL0 = 06h
MOV TH1,#FFh ;TH0 = FFh
SETB TR1 ;Start timer 1
BACK: JNB TF1,BACK ;Stay until timer rolls over
CLR TR1 ;Stop timer 1
CPL P1.5 ;Complement P1.5 to get High, Low
CLR TF1 ;Clear timer flag 1
SJMP AGAIN ;Reload timer

Example#2. Write a 8051 C program to toggle all the bits of port P1 continuously with 1mS
delay in between. Use Timer 0, 16-bit mode to generate the delay.
Solution:

Required delay = 1mS = 1000µS.

Let crystal frequency be 12MHz.


Then,
Timer Clock Frequency. = Master Clock Frequency/12
= 12MHz/12 = 1MHz

Therefore, Timer Clock period = 1/Timer Clock Frequency.


= 1/1MHz = 1µS.

Value to be loaded in decimal, n = 65536 – (Delay Required/Timer clock period)


= 65536- (1000µS/1µS)
=65536 -1000 = 64536 = FC18h
Therefore load 18 to register TL0 and load FC to register TH0 to get the required delay.

TMOD register initialization:


The value to be loaded in TMOD register to selecttimer 0 in mode0 = 0000 0001 =01h
Program:

Example#3. Write an 8051 C program to toggle only bit P1.5 continuously every 50 mS. Use Timer 1,
mode 1 (16-bit) to create the delay.

Required delay = 50mS = 50000µS.

Let crystal frequency be 12MHz.


Then,
Timer Clock Frequency. = Master Clock Frequency/12
= 12MHz/12 = 1MHz

Therefore, Timer Clock period = 1/Timer Clock Frequency.


= 1/1MHz = 1µS.

Value to be loaded in decimal, n = 65536 – (Delay Required/Timer clock period)


= 65536- (50000µS/1µS)
=65536-50000 = 15536 = 3CB0h
Therefore load B0 to register TL1 and load 3C to register TH1 to get the required delay.

TMOD register initialization:


The value to be loaded in TMOD register to selecttimer 0 in mode0 = 0001 0000 =10h
Program:

5.2 SERIAL PORT PROGRAMMING


➢ The 8051 supports a full duplex serial port.
➢ Three special function registers support serial communication.

1. SBUF Register: Serial Buffer (SBUF) register is an 8-bit register. It has separate
SBUF registers for data transmission and for data reception. For a byte of data to be
transferred via the TXD line, it must be placed in SBUF register. Similarly, SBUF holds
the 8-bit data received by the RXD pin and read to accept the received data.

2. SCON register: The contents of the Serial Control (SCON) register are shown below.
This register contains mode selection bits, serial port interrupt bit (TI and RI) and also
the ninth data bit for transmission and reception (TB8 and RB8).
3. PCON register:The SMOD bit (bit 7) of PCON register controls the baud rate in
asynchronousmode transmission.

5.2.1 SERIAL COMMUNICATION MODES

1. Mode 0

In this mode serial port runs in synchronous mode. The data is transmitted and received
through RXD pin and TXD is used for clock output. In this mode the baud rate is 1/12 of clock
frequency.

2. Mode 1

In this mode SBUF becomes a 10 bit full duplex transceiver. The ten bits are 1 start bit, 8 data
bit and 1 stop bit. The interrupt flag TI/RI will be set once transmission or reception is over.
In this mode the baud rate is variable and is determined by the timer 1 overflow rate.
Baud rate = [2smod/32] x Timer 1 overflow Rate
= [2smod /32] x [Oscillator Clock Frequency] / [12 x [256 – [TH1]]]
3. Mode 2

This is similar to mode 1 except 11 bits are transmitted or received. The 11 bits are, 1 start
bit, 8 data bit, a programmable 9th data bit, 1 stop bit.
Baud rate = [2smod /64] x Oscillator Clock Frequency

4. Mode 3
This is similar to mode 2 except baud rate is calculated as in mode 1
5.3 INTERRUPTS IN 8051

5.3.1 Types of Interrupts in 8051

➢ When an interrupt event occurs, the microcontroller pause its current program and
attend to the interrupt by executing an Interrupt Service Routine (ISR).
➢ At the end of the ISR, the microcontroller returns to the program it had pause and
continue its normal operations.

The 8051 microcontroller has five sources of interrupts:

1. Timer 0 overflow interrupt- TF0


2. Timer 1 overflow interrupt- TF1
3. External hardware interrupt- INT0
4. External hardware interrupt- INT1
5. Serial communication interrupt- RI/TI

External Hardware Interrupts :( INT0 and INT1)

➢ 8051 microcontrollers consists of two external hardware interrupts: INT0 and INT1.
➢ These can be edge triggered or level triggered.
➢ In level triggering, the low at the interrupt pin enables the interrupt.
➢ In edge triggering, the high to low transition enables the edge triggered interrupt.
➢ This edge triggering or level triggering is decided by the TCON register.

Internal Interrupts:( RI/TI , TF0 and TF1)


➢ Internallygeneratedinterruptscanbefromeithertimer,orfromtheserialinterface.
➢ Theserialinterfacecausesinterruptsduetoareceiveevent(RI)ordue
toatransmitevent(TI).
➢ Thereceiveeventoccurswhentheinputbufferofthe
serialline(sbufin)isfullandabyteneedstobereadfromit.
➢ Thetransmitevent
indicatesthatabytehasbeensentanewbytecanbewrittentooutputbufferof
theserialline(sbufout).

➢ 8051timersalwayscountup.Whentheircountrollsoverfromthemaximum
countto0000,theysetthecorrespondingtimerflagTF1orTF0inTCON and
aninterruptoccurs.

5.3.2 Interrupt Vectors

➢ Vector Address is the starting address of Interrupt service routine of a particular


interrupt.
➢ Vector address means the address by which the interrupt service routine is

stored.

➢ Thefollowingtablegives thevectoraddresses of various interrupts.


InterruptSource Vectoraddress
ExternalInterrupt0 0003H
Timer0Overflow 000BH
ExternalInterrupt1 0013H
Timer1Overflow 001BH
SerialInterface 0023H

5.3.3 SequenceofEventsafteraninterrupt

Whenanenabledinterruptoccurs,

1.ThePCissavedonthestack.

2.Otherinterruptsoflowerpriorityandsamepriorityaredisabled.
3.Exceptfortheserialinterrupt,thecorrespondinginterruptflagiscleared.

4.PCisloadedwiththevectoraddresscorrespondingtotheinterrupt.

5. Then interrupt service routine will be executed

When processorexecutes instruction‘RETI”

1.PCisrestoredbypoppingthestack.

2.Interruptstatusisrestoredtoitsoriginalvalue.(Sameandlowerpriority
interruptsrestoredtooriginalstatus).

5.3.4 Special Function Registers related to interrupt:


1. Interrupt Enable (IE) Register:
➢ This register is responsible for enabling and disabling the interrupt.
➢ It is a bit addressable register in which EA must be set to one for enabling interrupts.
➢ The corresponding bit in this register enables particular interrupt like timer, external and
serial inputs.
➢ In the below IE register, bit corresponding to 1 activates the interrupt and 0 disables the
interrupt.
2. Interrupt Priority Register:
➢ Each and every interrupt has a priority level by which the microcontroller serves
the interrupt in a predefined manner and its order is INT0, TF0, INT1, TF1, and SI.
➢ Each interrupt source can be programmed to have one of the two priority levels by
setting (high priority) or clearing (low priority) a bit in the IP (Interrupt Priority)
Register.
➢ This allows the low priority interrupt to interrupt the high-priority interrupt, but
prohibits the interruption by another low-priority interrupt.
➢ Similarly, the high-priority interrupt cannot be interrupted.

3. TCON Register:

➢ In addition to the above two registers, the TCON register specifies the type of
external interrupt to the 8051 microcontroller, as shown in the figure.
➢ The two external interrupts, whether edge or level triggered, specify by this
register by a set, or cleared by appropriate bits in it.
5.3.5 Interrupt Programming in 8051

While programming interrupts, first thing to do is to specify the microcontroller which interrupts
must be served. This is done by configuring the Interrupt Enable (IE) register which enables or
disables the various available interrupts.

To enable any of the interrupts, first the EA bit must be set to 1. After that the bits corresponding
to the desired interrupts are enabled. ET0 and ET1 bits are used to enable the Timer Interrupts 0
and 1 respectively. EX0 and EX1 are used to enable the external interrupts 0 and 1. ES is used
for serial interrupt.

EA bit acts as a lock bit. If any of the interrupt bits are enabled but EA bit is not set, the interrupt
will not function. By default all the interrupts are in disabled mode.

Note that the IE register is bit addressable and individual interrupt bits can also be accessed.

For example –

IE = 0x81; enables External Interrupt0 (EX0)

IE = 0x88; enables Serial Interrupt

Setting the bits of IE register is necessary and sufficient to enable the interrupts. Next step is to
specify the controller what to do when an interrupt occurs. This is done by writing a subroutine or
function for the interrupt. This is the ISR and gets automatically called when an interrupt occurs. It
is not required to call the Interrupt Subroutine explicitly in the code.

An important thing is that the definition of a subroutine must have the keyword interrupt followed
by the interrupt number. A subroutine for a particular interrupt is identified by this number. These
subroutine numbers corresponding to different interrupts are tabulated below.

Number Interrupt Symbol

0 External0 EX0

1 Timer0 IT0

2 External1 EX1

3 Timer1 IT1

4 Serial ES

5 Timer2 ET2
For example : Interrupt routine for Timer1

void ISR_timer1(void) interrupt 3


{
<Body of ISR>
}
For example : Interrupt routine for External Interrupt0 (EX0)

void ISR_ex0(void) interrupt 0


{
<Body of ISR>
}
Note that the interrupt subroutines always have void return type. They never return a value.

Programming Timer Interrupts

The timer interrupts IT0 and IT1 are related to Timers 0 and 1, respectively. (Please refer 8051

Timers for details on Timer registers and modes.) The interrupt programming for timers involves

following steps .

1. Configure TMOD register to select timer(s) and its/their mode.

2. Load initial values in THx and TLx for mode 0 and 1; or in THx only for mode 2.

3. Enable Timer Interrupt by configuring bits of IE register.

4. Start timer by setting timer run bit TRx.

5. Write subroutine for Timer Interrupt. The interrupt number is 1 for Timer0 and 3 for Timer1.

Note that it is not required to clear timer flag TFx.

6. To stop the timer, clear TRx in the end of subroutine. Otherwise it will restart from 0000H in case
of modes 0 or 1 and from initial values in case of mode 2.

7. If the Timer has to run again and again, it is required to reload initial values within the routine itself
(in case of mode 0 and 1). Otherwise after one cycle timer will start counting from 0000H.
Example code in Assembly Language:

Write a program that continuously get 8-bit data from P0 and sends it
to P1 while simultaneously creating a square wave of 200 μs period
on pin P2.1. Use timer 0 to create the square wave. Assume that
XTAL=11.0592MHz.

Solution:
We will use timer 0 in mode 2 (auto reload). TH0 = 100 μs /1.085 μs = 92
ORG 0000H
LJMP MAIN

// ISR for timer0 to generate square wave.


ORG 000BH
CPL P2.1
CLR TR0
RETI

// Main Program

ORG 0030H
MAIN: MOV TMOD, #02H ; Timer0 in auto reload mode
MOV P0, FFH ; P0 as input port
MOV TH0, #92d ; initial value for timer
MOV IE, #82H ; enable interrupt
SETB TR0
BACK: MOV A, P0
MOV P1,A
SJMP BACK

END

Timer interrupt to blink an LED; Time delay in mode1 using interrupt method

// Use of Timer mode0 for blinking LED using interrupt method


// XTAL frequency 11.0592MHz
#include<reg51.h>
sbit led = P1^0; //LED connected to D0 of port 1

void timer(void) interrupt 1 //interrupt no. 1 for Timer


0
{
led=~led; //toggle LED on interrupt
TH0=0xFC; // initial values loaded to timer
TL0=0x66;
}
main()
{
TMOD = 0x01; // mode1 of Timer0
TH0 = 0xFC; // initial values loaded to timer
TL0 = 0x66;
IE = 0x82; // enable interrupt
TR0 = 1; //start timer
while(1); // do nothing
}

2. Programming External Interrupts

The external interrupts are the interrupts received from the (external) devices interfaced with the
microcontroller. They are received at INTx pins of the controller. These can be level triggered or
edge triggered. In level triggered, interrupt is enabled for a low at INTx pin; while in case of edge
triggering, interrupt is enabled for a high to low transition at INTx pin. The edge or level trigger is
decided by the TCON register.

Setting the IT0 and IT1 bits make the external interrupt 0 and 1 edge triggered respectively. By
default these bits are cleared and so external interrupt is level triggered.

Note : For a level trigger interrupt, the INTx pin must remain low until the start of the ISR and
should return to high before the end of ISR. If the low at INTx pin goes high before the start of
ISR, interrupt will not be generated. Also if the INTx pin remains low even after the end of ISR, the
interrupt will be generated once again. This is the reason why level trigger interrupt (low) at INTx
pin must be four machine cycles long and not greater than or smaller than this.

Following are the steps for using external interrupt :

1. Enable external interrupt by configuring IE register.

2. Write routine for external interrupt. The interrupt number is 0 for EX0 and 2 for EX1
respectively.
Example code#1

Example code#2

//Level trigger external interrupt


void main()
{
IE = 0x81;
while(1);
}
void ISR_ex0(void) interrupt 0
{
<body of interrupt>
}

Example code#3

//Edge trigger external interrupt


void main()
{
IE = 0x84;
IT1 = 1;
while(1);
}
void ISR_ex1(void) interrupt 2
{
<body of interrupt>
}

3. Programming Serial Interrupt


To use the serial interrupt the ES bit along with the EA bit is set. Whenever one byte of data is

sent or received, the serial interrupt is generated and the TI or RI flag goes high. Here, the TI or

RI flag needs to be cleared explicitly in the interrupt routine (written for the Serial Interrupt).

The programming of the Serial Interrupt involves the following steps:

1. Enable the Serial Interrupt (configure the IE register).

2. Configure SCON register.

3. Write routine or function for the Serial Interrupt. The interrupt number is 4.

4. Clear the RI or TI flag within the routine.

Example code#1

Example code#2

Send ‘A’ from serial port with the use of interrupt

// Sending ‘A’ through serial port with interrupt


// XTAL frequency 11.0592MHz
void main()
{
TMOD = 0x20;
TH1 = -1;
SCON = 0x50;
TR1 = 1;
IE = 0x90;
while(1);
}
void ISR_sc(void) interrupt 4
{
if(TI==1)
{
SBUF = ‘A’;
TI = 0;
}
else
RI = 0;
}

Example code#3

// Receive data from serial port through interrupt


// XTAL frequency 11.0592MHz
void main()
{
TMOD = 0x20;
TH1 = -1;
SCON = 0x50;
TR1 = 1;
IE = 0x90;
while(1);
}
void ISR_sc(void) interrupt 4
{
unsigned char val;
if(TI==1)
{
TI = 0;
}
else
{
val = SBUF;
RI = 0;
}
}
5.4 INTERFACING

5.4.1. INTERFACING ANLOG TO DIGITAL CONVERTER (ADC) WITH 8051

➢ The analog to digital converter is treated as an input device by the microcontroller.


➢ ADC 0808 is an ADC chip with 8 input channels which is the commonly used one.

During the analog to digital conversion process,


➢ Initially, microcontroller sends an initializing signal (start of conversion-SOC) to the ADC to
start the analog to digital data conversion process. The start of conversion signal is a pulse
of a specific duration.
➢ The microcontroller has to wait for the digital data till the conversion is over. After the
conversion is over, the ADC sends end of conversion EOC signal to inform the
microcontroller that the conversion is over and the result is ready at the output buffer of
the ADC.

Example: ADC interfacing program to read the digital value output of ADC from Port 2 and send it
to Port3.
Solution:

➢ The analog input I/P2 is used and therefore address pins A,B,C should be 0,1,0 respectively
to select I/P2.
➢ Analog channel select lines are connected at P1.2,P1.3 and P1.4
➢ Start of conversion signal is connected at P1.0.
➢ End of conversion signal is connected at P1.1. Hence P1.1 pin is an input pin.
➢ ADC digital output is connected at Port2. Hence Port 2 is input port.
Program:
ORG 0000H
MOV A,#FFH
MOV P2,A ;Initialize P2 as input port
SETB P1.1 ;Initialize P1.1 as input port

CLR P1.2 ;Makeselect line a 0


SETB P1.3 ; Make select line b 1
CLR P1.4 :Make select line c 0 (abc=010 to select channel)
CLR P1.0 ; Make SOC low
SETB P1.0 ; Make SOC high
CLR P1.0 ; Make SOC low
HERE: JNB P1.1, HERE
MOV A,P2 ;Read the digital out from ADC
MOV P3, A ; Store at memory.
END
-----------------------------------------------------Program in C-----------------------------------------------------
#include<REGX51.H>
#define soc P1.0 //soc P1.0
#defineeoc P1.1//eoc P1.1
#define a P1.2//select line a P1.2
#defineb P1.3 //select line b P1.3
#definec P1.4 //select line c P1.4

unsignedcharadc_val;

voidmain()
{
P2 = 0xFF; //Initialize Port2 as input port
eoc = 1; //Initialize Port1.1 as input pin

while(1) //Forever loop


{
a =0;//Make a low
b =1;//Make b high
c =0;//Make c low (abc=010 to select channel)
soc =0;//Make soc low
soc =1;//Make soc high
soc =0;//Make soc low
while(eoc==1);//Wait for eoc to go high
adc_val = P2; //Read digital value from P2
P3 =adc_val;//Send the digital value to P3
}
}
----------------------------------------------------------------------------------------------------------------------------
5.4.2. INTERFACING DIGITAL TO ANALOG CONVERTER (DAC) WITH 8051
➢ In the DAC0808, the digital inputs are converted to current (Iout), and by connecting
a resistor to the Iout pin, we convert the result to voltage.
➢ The total current provided by the Iout pin is a function of the binary numbers at the
DO – D7 inputs of the DAC0808 and the reference current (Iref), and is as follows:

where DO is the LSB, D7 is the MSB for the inputs, and I ref is the input current that must
be applied to pin 14

Figure: Interfacing DAC with 8051

Programming Example:

Write an ALP to generate Triangular wave form on port P1 of 8051 microcontroller using DAC.

ORG 0000h
MOV P1, #00H
REPEAT: ACALL TRIWAVE
SJMP REPEAT

TRIWAVE: MOV A.#00


INCR: MOV P1,A
INC A
CJNE A,#0FFH,INCR
DECR: MOV P1,A
DEC A
CJNE A,#00H,DECR
RET
END

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