Microcontrollers Applications Note 4
Microcontrollers Applications Note 4
Module IV
Interfacing of DIP switch’- LED -7 segment displays –alphanumeric LCD – relay interface –Stepper
motor –ADC-DAC-interfacing programs using assembly language.
LED Interfacing
6. Go To 2.
Program
ORG 0000h
loop:
CLR P2.0
ACALL DELAY
SETB P2.0
ACALL DELAY
SJMP loop
Generating delay
Loop technique
1. Start.
2. Load a number in a RAM location. e.g. R0.
3. Decrement RAM Location.
4. Is RAM = 00? If NO, GO TO 3.
5. STOP.
As you can see in the algorithm a number is loaded in a RAM location. It is then decremented & then if
the content of the RAM location is not equal to zero a jump is made to the decrementing instruction.
In 8051 a single instruction "DJNZ" is specifically designed for this kind of programs. It stands
for Decrement & Jump if Not Zero. This instruction takes care or STEP 3 & STEP 4 of the above
algorithm.
Delay Program
Delay:
MOV R7,#100
AGAIN:DJNZ R7,AGAIN
RET
A DIP switch is connected to Port 1 and two LEDs are connected to P2.0 and P2.2 respectively.
Write a program to blink the LED 1 if SW5 is ON and blink the LED2 if SW6 is ON. Note that
at a time only one LED should be ON.
Program
ORG 00H
MOV P1,#0FFH
AGAIN 1: JB P1.4,LED1
AGAIN2:JB P1.5,LED2
LED1: CLR P2.0
ACALL DELAY
SETB P2.0
ACALL DELAY
SJMP AGAIN1
LED2: CLR P2.2
ACALL DELAY
SETB P2.2
ACALL DELAY
SJMP AGAIN2
7 Segment Displays
1. Check if the seven segment is common anode or common cathode. If it is common anode then
connect a VCC to the common anode pin. To switch on any of the respective segment/LED pass 0 to
that pin through our 8051 microcontroller.
2. If the Seven Segment is common cathode connect Gnd to the common cathode pin. To switch on
any of the respective segments/LED give 1 to that pin through our 8051 microcontroller.
Program
Program Description.
Instruction MOVC A,@A+DPTR is the instruction that produces the required digit drive
pattern for the display. Execution of this instruction will add the value in the accumulator A with the
content of the data pointer (starting address of the ARRAY) and will move the data present in the
resultant address to A. In the program, initial value in A is 00H. Execution of MOVC A,@A+DPTR
will add 00H to the content in DPTR . The result will be the address of label DB 3FH and the data
present in this address ie 3FH (digit drive pattern for 0) gets moved into the accumulator. Moving
this pattern in the accumulator to Port 1 will display 0 which is the first count.
At the next count, value in A will advance to 01H and after the execution of MOVC A,@+DPTR
,the value in A will be 06H which is the digit drive pattern for 1 and this will display 1 which is the
next count and this cycle gets repeated for subsequent counts.
Label DB is known as Define Byte – which defines a byte. This table defines the digit drive patterns
for 7 segment display as bytes (in hex format). MOVC operator fetches the byte from this table based
on the result of adding DPTR and contents in the accumulator.
Register R0 is used as a temporary storage of the initial value of the accumulator and the subsequent
increments made to accumulator to fetch each digit drive pattern one by one from the ARRAY.
Alphanumeric LCD
3 VEE Used for adjusting the contrast commonly attached to the potentiometer.
4 RS RS is the register select pin used to write display data to the LCD (characters),
this pin has to be high when writing the data to the LCD. During the initializing
sequence and other commands this pin should low.
5 R/W Reading and writing data to the LCD for reading the data R/W pin should be high
(R/W=1) to write the data to LCD R/W pin should be low (R/W=0)
6 E Enable pin is for starting or enabling the module. A high to low pulse of about
450ns pulse is given to this pin.
7 DB0
8 DB1
9 DB2
10 DB3
11 DB4 DB0-DB7 Data pins for giving data(normal data like numbers characters or
command data) which is meant to be displayed
12 DB5
13 DB6
14 DB7
VEE pin is meant for adjusting the contrast of the LCD display and the contrast can be
adjusted by varying the voltage at this pin. This is done by connecting one end of a POT to the Vcc
(5V), other end to the Ground and connecting the center terminal (wiper) of the POT to the VEE pin.
The JHD162A has two built in registers namely data register and command register. Data register is
for placing the data to be displayed , and the command register is to place the commands. The 16×2
LCD module has a set of commands each meant for doing a particular job with the display. High
logic at the RS pin will select the data register and Low logic at the RS pin will select the command
register. If we make the RS pin high and the put a data in the 8 bit data line (DB0 to DB7), the LCD
module will recognize it as a data to be displayed . If we make RS pin low and put a data on the data
R/W pin is meant for selecting between read and write modes. High level at this pin enables read
E pin is for enabling the module. A high to low transition at this pin will enable the module.
DB0 to DB7 are the data pins. The data to be displayed and the command instructions are placed on
these pins.
LED+ is the anode of the back light LED and this pin must be connected to Vcc through a suitable
series current limiting resistor. LED- is the cathode of the back light LED and this pin must be
connected to ground.
The steps involved in interfacing an LCD with 8051
Scrolling Display
i. For left scroll pass a command of 0x18 and then give a delay.
ii. For right scroll pass a command of 0x1C and then give a delay.
to do a particular task. The commonly used commands and their function are given in the table
below.
Command Function
2 Return home.
4 Decrement cursor
6 Increment cursor
LCD initialization.
The steps that has to be done for initializing the LCD display is given below and these steps are
common for almost all applications.
The steps for sending data to the LCD module is given below. As explained, the LCD module has
pins namely RS, R/W and E. It is the logic state of these pins that make the module to determine
whether a given data input is a command or data to be displayed.
Make R/W low.
Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to be
displayed.
Place data byte on the data register.
Pulse E from high to low.
Repeat above steps for sending another data.
Circuit diagram
The circuit diagram given above shows how to interface a 16×2 LCD module with 8051
microcontroller. P1.0 to P1.7 pins of the microcontroller is connected to the D0 to D7 pins of the
module respectively and through this route the data goes to the LCD module. P3.3, P3.4 and P3.5
are connected to the E, R/W, RS pins of the microcontroller and through this route the control signals
are transffered to the LCD module. POT is used for adjusting the contrast of the display.
Programming Example:
Write an ALP to initialize the LCD and display message “YES”. Say the command to be given is
:38H (2 lines ,5x7 matrix), 0EH (LCD on, cursor on), 01H (clear LCD), 06H (shift cursor right), 86H
(cursor: line 1, pos. 6)
Program:
Calls a time delay before sending next data/command ;P1.0-P1.7 are connected to LCD data pins D0-
D7 ;P3.5 is connected to RS pin of LCD ;P3.4 is connected to R/W pin of LCD ;P3.3 is connected to
E pin of LCD.
ORG 0H
MOV A,#38H ; LCD 2 lines, 5x7 matrix
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#86H ;cursor at line 1, pos. 6
ACALL COMNWRT ;call command subroutine
Relay Interfacing
A relay is an electromechanical switch, which perform ON and OFF operations without any
human interaction. General representation of double contact relay is shown in fig.
Generally, the relay consists a inductor coil, a spring, Swing terminal (armature), and two
high power contacts named as normally closed (N/C) and normally opened (N/O). Relay uses an
Electromagnet to move swing terminal between two contacts (N/O and N/C). When there is no
power applied to the inductor coil (Relay is OFF), the spring holds the swing terminal is attached to
NC contact.
Whenever required power is applied to the inductor coil, the current flowing through the coil
generates a magnetic field which is helpful to move the swing terminal and attached it to the
normally open (NO) contact. Again when power is OFF, the spring restores the swing terminal
position to NC.
Advantage of relay:
A relay takes small power to turn ON, but it can control high power devices to switch ON and
OFF. Consider an example; a relay is used to control the ceiling FAN at our home. The ceiling
FAN may runs at 230V AC and draws a current maximum of 4A. Therefore the power required is
4X230 = 920 watts. Off course we can control AC, lights, etc., depend up on the relay ratings.
Applications of Relay
Relays are used to realize logic functions. They play a very important role in providing safety
critical logic.
Relays are used to provide time delay functions. They are used to time the delay open and
delay close of contacts.
Relays are used to control high voltage circuits with the help of low voltage signals. Similarly
they are used to control high current circuits with the help of low current signals.
They are also used as protective relays. By this function all the faults during transmission and
reception can be detected and isolated.
Relays have the exact working of a switch. So, the same concept is also applied. A relay is said to
switch one or more poles. Each pole has contacts that can be thrown in mainly three ways. They are
Normally Open Contact (NO) – NO contact is also called a make contact. It closes the circuit
when the relay is activated. It disconnects the circuit when the relay is inactive.
Normally Closed Contact (NC) – NC contact is also known as break contact. This is opposite to
the NO contact. When the relay is activated, the circuit disconnects. When the relay is deactivated,
the circuit connects.
Change-over (CO) / Double-throw (DT) Contacts – This type of contacts are used to control
two types of circuits. They are used to control a NO contact and also a NC contact with a
common terminal. According to their type they are called by the names break before
make and make before breakcontacts.
Relays are also named with designations like
Single Pole Single Throw (SPST) – This type of relay has a total of four terminals. Out of these
two terminals can be connected or disconnected. The other two terminals are needed for the coil.
Single Pole Double Throw (SPDT) – This type of a relay has a total of five terminals. Out f
these two are the coil terminals. A common terminal is also included which connects to either of
two others.
Double Pole Single Throw (DPST) – This relay has a total of six terminals. These terminals
are further divided into two pairs. Thus they can act as two SPST’s which are actuated by a single
coil. Out of the six terminals two of them are coil terminals.
Double Pole Double Throw (DPDT) – This is the biggest of all. It has mainly eight relay
terminals. Out of these two rows are designed to be change over terminals. They are designed to
act as two SPDT relays which are actuated by a single coil.
We need a large current sinker circuit between the relay and 8051 microcontroller. A
transistor which has current sinking capability greater that 70mA is enough to act as a relay driver
between the microcontrollers and relay. But the biasing circuit required for the transistor is a bit
complex. In some cases like robotic car, the number of relays required will increase. Therefore the
number of transistors and its biasing components will increase, PCB size increases, debugging is a
bit headache. So the simple way to drive the relay with 8051 microcontroller is by using
ULN2003/ULN2803. A ULN driver has 500mA current sinking capability for each output pin. When
input pin of ULN driver is at logic high then the corresponding output pin is connected to ground via
500mA fuse. Internally each fuse is designed by using Darlington transistor pair. So interfacing the
8051 microcontroller to relay via ULN driver will not damage the microcontroller port pin.
Microcontrollers have internal pull up resistors hence when a port pin is HIGH the output current
flows through this internal pull up resistor. 8051 microcontrollers have an internal pull up of 10KΩ.
Hence the maximum output current will be 5v/10k = 0.5ma. This current is not sufficient to drive
the transistor into saturation and turn ON the relay. Hence an external pull up resistor (4.7K) is used.
Relay Interfacing
The following program turns the lamp on and off shown in Figure. by energizing and de-energizing
the relay every second.
Stepper motor is a widely used device that translates electrical pulses into mechanical
movement. Stepper motor is used in applications such as; disk drives, dot matrix printer, robotics
etc,. The construction of the motor is as shown in figure 1 below.
The stator is a magnet over which the electric coil is wound. One end of the coil are connected
commonly either to ground or +5V. The other end is provided with a fixed sequence such that the
motor rotates in a particular direction. Stepper motor shaft moves in a fixed repeatable increment,
which allows one to move it to a precise position. Direction of the rotation is dictated by the stator
poles. Stator poles are determined by the current sent through the wire coils.
How much movement is associated with a single step? This depends on the internal construction of the motor,
in particular the number of teeth on the stator and the rotor. The step angle is the minimum degree of rotation
associated with a single step. Various motors have different step angles. Table below shows some step angles
for various motors. In Table, notice the term steps per revolution. This is the total number of steps needed to
rotate one complete rotation or 360 degrees (e.g., 180 steps x 2 degrees = 360).
That means, No of steps per revolution = 360° / step angle. Example: step angle = 2° No of steps per
revolution = 180
The relation between rpm (revolutions per minute), steps per revolution, and steps per second is as follows.
As discussed earlier the coils need to be energized for the rotation. This can be done by sending a
bits sequence to one end of the coil while the other end is commonly connected. The bit sequence
sent can make either one phase ON or two phase ON for a full step sequence or it can be a
combination of one and two phase ON for half step sequence. Both are tabulated below.
The following steps show the 8051 connection to the stepper motor and its programming.
1. Use an ohmmeter to measure the resistance of the leads. This should identify which
COM leads are connected to which winding leads.
2. The common wire(s) are connected to the positive side of the motor’s power supply.
In many motors, +5 V is sufficient.
3. The four leads of the stator winding are controlled by four bits of the 8051 port (Pl.O
- P1.3). However, since the 8051 lacks sufficient current to drive the stepper motor
windings, we must use a driver such as the ULN2003 to energize the stator. Instead
of the ULN2003, we could have used transistors as drivers, as shown in Figure 17-9.
However, notice that if transistors are used as drivers, we must also use diodes to
take care of inductive current generated when the coil is turned off. One reason that
using the ULN2003 is preferable to the use of transistors as drivers is that the
ULN2003 has an internal diode to take care of back EMF.
Note: Change the value of DELAY to set the speed of rotation. We can use the single-bit instructions SETB
and CLR instead of RR A to create the sequences.
ULN 2003
on an input pin will turn on the darlington pair transistor pulling down the output pin. The load goes
between the output pin and the load supply voltage which can be up to 50V.
Each channel of the array is rated at 500mA and can withstand peak currents of up to 600mA
making it ideal for controlling small motors or lamps or the gates and bases of high power
semiconductors. Additional suppression diodes are included for inductive load driving.
It consists of common cathode clamp diodes for each NPN darlington pair which makes this
driver IC useful for switching inductive loads. (The clamp diode provides a path for the inductive
discharge current to flow when the driver switch is opened. If not provided, it will generate an arc in
the switch—while the arc will not generally damage a switch contact, it will cause contact
degradation over time—and it will destroy transistors). The output of the driver is open collector and
the collector current rating of each darlington pair is 500mA. Darlington pairs may be paralleled if
higher current is required. The driver IC also consists of a 2.7KΩ base resistor for each darlington
pair. Thus each darlington pair can be operated directly with TTL or 5V CMOS devices. This driver
IC can be used for high voltage applications up to 50V.
Note that the driver provides open collector output, so it can only sink current, cannot source.
Thus when a 5V is given to 1B terminal, 1C terminal will be connected to ground via darlington pair
and the maximum current that it can handle is 500A. From the logic diagram we can see that cathode
of protection diodes are shorted to 9th pin called COM.
When an input (pins 1 to 7) is driven “HIGH” the corresponding output will switch “LOW” sinking
current. Likewise, when the input is driven “LOW” the corresponding output switches to a high
impedance state. This high impedance “OFF” state blocks load current and reduces leakage current
through the device improving efficiency.
Pin 8, (GND) is connected to the loads ground or 0 volts, while pin 9 (Vcc) connects to the loads
supply. Then any load needs to be connected between +Vcc and an output pin, pins 10 to 16. For
inductive loads such as motors, relays and solenoids, etc, pin 9 should always be connected to Vcc.
Programming Examples:
Example 1: Write an ALP to rotate the stepper motor clockwise / anticlockwise continuously with
full step sequence.
Program:
MOV A,#66H
RR A
ACALL DELAY
SJMP BACK
DJNZ R1,UP1
RET
Example 2: A switch is connected to pin P2.7. Write an ALP to monitor the status of the SW. If SW
= 0, motor moves clockwise and if SW = 1, motor moves anticlockwise.
Program:
ORG 0000H
SETB P2.7
MOV A, #66H
MOV P1,A
TURN: JNB P2.7, CW
RL A
ACALL DELAY
MOV P1,A
SJMP TURN
CW: RR A
ACALL DELAY
MOV P1,A
SJMP TURN
DELAY: MOV R1,#100
UP1: MOV R2,#50
UP: DJNZ R2,UP
DJNZ R1,UP1
RET
ADC Interfacing
Analog-to-digital converters are among the most widely used devices for data acquisition.
Digital computers or the microcontrollers use binary (discrete) values, but in the physical world
everything is analog. Temperature, pressure, humidity and velocity are a few examples of physical
quantities that we deal with everyday. A physical quantity can be converted into electrical signals
using a device called as transducer. Transducers are also referred to as sensors. Most commonly
sensors produce analog signals. We need an analog to digital converter to translate he analog signals
to digital numbers so that the microcontroller can read and process them. An ADC has n-bit
resolution where n can be 8, 10, 12, 16 or even 24 bits. The highest-resolution ADC is the one where
step size is the smallest change that can be measured by an ADC.
ADC 0804
adjusted to convert smaller analogue voltage span to 8 bit resolution etc. The pin out diagram of
ADC0804 is shown in the figure below.
The voltage at Vref/2 (pin9) of ADC0804 can be externally adjusted to convert smaller input voltage
spans to full 8 bit resolution. Vref/2 (pin9) left open means input voltage span is 0-5V and step size is
5/255=19.6V. Have a look at the table below for different Vref/2 voltages and corresponding analogue
input voltage spans.
CLK IN and CLK R: CLK IN is an input pin connected to an external clock source. To
use the internal clock generator (also called self-clocking), CLK IN and CLK R pins are
connected to a capacitor and a resistor and the clock frequency is determined by:
Typical values are R = 10K ohms and C =150pF. We get f = 606 kHz and the conversion
time is 110μs.
Vref/2 : It is used for the reference voltage. If this pin is open (not connected), the analog
input voltage is in the range of 0 to 5 volts (the same as the Vcc pin). If the analog
input range needs to be 0 to 4 volts, Vref/2 is connected to 2 volts. Step size is the
smallest change can be discerned by an ADC.
D0-D7: The digital data output pins. These are tri-state buffered. The converted data is
accessed only when CS =0 and RD is forced low. To calculate the output voltage, use
the following formula.
Analog ground and digital ground: Analog ground is connected to the ground of the
analog Vin and digital ground is connected to the ground of the Vcc pin. To isolate
the analog Vin signal from transient voltages caused by digital switching of the output
D0 – D7. This contributes to the accuracy of the digital data output.
Vin(+) & Vin(-): Differential analog inputs where Vin = Vin (+) – Vin (-). Vin (-) is
connected to ground and Vin (+) is used as the analog input to be converted.
RD: Is “output enable” a high-to-low RD pulse is used to get the 8-bit converted data out
of ADC804.
INTR: It is “end of conversion” When the conversion is finished, it goes low to signal the
CPU that the converted data is ready to be picked up.
The following steps must be followed for data conversion by the ADC804 chip:
2. Monitor the INTR pin, if high keep polling but if low, conversion is complete, go to next
step.
3. Make CS= 0 and send a H-to-L pulse to pin RD to get the data out.
Circuit Diagram
The figure above shows the schematic for interfacing ADC0804 to 8051. The circuit
initiates the ADC to convert a given analogue input , then accepts the corresponding digital data and
displays it on the LED array connected at P0. For example, if the analogue input voltage Vin is 5V
then all LEDs will glow indicating 11111111 in binary which is the equivalent of 255 in decimal.
AT89s51 is the microcontroller used here. Data out pins (D0 to D7) of the ADC0804 are connected
to the port pins P1.0 to P1.7 respectively. LEDs D1 to D8 are connected to the port pins P0.0 to P0.7
respectively. Resistors R1 to R8 are current limiting resistors. In simple words P1 of the
microcontroller is the input port and P0 is the output port. Control signals for the ADC (INTR, WR,
RD and CS) are available at port pins P3.4 to P3.7 respectively. Resistor R9 and capacitor C1 are
associated with the internal clock circuitry of the ADC. Preset resistor R10 forms a voltage divider
which can be used to apply a particular input analogue voltage to the ADC. Push button S1, resistor
R11 and capacitor C4 forms a debouncing reset mechanism. Crystal X1 and capacitors C2,C3 are
associated with the clock circuitry of the microcontroller.
Program.
ORG 00H
MOV P1,#0FFH // initiates P1 as the input port
SETB P3.4
MAIN: CLR P3.7 // makes CS=0
SETB P3.6 // makes RD high
CLR P3.5 // makes WR low
SETB P3.5 // low to high pulse to WR for starting conversion
WAIT: JB P3.4,WAIT // polls until INTR=0
CLR P3.7 // ensures CS=0
CLR P3.6 // high to low pulse to RD for reading the data from ADC
MOV A,P1 // moves the digital data to accumulator
CPL A // complements the digital data (*see the notes)
MOV P0,A // outputs the data to P0 for the LEDs
SJMP MAIN // jumps back to the MAIN program
END
Notes.
ADC 0804 has active low outputs and the instruction CPL A complements it t0 have a
straight forward display. For example, if input is 5V then the output will be 11111111 and if CPL
A was not used it would have been 00000000 which is rather awkward to see.
ADC0808/0809 chip:
ADC808 has 8 analog inputs. It allows us to monitor up to 8 different transducers using only
single chip. The chip has 8-bit data output just like the ADC804. The 8 analog input channels are
multiplexed and selected according to the values given to the three address pins, A, B, and C. that is;
if CBA=000, CH0 is selected; CBA=011, CH3 is selected and so on. The pin details of ADC0808 are
as shown in the figure 11 below. (Explanation can be done as is with ADC0804).
Pin Description
D0 – D7 – D0- D7 are the digital data output pins since ADC0808 is a parallel ADC chip. These are
tri state buffered and the converted data is accessed only when CS=0 and RD is forced low. To
calculate the output voltage, we can use following formula
Dout = Vin / step size
Where Dout = digital data output, Vin = analog input voltage, and step size is the smallest input
change.
MULTIPLEXER
The device contains an 8-channel single-ended analog signal multiplexer. A particular input channel
is selected by using the address decoder. Table 1 shows the input states for the address lines to select
any channel. The address is latched into the decoder on the low-to-high transition of the address latch
enable signal.
MOV A, P1
CLR P2.5
ACALL CONVERSION
ACALL DATA DISPLAY
SJMP BACK
where DO is the LSB, D7 is the MSB for the inputs, and Iref is the input current that must be applied
to pin 14. The Iref current is generally set to 2.0 mA. Figure shows the generation of current reference
(setting Iref = 2 mA) by using the standard 5-V power supply and IK and 1.5K-ohm standard
resistors. Some DACs also use the zener diode (LM336), which overcomes any fluctuation
associated.
Ideally we connect the output pin I out to a resistor, convert this current to voltage, and monitor
the output on the scope. In real life, however, this can cause inaccuracy since the input resistance of
the load where it is connected will also affect the output voltage. For this reason, the Iref current
output is isolated by connecting it to an op-amp such as the 741 with Rf = 5K ohms for the feedback
resistor. Assuming that R = 5K ohms, by changing the binary input, the output voltage changes as
shown in following example.
ProgrammingExample
In order to generate a stair-step ramp, set up the circuit in Figure 13-18 and connect the output to an
oscilloscope. Then write a program to send data to the DAC to generate a stair-step ramp.
To generate a sine wave, we first need a table whose values represent the magnitude of the
sine of angles between 0 and 360 degrees. The values for the sine function vary from -1.0 to +1.0 for
0- to 360-degree angles. Therefore, the table values are integer numbers representing the voltage
magnitude for the sine of theta. This method ensures that only integer numbers are output to the DAC
by the 8051 microcontroller. Table 13-7 shows the angles, the sine values, the voltage magnitudes,
and the integer values representing the voltage magnitude for each angle (with 30-degree
increments). To generate Table 13-7, we assumed the full-scale voltage of 10 V for DAC output (as
designed in Figure 13-18). Full-scale output of the DAC is achieved when all the data inputs of the
DAC are high. Therefore, to achieve the full-scale 10 V output, we use the following equation.
Vout of DAC for various angles is calculated and shown in the following Table.
Table : Angle vs. Voltage Magnitude for Sine Wave
To find the value sent to the DAC for various angles, we simply multiply the V out voltage by 25.60
because there are 256 steps and full-scale Vout is 10 volts. Therefore, 256 steps /10 V = 25.6 steps per
volt. To further clarify this, look at the following code. This program sends the values to the DAC
continuously (in an infinite loop) to produce a crude sine wave. See Figure shown below.
Program:
MOV A, #00H
INCR: MOV P1,
A INC A
CJNE A, #255, INCR
DECR: MOV P1, A
DEC A
CJNE A, #00, DECR
SJMP INCR
END