Wireless Energy Meter Data Logger on Pc
-
Upload
akhilesh-shah -
Category
Documents
-
view
224 -
download
0
Transcript of Wireless Energy Meter Data Logger on Pc
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
1/103
INTRODUCTION
In this project we show that ho we monitor the energy meter wirelessly. By
using this technique it is very easy to check the pulse to pulse. When we are
monitoring pulse to pulse then we easily detect the maximum load period,
easily check the meter failure and at the same time we easily monitor the
tapping also.
Logic behind this project is to transfer the pulse of meter via radio frequency
module. With the help of radio frequency module we made connectivity
between meter and central monitor system. In this project we check the pulse
monitoring of two meter at a time.
In this project we use three circuits. One each for the meter and one as a
central receiver and transfer the data on the led.
1
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
2/103
2
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
3/103
Transmitter circuit.
In the transmitter circuit we use one small energy meter to get the data of
pulse . Now first of all we connect a load with the meter. In this section of
the project we use one step down transformer to step down the voltage from
220 volt ac to 9-0-9 ac. This transformer is a centre tap transformer having a
current rating of 1 ampere. Output of the centre tap transformer is connected
to the rectifier circuit. In this project we use full wave rectifier to convert the
ac voltage from the transformer to pulsating dc. This pulsating dc is further
converted into smooth dc with the help of capacitor filter. Capacitor convert
the pulsating dc into smooth dc and with the help of
regulator we regulate the voltage to 5 volt dc.
Here we use 7805 regulator to regulate the voltage
for 5 volt dc.
3
Figure 1
Figure 2
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
4/103
Output from the meter is connected to the electronics transmitter circuit via
optocoupler device. Optocoupler device provide an optical isolation
between meter and electronics circuit. In this project we use pc 817
optocoupler. Pin no 1,2 is connected to meter internally and output of the
optocoupler is connected to the lm358 comparator. Other pin of the
comparator is connected to the variable resistor to set the reference voltage.
As the pulse is on the op-amp then circuit provide a output signal. Meter
provides a 3200 pulse for one unit. These 3200 pulses are transmit by the
RF transmitter serially. Here we use 433 MHz transmitters to transmit the
pulse. We connect a 4 bit encoder between pulse and RF transmitter. We use
HT 12 e encoder to interface the data with RF module HT12 E and HT 12 D
decoder are easily available in the market.
The 212 encoders are a series of CMOS LSIs for remote
control system applications. They are capable of encoding
information which consists of N address bits and 12_N data
bits. Each address/data input can be set to one of the two
logic states. The programmed addresses/ data are
transmitted together with the header bits via an RF or an
infrared transmission medium upon receipt of a trigger
signal. The capability to select a TE trigger on the HT12E or a
4
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
5/103
DATA trigger on the HT12A further enhances the application
flexibility of the 212 series of encoders. The HT12A
additionally provides a 38 kHz carrier for infrared systems.
5
Figure 3
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
6/103
In this portion of transmitter circuit we add a small IC 555 here. Here IC
555 work as a astable multivibrator to produce a square wave when required.
We use this circuit to check the transmitter for proper working. In actual
meter pulse is not very fast, its according to the load. With the help of IC
555 we generate a artificial pulse for fast pulse. One switch is connected
between artificial pulse and actual pulse . We select the switch position as
we required.
6
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
7/103
7
Figure 4
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
8/103
8
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
9/103
In the receiver circuit we use two decoder to get the data. Data is received by
the Rf receiver. This rf module is pair version of the transmitter . Rf
receiver demodulate the data and connected to the decoder circuit. In the
decoder circuit we decode the data with address matching. IN the portion of
project we use two decoder circuit because we use two transmitter with two
different energy meter. In both the encoder and decoder circuit we use
separate address line for easy decoding. This address coding point is very
much important in the project. Output of decoder is connected to the 89s51
controller directly. Controller get the input from decoder and converted into
ASCII code and display the same on the lcd display. Here we use 2 by 16
lcd to display the code with specific address and store the data in ram. In
later on this data is to be store on the external memory 24c02.
Controller not only display the data on lcd but at the same time transfer the
data to pc via max 232 ic.
Microcontroller convert the data into serially and transfer to the pc at the rate
of 9600 bps. 9600 is the default baud rate of the pc for interface. In the pc
we display the same data on HyperTerminal or in visual basic platform
In this project we use one 5 volt regulated power supply to
convert the 220 volt ac in to 5 volt dc with the help of the 5 volt
9
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
10/103
regulator circuit. First OF all we step down the 220 volt ac into 6 volt
ac with the help of step down transformer. Step down transformer
step down the voltage from 220 volt ac to 9 volt ac. This ac is further
converted into the dc voltage with the help of the full wave rectifier
circuit
Output of the diode is pulsating dc . so to convert the pulsating dc into
smooth dc we use electrolytic capacitor. Electrolytic capacitor convert
the pulsating dc into smooth dc. This Dc is further regulated by the ic
7805 regulator. IC 7805 regulator provide a regulated 5 volt dc to the
microcontroller circuit and lcd circuit.
Pin no 40 of the controller is connected to the positive supply. Pin no
20 is connected to the ground. Pin no 9 is connected to external
10
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
11/103
resistor capacitor to provide a automatic reset option when power is
on.
Reset Circuitry:
Pin no 9 of the controller is connected to the reset circuit. On the
circuit we connect one resistor and capacitor circuit to provide a reset
option when power is on
As soon as you give the power supply the 8051 doesnt start. You
need to restart for the microcontroller to start. Restarting the
microcontroller is nothing but giving a Logic 1 to the reset pin at least
for the 2 clock pulses. So it is good to go for a small circuit which can
provide the 2 clock pulses as soon as the microcontroller is powered.
This is not a big circuit we are just using a capacitor to charge the
microcontroller and again discharging via resistor.
11
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
12/103
Crystals
Pin no 18 and 19 is connected to external crystal oscillator to provide
a clock to the circuit.
Crystals provide the synchronization of the internal function and to the
peripherals. Whenever ever we are using crystals we need to put the capacitor
behind it to make it free from noises. It is good to go for a 33pf capacitor.
We can also resonators instead of costly crystal which are low cost
and external capacitor can be avoided.
12
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
13/103
But the frequency of the resonators varies a lot. And it is strictly not
advised when used for communications projects.
How is this time then calculated?
The speed with which a microcontroller executes instructions is
determined by what is known as the crystal speed. A crystal is a
component connected externally to the microcontroller. The crystal
has different values, and some of the used values are 6MHZ, 10MHZ,
and 11.059 MHz etc.
Thus a 10MHZ crystal would pulse at the rate of 10,000,000 times
per second.
The time is calculated using the formula
No of cycles per second = Crystal frequency in HZ / 12.
For a 10MHZ crystal the number of cycles would be,
10,000,000/12=833333.33333 cycles.
This means that in one second, the microcontroller would execute
833333.33333 cycles.
13
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
14/103
Pin no 1 to pin no 8 is PORT 1 and Pin no 10 to 17 is PORT 3. Pin no
18 and 19 of the ic is connected to the external crystal to provide a
external clock to run the internal CPU of controller . Pin no 20 is
ground pin. Pin no 21 to 28 is PORT 2 pins. Pin no 29,30,31 is not
use in this project. We use these pin when we require a extra
memory for the project. If we internal memory of the 89s51 ( which is
4k rom) then we connect pin no 31 to the positive supply.
14
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
15/103
The TWS-434 and RWS-434 are extremely small, and are excellentfor applications requiring short-range RF remote controls. Thetransmitter module is only 1/3 the size of a standard postage stamp,and can easily be placed inside a small plastic enclosure.
TWS-434: The transmitter output is up to 8mW at 433.92MHz with a
range of approximately 400 foot (open area) outdoors. Indoors, therange is approximately 200 foot, and will go through most walls.....
TWS-434A
The TWS-434 transmitter accepts both linear and digital inputs, canoperate from 1.5 to 12 Volts-DC, and makes building a miniature
hand-held RF transmitter very easy. The TWS-434 is approximatelythe size of a standard postage stamp.
TWS-434 Pin Diagram
15
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
16/103
Sample Transmitter Application Circuit
RWS-434: The receiver also operates at 433.92MHz, and has asensitivity of 3uV. The RWS-434 receiver operates from 4.5 to 5.5volts-DC, and has both linear and digital outputs.
Click on picture for larger image
RWS-434 Receiver
16
http://www.rentron.com/images/rws434med.jpg -
7/28/2019 Wireless Energy Meter Data Logger on Pc
17/103
RWS-434 Pin Diagram
Sample Receiver Application Circuit
17
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
18/103
The example above shows the receiver section using the HT-12D decoder IC
for a 4-bit RF remote control system. The transmitter and receiver can also use
the Holtek 8-bit HT-640/HT-648L remote control encoder/decoder combination
for an 8-bit RF remote control system. Here are the schematics for an 8-bit RF
remote control system:
LIQUID CRYSTAL DISPLAY
A liquid crystal display (LCD) is a thin, flat display device made up of anynumber of color ormonochromepixels arrayed in front of a light source or
reflector. It is prized by engineers because it uses very small amounts of
electric power, and is therefore suitable for use in battery-powered electronicdevices.
18
http://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Display_devicehttp://en.wikipedia.org/wiki/Monochromehttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Lighthttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Display_devicehttp://en.wikipedia.org/wiki/Monochromehttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Lighthttp://en.wikipedia.org/wiki/Electronics -
7/28/2019 Wireless Energy Meter Data Logger on Pc
19/103
Reflective twisted nematic liquid crystal display.
1. Vertical filter film topolarize the light as it enters.2. Glass substrate with ITO electrodes. The shapes of these electrodes
will determine the dark shapes that will appear when the LCD isturned on or off. Vertical ridges etched on the surface are smooth.3. Twisted nematic liquid crystals.4. Glass substrate with common electrode film (ITO) with horizontal
ridges to line up with the horizontal filter.5. Horizontal filter film to block/allow through light.6. Reflective surface to send light back to viewer.
19
http://en.wikipedia.org/wiki/Polarisationhttp://en.wikipedia.org/wiki/Indium_tin_oxidehttp://en.wikipedia.org/wiki/Polarisationhttp://en.wikipedia.org/wiki/Indium_tin_oxide -
7/28/2019 Wireless Energy Meter Data Logger on Pc
20/103
A subpixel of a color LCD
Overview
Eachpixel of an LCD consists of a layer of liquid crystal molecules alignedbetween two transparent electrodes, and twopolarizing filters, the axes ofpolarity of which are perpendicular to each other. With no liquid crystalbetween the polarizing filters, light passing through one filter would beblocked by the other.
The surfaces of the electrodes that are in contact with the liquid crystalmaterial are treated so as to align the liquid crystal molecules in a particular
direction. This treatment typically consists of a thin polymer layer that isunidirectionally rubbed using a cloth (the direction of the liquid crystalalignment is defined by the direction of rubbing).
Before applying an electric field, the orientation of the liquid crystalmolecules is determined by the alignment at the surfaces. In a twistednematic device (the most common liquid crystal device), the surface
20
http://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Indium_tin_oxidehttp://en.wikipedia.org/wiki/Polarizationhttp://upload.wikimedia.org/wikipedia/commons/d/d9/LCD_subpixel_%28en%29.pnghttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Indium_tin_oxidehttp://en.wikipedia.org/wiki/Polarization -
7/28/2019 Wireless Energy Meter Data Logger on Pc
21/103
alignment directions at the two electrodes are perpendicular, and so themolecules arrange themselves in a helical structure, or twist. Because theliquid crystal material is birefringent (i.e. light of different polarizationstravels at different speeds through the material), light passing through one
polarizing filter is rotated by the liquid crystal helix as it passes through theliquid crystal layer, allowing it to pass through the second polarized filter.Half of the light is absorbed by the first polarizing filter, but otherwise theentire assembly is transparent.
When a voltage is applied across the electrodes, a torque acts to align theliquid crystal molecules parallel to the electric field, distorting the helicalstructure (this is resisted by elastic forces since the molecules areconstrained at the surfaces). This reduces the rotation of the polarization ofthe incident light, and the device appears gray. If the applied voltage is large
enough, the liquid crystal molecules are completely untwisted and thepolarization of the incident light is not rotated at all as it passes through theliquid crystal layer. This light will then be polarized perpendicular to thesecond filter, and thus be completely blocked and the pixel will appear
black. By controlling the voltage applied across the liquid crystal layer ineachpixel, light can be allowed to pass through in varying amounts,correspondingly illuminating the pixel.
With a twisted nematic liquid crystal device it is usual to operate the devicebetween crossed polarizers, such that it appears bright with no applied
voltage. With this setup, the dark voltage-on state is uniform. The device canbe operated between parallel polarizers, in which case the bright and darkstates are reversed (in this configuration, the dark state appears blotchy).
Both the liquid crystal material and the alignment layer material containionic compounds. If an electric field of one particular polarity is applied fora long period of time, this ionic material is attracted to the surfaces anddegrades the device performance. This is avoided by applying either analternating current, or by reversing the polarity of the electric field as the
device is addressed (the response of the liquid crystal layer is identical,regardless of the polarity of the applied field).
When a large number of pixels is required in a display, it is not feasible todrive each directly since then each pixel would require independentelectrodes. Instead, the display is multiplexed. In a multiplexed display,electrodes on one side of the display are grouped and wired together
21
http://en.wikipedia.org/wiki/Helixhttp://en.wikipedia.org/wiki/Electric_fieldhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Alternating_currenthttp://en.wikipedia.org/wiki/Helixhttp://en.wikipedia.org/wiki/Electric_fieldhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Alternating_current -
7/28/2019 Wireless Energy Meter Data Logger on Pc
22/103
(typically in columns), and each group gets its own voltage source. On theother side, the electrodes are also grouped (typically in rows), with eachgroup getting a voltage sink. The groups are designed so each pixel has aunique, unshared combination of source and sink. The electronics, or thesoftware driving the electronics then turns on sinks in sequence, and drivessources for the pixels of each sink.
Important factors to consider when evaluating an LCD monitor includeresolution, viewable size, response time (sync rate), matrix type (passive oractive), viewing angle, color support, brightness and contrast ratio, aspectratio, and input ports (e.g. DVI orVGA).
Color displays
In color LCDs each individualpixel is divided into three cells, or subpixels,which are colored red, green, and blue, respectively, by additional filters(pigment filters, dye filters and metal oxide filters). Each subpixel can becontrolled independently to yield thousands or millions of possible colors for
each pixel. OlderCRT monitors employ a similar method.
Color components may be arrayed in variouspixel geometries, depending onthe monitor's usage. If software knows which type of geometry is being usedin a given LCD, this can be used to increase the apparent resolution of themonitor through subpixel rendering. This technique is especially useful fortext anti-aliasing.
22
http://en.wikipedia.org/wiki/Display_resolutionhttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Liquid_crystal_display#Passive-matrix_and_active-matrix%23Passive-matrix_and_active-matrixhttp://en.wikipedia.org/wiki/Viewing_anglehttp://en.wikipedia.org/wiki/Contrast_(vision)http://en.wikipedia.org/wiki/Digital_Visual_Interfacehttp://en.wikipedia.org/wiki/Video_Graphics_Arrayhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Cathode_ray_tubehttp://en.wikipedia.org/wiki/Pixel_geometryhttp://en.wikipedia.org/wiki/Subpixel_renderinghttp://en.wikipedia.org/wiki/Anti-aliasinghttp://en.wikipedia.org/wiki/Display_resolutionhttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Liquid_crystal_display#Passive-matrix_and_active-matrix%23Passive-matrix_and_active-matrixhttp://en.wikipedia.org/wiki/Viewing_anglehttp://en.wikipedia.org/wiki/Contrast_(vision)http://en.wikipedia.org/wiki/Digital_Visual_Interfacehttp://en.wikipedia.org/wiki/Video_Graphics_Arrayhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Cathode_ray_tubehttp://en.wikipedia.org/wiki/Pixel_geometryhttp://en.wikipedia.org/wiki/Subpixel_renderinghttp://en.wikipedia.org/wiki/Anti-aliasing -
7/28/2019 Wireless Energy Meter Data Logger on Pc
23/103
23
http://upload.wikimedia.org/wikipedia/commons/7/74/Liquid_Crystal_Display_Macro_Example_zoom.jpg -
7/28/2019 Wireless Energy Meter Data Logger on Pc
24/103
Passive-matrix and active-matrix
A general purpose alphanumeric LCD, with two lines of 16 characters.
LCDs with a small number of segments, such as those used in digitalwatches andpocket calculators, have a single electrical contact for eachsegment. An external dedicated circuit supplies an electric charge to controleach segment. This display structure is unwieldy for more than a few display
elements.
Small monochrome displays such as those found in personal organizers, orolderlaptop screens have a passive-matrix structure employing supertwistnematic (STN) or double-layer STN (DSTN) technology (DSTN corrects acolor-shifting problem with STN). Each row or column of the display has asingle electrical circuit. The pixels are addressed one at a time by row andcolumn addresses. This type of display is called a passive matrix because the
pixel must retain its state between refreshes without the benefit of a steady
electrical charge. As the number of pixels (and, correspondingly, columnsand rows) increases, this type of display becomes less feasible. Very slowresponse times and poorcontrast are typical of passive-matrix LCDs.
High-resolution color displays such as modern LCD computer monitors andtelevisions use an active matrix structure. A matrix ofthin-film transistors(TFTs) is added to the polarizing and color filters. Each pixel has its own
24
http://en.wikipedia.org/wiki/Alphanumerichttp://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Electrical_networkhttp://en.wikipedia.org/wiki/Laptophttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Contrasthttp://en.wikipedia.org/wiki/Display_resolutionhttp://en.wikipedia.org/wiki/Computer_displayhttp://en.wikipedia.org/wiki/Televisionshttp://en.wikipedia.org/wiki/Active-matrix_liquid_crystal_displayhttp://en.wikipedia.org/wiki/Thin-film_transistorhttp://upload.wikimedia.org/wikipedia/en/2/24/LCD_display_16x2_alphanumeric.jpghttp://en.wikipedia.org/wiki/Alphanumerichttp://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Electrical_networkhttp://en.wikipedia.org/wiki/Laptophttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Contrasthttp://en.wikipedia.org/wiki/Display_resolutionhttp://en.wikipedia.org/wiki/Computer_displayhttp://en.wikipedia.org/wiki/Televisionshttp://en.wikipedia.org/wiki/Active-matrix_liquid_crystal_displayhttp://en.wikipedia.org/wiki/Thin-film_transistor -
7/28/2019 Wireless Energy Meter Data Logger on Pc
25/103
dedicated transistor, allowing each column line to access one pixel. When arow line is activated, all of the column lines are connected to a row of pixelsand the correct voltage is driven onto all of the column lines. The row line isthen deactivated and the next row line is activated. All of the row lines areactivated in sequence during a refresh operation. Active-matrix displays aremuch brighter and sharper than passive-matrix displays of the same size, andgenerally have quicker response times, producing much better images.
Twisted nematic (TN)
LCD Display Technology
.In-plane switching (IPS)
control
Some LCD panels have defective transistors, causing permanently lit or unlitpixels which are commonly referred to as stuck pixels ordead pixelsrespectively. Unlike integrated circuits, LCD panels with a few defective
pixels are usually still usable. It is also economically prohibitive to discard apanel with just a few defective pixels because LCD panels are much largerthan ICs. Manufacturers have different standards for determining amaximum acceptable number of defective pixels. The maximum acceptable
number of defective pixels for LCD varies a lot (such as zero-tolerancepolicy and 11-dead-pixel policy) from one brand to another, often a hotdebate between manufacturers and customers. To regulate the acceptabilityof defects and to protect the end user, ISO released the ISO 13406-2standard. However, not every LCD manufacturer conforms to the ISOstandard and the ISO standard is quite often interpreted in different ways.
25
http://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Refresh_ratehttp://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Stuck_pixelhttp://en.wikipedia.org/wiki/Dead_pixelhttp://en.wikipedia.org/wiki/Integrated_circuitshttp://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Refresh_ratehttp://en.wikipedia.org/wiki/Transistorhttp://en.wikipedia.org/wiki/Stuck_pixelhttp://en.wikipedia.org/wiki/Dead_pixelhttp://en.wikipedia.org/wiki/Integrated_circuits -
7/28/2019 Wireless Energy Meter Data Logger on Pc
26/103
Examples of defects in LCD displays
LCD panels are more likely to have defects than most ICs due to their largersize. In this example, a 12" SVGA LCD has 8 defects and a 6" wafer hasonly 3 defects. However, 134 of the 137 dies on the wafer will beacceptable, whereas rejection of the LCD panel would be a 0% yield. Thestandard is much higher now due to fierce competition betweenmanufacturers and improved quality control. An SVGA LCD panel with 4defective pixels is usually considered defective and customers can request anexchange for a new one. Some manufacturers, notably in South Korea wheresome of the largest LCD panel manufacturers, such as LG, are located, now
have "zero defective pixel guarantee" and would replace a product even withone defective pixel. Even where such guarantees do not exist, the location ofdefective pixels is important. A display with only a few defective pixels may
be unacceptable if the defective pixels are near each other. Manufacturersmay also relax their replacement criteria when defective pixels are in thecenter of the viewing area.
Zero-power displaysThe zenithal bistable device (ZBD), developed by QinetiQ (formerlyDERA), can retain an image without power. The crystals may exist in one oftwo stable orientations (Black and "White") and power is only required tochange the image. ZBD Displays is a spin-off company from QinetiQ whomanufacture both grayscale and colour ZBD devices.
26
http://en.wikipedia.org/wiki/QinetiQhttp://en.wikipedia.org/wiki/DERAhttp://www.zbddisplays.com/http://en.wikipedia.org/wiki/QinetiQhttp://en.wikipedia.org/wiki/DERAhttp://www.zbddisplays.com/ -
7/28/2019 Wireless Energy Meter Data Logger on Pc
27/103
A French company, Nemoptic, has developed another zero-power,paper-like LCD technology which has been mass-produced in Taiwan since July2003. This technology is intended for use in low-power mobile applicationssuch as e-books and wearable computers. Zero-power LCDs are incompetition with electronic paper.
Kent Displays has also developed a "no power" display that uses PolymerStabilized Cholesteric Liquid Crystals (ChLCD). The major drawback to theChLCD display is slow refresh rate, especially with low temperatures.
Drawbacks
LCD technology still has a few drawbacks in comparison to some otherdisplay technologies:
While CRTs are capable of displaying multiple video resolutionswithout introducing artifacts, LCD displays produce crisp images only intheir "native resolution" and, sometimes, fractions of that native resolution.Attempting to run LCD display panels at non-native resolutions usuallyresults in the panel scaling the image, which introduces blurriness or"blockiness".
LCD displays have a lowercontrast ratio than that on a plasma displayor CRT. This is due to their "light valve" nature: some light always leaksout and turns black into gray. In brightly lit rooms the contrast of LCDmonitors can, however, exceed some CRT displays due to highermaximum brightness.
LCDs have longer response time than their plasma and CRTcounterparts, older displays creating visible ghosting when images rapidlychange; this drawback, however, is continually improving as thetechnology progresses and is hardly noticeable in current LCD displayswith "overdrive" technology. Most newer LCDs have response times of
around 8 ms. In addition to the response times, some LCD panels have significant
input lag, which makes them unsuitable for fast and time-precise mouseoperations (CAD design, FPS gaming) as compared to CRTs
Overdrive technology on some panels can produce artifacts acrossregions of rapidly transitioning pixels (eg. video images) that looks likeincreased image noise or halos. This is a side effect of the pixels being
27
http://en.wikipedia.org/wiki/Paperhttp://en.wikipedia.org/wiki/Taiwanhttp://en.wikipedia.org/wiki/Electronic_paperhttp://en.wikipedia.org/wiki/Native_resolutionhttp://en.wikipedia.org/wiki/Image_scalinghttp://en.wikipedia.org/wiki/Contrast_ratiohttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Ghostinghttp://en.wikipedia.org/wiki/Input_laghttp://en.wikipedia.org/wiki/Paperhttp://en.wikipedia.org/wiki/Taiwanhttp://en.wikipedia.org/wiki/Electronic_paperhttp://en.wikipedia.org/wiki/Native_resolutionhttp://en.wikipedia.org/wiki/Image_scalinghttp://en.wikipedia.org/wiki/Contrast_ratiohttp://en.wikipedia.org/wiki/Response_timehttp://en.wikipedia.org/wiki/Ghostinghttp://en.wikipedia.org/wiki/Input_lag -
7/28/2019 Wireless Energy Meter Data Logger on Pc
28/103
driven past their intended brightness value (or rather the intended voltagenecessary to produce this necessary brightness/colour) and then allowed tofall back to the target brightness in order to enhance response times.
LCD display panels have a limited viewing angle, thus reducing thenumber of people who can conveniently view the same image. As theviewer moves closer to the limit of the viewing angle, the colors andcontrast appear to deteriorate. However, this negative has actually beencapitalized upon in two ways. Some vendors offer screens withintentionally reduced viewing angle, to provide additional privacy, such aswhen someone is using a laptop in a public place. Such a set can also showtwo different images to one viewer, providing a three-dimensional effect.
Some users of older (around pre-2000) LCD monitors complain ofmigraines and eyestrain problems due to flicker from fluorescent
backlights fed at 50 or 60 Hz. This does not happen with most modern
displays which feed backlights with high-frequency current. LCD screens occasionally suffer from image persistence, which is
similar to screen burn on CRT and plasma displays. This is becoming lessof a problem as technology advances, with newer LCD panels usingvarious methods to reduce the problem. Sometimes the panel can berestored to normal by displaying an all-white pattern for extended periodsof time.
Some light guns do not work with this type of display since they donot have flexible lighting dynamics that CRTs have. However, the fieldemission display will be a potential replacement for LCD flat-paneldisplays since they emulate CRTs in some technological ways.
Some panels are incapable of displaying low resolution screen modes(such as 320x200). However, this is due to the circuitry that drives theLCD rather than the LCD itself.
Consumer LCD monitors are more fragile than their CRTcounterparts, with the screen especially vulnerable. However, lighterweight makes falling less dangerous, and some displays may be protectedwith glass shields.
28
http://en.wikipedia.org/wiki/Viewing_anglehttp://en.wikipedia.org/wiki/Image_persistencehttp://en.wikipedia.org/wiki/Phosphor_burn-inhttp://en.wikipedia.org/wiki/Light_gunhttp://en.wikipedia.org/wiki/CRThttp://en.wikipedia.org/wiki/Field_emission_displayhttp://en.wikipedia.org/wiki/Field_emission_displayhttp://en.wikipedia.org/wiki/Flat-panelhttp://en.wikipedia.org/wiki/Viewing_anglehttp://en.wikipedia.org/wiki/Image_persistencehttp://en.wikipedia.org/wiki/Phosphor_burn-inhttp://en.wikipedia.org/wiki/Light_gunhttp://en.wikipedia.org/wiki/CRThttp://en.wikipedia.org/wiki/Field_emission_displayhttp://en.wikipedia.org/wiki/Field_emission_displayhttp://en.wikipedia.org/wiki/Flat-panel -
7/28/2019 Wireless Energy Meter Data Logger on Pc
29/103
8051 micro controller
The 8051
The 8051 developed and launched in the early 80`s, is one of the mostpopular micro controller in use today. It has a reasonably large amount ofbuilt in ROM and RAM. In addition it has the ability to access externalmemory.
The generic term `8x51` is used to define the device. The value of x definingthe kind of ROM, i.e. x=0, indicates none, x=3, indicates mask ROM, x=7,indicates EPROM and x=9 indicates EEPROM or Flash.
A note on ROM
The early 8051, namely the 8031 was designed without any ROM. Thisdevice could run only with external memory connected to it. Subsequentdevelopments lead to the development of the PROM or the programmableROM. This type had the disadvantage of being highly unreliable.
The next in line, was the EPROM or Erasable Programmable ROM. Thesedevices used ultraviolet light erasable memory cells. Thus a program could
be loaded, tested and erased using ultra violet rays. A new program couldthen be loaded again.
An improved EPROM was the EEPROM or the electrically erasable PROM.This does not require ultra violet rays, and memory can be cleared usingcircuits within the chip itself.
Finally there is the FLASH, which is an improvement over the EEPROM.While the terms EEPROM and flash are sometimes used interchangeably,the difference lies in the fact that flash erases the complete memory at onestroke, and not act on the individual cells. This results in reducing the timefor erasure.
Different microcontrollers in market.
29
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
30/103
PIC One of the famous microcontrollers used in the industries. It is
based on RISC Architecture which makes the microcontroller process faster thanother microcontroller.
INTEL These are the first to manufacture microcontrollers. These are not
as sophisticated other microcontrollers but still the easiest one to learn.
ATMEL Atmels AVR microcontrollers are one of the most
powerful in the embedded industry. This is the only microcontroller having 1kb ofram even the entry stage. But it is unfortunate that in India we are unable to findthis kind of microcontroller.
Intel 8051
Intel 8051 is CISC architecture which is easy to program in assembly language and alsohas a good support for High level languages.
The memory of the microcontroller can be extended up to 64k.
This microcontroller is one of the easiest microcontrollers to learn.
The 8051 microcontroller is in the field for more than 20 years. There are lots of booksand study materials are readily available for 8051.
30
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
31/103
Derivatives
The best thing done by Intel is to give the designs of the 8051 microcontroller toeveryone. So it is not the fact that Intel is the only manufacture for the 8051 there morethan 20 manufactures, with each of minimum 20 models. Literally there are hundreds ofmodels of 8051 microcontroller available in market to choose. Some of the majormanufactures of 8051 are
Atmel
Philips
Philips
The Philipss 8051 derivatives has more number of features than in anymicrocontroller. The costs of the Philips microcontrollers are higher than the Atmelswhich makes us to choose Atmel more often than Philips
Dallas
Dallas has made many revolutions in the semiconductor market. Dallass 8051derivative is the fastest one in the market. It works 3 times as fast as a 8051 can process.But we are unable to get more in India.
Atmel
These people were the one to master the flash devices. They are the cheapest
microcontroller available in the market. Atmels even introduced a 20pin variant of 8051named 2051. The Atmels 8051 derivatives can be got in India less than 70 rupees. Thereare lots of cheap programmers available in India for Atmel. So it is always good forstudents to stick with 8051 when you learn a new microcontroller.
]
31
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
32/103
Architecture
Architecture is must to learn because before learning new machine it is necessary to learnthe capabilities of the machine. This is some thing like before learning about the car you
cannot become a good driver. The architecture of the 8051 is given below.
The 8051 doesnt have any special feature than other microcontroller. The only feature isthat it is easy to learn. Architecture makes us to know about the hardware features of themicrocontroller. The features of the 8051 are
4K Bytes of Flash Memory
128 x 8-Bit Internal RAM
Fully Static Operation: 1 MHz to 24 MHz
32 Programmable I/O Lines
Two 16-Bit Timer/Counters
Six Interrupt Sources (5 Vectored)
Programmable Serial Channel
32
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
33/103
Low Power Idle and Power Down Modes
The 8051 has a 8-Bit CPU that means it is able to process 8 bit of data at a time. 8051 has235 instructions. Some of the important registers and their functions are
Lets now move on to a practical example. We shall work on a simple
practical application and using the example as a base, shall explore the
various features of the 8051 microcontroller.
Consider an electric circuit as follows,
The positive side (+ve) of the battery is connected to one side of a switch.The other side of the switch is connected to a bulb or LED (Light EmittingDiode). The bulb is then connected to a resistor, and the other end of theresistor is connected to the negative (-ve) side of the battery.
When the switch is closed or switched on the bulb glows. When the switchis open or switched off the bulb goes off
If you are instructed to put the switch on and off every 30 seconds, howwould you do it? Obviously you would keep looking at your watch andevery time the second hand crosses 30 seconds you would keep turning theswitch on and off.
Imagine if you had to do this action consistently for a full day. Do you think
33
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
34/103
you would be able to do it? Now if you had to do this for a month, a year??
No way, you would say!
The next step would be, then to make it automatic. This is where we use theMicrocontroller.
But if the action has to take place every 30 seconds, how will themicrocontroller keep track of time?
Execution time
Look at the following instruction,clr p1.0
This is an assembly language instruction. It means we are instructing themicrocontroller to put a value of zero in bit zero of port one. Thisinstruction is equivalent to telling the microcontroller to switch on the bulb.The instruction then to instruct the microcontroller to switch off the bulb is,
Set p1.0
This instructs the microcontroller to put a value of one in bit zero of portone.
Dont worry about what bit zero and port one means. We shall learn it inmore detail as we proceed.
There are a set of well defined instructions, which are used whilecommunicating with the microcontroller. Each of these instructions requiresa standard number of cycles to execute. The cycle could be one or more innumber.
How is this time then calculated?
The speed with which a microcontroller executes instructions is determinedby what is known as the crystal speed. A crystal is a component connectedexternally to the microcontroller. The crystal has different values, and someof the used values are 6MHZ, 10MHZ, and 11.059 MHz etc.
34
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
35/103
Thus a 10MHZ crystal would pulse at the rate of 10,000,000 times persecond.
The time is calculated using the formula
No of cycles per second = Crystal frequency in HZ / 12.
For a 10MHZ crystal the number of cycles would be,
10,000,000/12=833333.33333 cycles.
This means that in one second, the microcontroller would execute 833333.33333 cycles.
Therefore for one cycle, what would be the time? Try it out.
The instruction clr p1.0 would use one cycle to execute. Similarly, the instruction setbp1.0 also uses one cycle.
So go ahead and calculate what would be the number of cycles required to be executed toget a time of 30 seconds!
Getting back to our bulb example, all we would need to do is to instruct themicrocontroller to carry out some instructions equivalent to a period of 30 seconds, likecounting from zero upwards, then switch on the bulb, carry out instructions equivalent to30 seconds and switch off the bulb.
Just put the whole thing in a loop, and you have a never ending on-off sequence.
Let us now have a look at the features of the 8051core, keeping the aboveexample as a reference,
1. 8-bit CPU.( Consisting of the A and B registers)
Most of the transactions within the microcontroller are carried out throughthe A register, also known as the Accumulator. In addition all arithmeticfunctions are carried out generally in the A register. There is anotherregister known as the B register, which is used exclusively for
35
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
36/103
multiplication and division.
Thus an 8-bit notation would indicate that the maximum value that can beinput into these registers is 11111111. Puzzled?
The value is not decimal 111, 11,111! It represents a binary number, havingan equivalent value of FF in Hexadecimal and a value of 255 in decimal.
We shall read in more detail on the different numbering systems namely theBinary and Hexadecimal system in our next module.
2. 4K on-chip ROM
Once you have written out the instructions for the microcontroller, where do
you put these instructions?
Obviously you would like these instructions to be safe, and not get deletedor changed during execution. Hence you would load it into the ROM
The size of the program you write is bound to vary depending on theapplication, and the number of lines. The 8051 microcontroller gives youspace to load up to 4K of program size into the internal ROM.
4K, thats all? Well just wait. You would be surprised at the amount of stuffyou can load in this 4K of space.
Of course you could always extend the space by connecting to 64K ofexternal ROM if required.
3. 128 bytes on-chip RAM
This is the space provided for executing the program in terms of movingdata, storing data etc.
4. 32 I/O lines. (Four- 8 bit ports, labeled P0, P1, P2, P3)
In our bulb example, we used the notation p1.0. This means bit zero of portone. One bit controls one bulb.
Thus port one would have 8 bits. There are a total of four ports named p0,
36
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
37/103
p1, p2, p3, giving a total of 32 lines. These lines can be used both as input oroutput.
5. Two 16 bit timers / counters.
A microcontroller normally executes one instruction at a time. Howevercertain applications would require that some event has to be trackedindependent of the main program.
The manufacturers have provided a solution, by providing two timers. Thesetimers execute in the background independent of the main program. Oncethe required time has been reached, (remember the time calculationsdescribed above?), they can trigger a branch in the main program.
These timers can also be used as counters, so that they can count the numberof events, and on reaching the required count, can cause a branch in the main
program.
6. Full Duplex serial data receiver / transmitter.
The 8051 microcontroller is capable of communicating with external deviceslike the PC etc. Here data is sent in the form of bytes, at predefined speeds,also known as baud rates.
The transmission is serial, in the sense, one bit at a time
7. 5- interrupt sources with two priority levels (Two external and three
internal)
During the discussion on the timers, we had indicated that the timers cantrigger a branch in the main program. However, what would we do in casewe would like the microcontroller to take the branch, and then return back to
the main program, without having to constantly check whether the requiredtime / count has been reached?
This is where the interrupts come into play. These can be set to either thetimers, or to some external events. Whenever the background program hasreached the required criteria in terms of time or count or an external event,the branch is taken, and on completion of the branch, the control returns to
37
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
38/103
the main program.
Priority levels indicate which interrupt is more important, and needs to beexecuted first in case two interrupts occur at the same time.
8. On-chip clock oscillator.
This represents the oscillator circuits within the microcontroller. Thus thehardware is reduced to just simply connecting an external crystal, to achievethe required pulsing rate.
PIN FUNCTION OF IC 89C51.
1 Supply pin of this ic is pin no 40. Normally we apply a 5 volt regulated dcpower supply to this pin. For this purpose either we use step downtransformer power supply or we use 9 volt battery with 7805 regulator.
2 Groundpin of this ic is pin no 20. Pin no 20 is normally connected to theground pin ( normally negative point of the power supply.
3 XTAL is connected to the pin no 18 and pin no 19 of this ic. The quartzcrystal oscillator connected to XTAL1 and XTAL2 PIN. These pins also needs
two capacitors of 30 pf value. One side of each capacitor is connected tocrystal and other pis is connected to the ground point. Normally we connect
a 12 MHz or 11.0592 MHz crystal with this ic.. But we use crystal upto 20
MHz to this pins
4 RESETPIN.. Pin no 9 is the reset pin of this ic.. It is an active high pin.On applying a high pulse to this pin, the micro controller will reset and
terminate all activities. This is often referred to as a power on reset. The high
pulse mustbe high for a minimum of 2 machine cycles before it is allowed to go low.
5. PORT0 Port 0 occupies a total of 8 pins. Pin no 32 to pin no 39. It can beused for input or output. We connect all the pins of the port 0 with the pullup
resistor (10 k ohm) externally. This is due to fact that port 0 is an open drain
mode. It is just like a open collector transistor.
6. PORT1. ALL the ports in micrcontroller is 8 bit wide pin no 1 to pin no 8because it is a 8 bit controller. All the main register and sfr all is mainly 8 bitwide. Port 1 is also occupies a 8 pins. But there is no need of pull up resistor
in this port. Upon reset port 1 act as a input port. Upon reset all the ports act
as a input port
38
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
39/103
7. PORT2. port 2 also have a 8 pins. It can be used as a input or output.There is no need of any pull up resistor to this pin.
PORT 3. Port3 occupies a totoal 8 pins from pin no 10 to pin no 17. It can
be used as input or output. Port 3 does not require any pull up resistor. Thesame as port 1 and port2. Port 3 is configured as an output port on reset. Port3 has the additional function of providing some important signals such asinterrupts. Port 3 also use for serial communication.
ALE ALE is an output pin and is active high. When connecting an 8031 to externalmemory, port 0 provides both address and data. In other words, the 8031 multiplexes
address and data through port 0 to save pins. The ALE pin is used for demultiplexing theaddress and data by connecting to the ic 74ls373 chip.
PSEN. PSEN stands for program store eneable. In an 8031 based system in which anexternal rom holds the program code, this pin is connected to the OE pin of the rom.
EA. EA. In 89c51 8751 or any other family member of the ateml 89c51 series all comewith on-chip rom to store programs, in such cases the EA pin is connected to the Vcc.
For family member 8031 and 8032 is which there is no on chip rom, code is stored inexternal memory and this is fetched by 8031. In that case EA pin must be connected to
GND pin to indicate that the code is stored externally.
39
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
40/103
SPECIAL FUNCTION REGISTER ( SFR) ADDRESSES.
ACC ACCUMULATOR 0E0H
B B REGISTER 0F0H
PSW PROGRAM STATUS WORD 0D0H
SP STACK POINTER 81H
DPTR DATA POINTER 2 BYTES
DPL LOW BYTE OF DPTR 82H
DPH HIGH BYTE OF DPTR 83H
P0 PORT0 80H
P1 PORT1 90H
P2 PORT2 0A0H
P3 PORT3 0B0H
TMOD TIMER/COUNTER MODE CONTROL 89H
TCON TIMER COUNTER CONTROL 88H
TH0 TIMER 0 HIGH BYTE 8CH
TLO TIMER 0 LOW BYTE 8AH
TH1 TIMER 1 HIGH BYTE 8DH
TL1 TIMER 1 LOW BYTE 8BH
SCON SERIAL CONTROL 98H
SBUF SERIAL DATA BUFFER 99H
PCON POWER CONTROL 87H
INSTRUCTIONS
40
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
41/103
SINGLE BIT INSTRUCTIONS.
SETB BIT SET THE BIT =1
CLR BIT CLEAR THE BIT =0
CPL BIT COMPLIMENT THE BIT 0 =1, 1=0
JB BIT,TARGET JUMP TO TARGET IF BIT =1
JNB BIT, TARGET JUMP TO TARGET IF BIT =0
JBC BIT,TARGET JUMP TO TARGET IF BIT =1 &THEN CLEAR THE BIT
MOV INSTRUCTIONS
MOV instruction simply copy the data from one location to another location
MOV D,S
Copy the data from(S) source to D(destination)
MOV R0,A ; Copy contents of A into Register R0
MOV R1,A ; Copy contents of A into register R1
MOV A,R3 ; copy contents of Register R3 into Accnmulator.
DIRECT LOADING THROUGH MOV
MOV A,#23H ; Direct load the value of 23h in A
MOV R0,#12h ; direct load the value of 12h in R0
MOV R5,#0F9H ; Load the F9 value in the Register R5
ADD INSTRUCTIONS.
41
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
42/103
ADD instructions adds the source byte to the accumulator ( A) and place the result in the
Accumulator.
MOV A, #25H
ADD A,#42H ; BY this instructions we add the value 42h in Accumulator
( 42H+ 25H)
ADDA,R3 ;By this instructions we move the data from register r3 to
accumulator and then add the contents of the register into
accumulator .
SUBROUTINE CALL FUNCTION.
ACALL,TARGET ADDRESS
By this instructions we call subroutines with a target address within 2k bytes from the
current program counter.
LCALL, TARGET ADDRESS.
ACALL is a limit for the 2 k byte program counter, but for upto 64k byte we use
LCALL instructions.. Note that LCALL is a 3 byte instructions.ACALL is a two byte instructions.
AJMP TARGET ADDRESS.
This is for absolute jump
AJMPstand for absolute jump. It transfers program execution to the target address
unconditionally. The target address for this instruction must be
withib 2 k byte of program memory.
LJMP is also for absoltute jump. It tranfer program execution to the target addres
unconditionally. This is a 3 byte instructions LJMP jump to anyaddress within 64 k byte location.
42
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
43/103
INSTRUCTIONS RELATED TO THE CARRY
JC TARGET
JUMP TO THE TARGET IF CY FLAG =1
JNC TARGET
JUMP TO THE TARGET ADDRESS IF CY FLAG IS = 0
INSTRUCTIONS RELASTED TO JUMP WITHACCUMULATOR
JZ TARGET
JUMP TO TARGET IF A = 0
JNZ TARGET
JUMP IF ACCUMULATOR IS NOT ZERO
This instructions jumps if registe A has a value other than zero
INSTRUCTIONS RELATED TO THE ROTATE
43
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
44/103
RL A
ROTATE LEFT THE ACCUMULATOR
BY this instructions we rotate the bits of A left. The bits rotated out of A arerotated back into A at the opposite end
RR A
By this instruction we rotate the contents of the accumulator from right to
left from LSB to MSB
RRC A
This is same as RR A but difference is that the bit rotated out of register first
enter in to carry and then enter into MSB
RLC A
ROTATE A LEFT THROUGH CARRY
Same as above but but shift the data from MSB to carry and carry to LSB
RET
This is return from subroutine. This instructions is used to return from a
subroutine previously entered by instructions LCALL and ACALL.
44
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
45/103
RET1
THIS is used at the end of an interrupt service routine. We use this
instructions after intruupt routine,
PUSH.
This copies the indicated byte onto the stack and increments SP by . This
instructions supports only direct addressing mode.
POP.
POP FROM STACK.
This copies the byte pointed to be SP to the location whose direct address is
indicated, and decrements SP by 1. Notice that this instructions supports
only direct addressing mode.
DPTR INSTRUCTIONS.
MOV DPTR,#16 BIT VALUE
LOAD DATA POINTER
This instructions load the 16 bit dptr register with a 16 bit immediate value
MOV C A,@A+DPTR
This instructions moves a byte of data located in program ROM into register
A. This allows us to put strings of data, such as look up table elements.
45
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
46/103
MOVC A,@A+PC
This instructions moves a byte of data located in the program area to A. the address of thedesired byte of data is formed by adding the program counter ( PC) register to the original
value of the accumulator.
INC BYTE
This instructions add 1 to the register or memory location specified by the
operand.
INC A
INC Rn
INC DIRECT
DEC BYTE
This instructions subtracts 1 from the byte operand. Note that CY is
unchanged
DEC A
DEC Rn
DEC DIRECT
ARITHMATIC INSTRUCTIONS.
ANL dest-byte, source-byte
This perform a logical AND operation
This performs a logical AND on the operands, bit by bit, storing the result in
the destination. Notice that both the source and destination values are byte
size only
46
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
47/103
`
DIV AB
This instructions divides a byte accumulator by the byte in register B. It is
assumed that both register A and B contain an unsigned byte. After the
division the quotient will be in register A and the remainder in register B.
TMOD ( TIMER MODE ) REGISTER
Both timer is the 89c51 share the one register TMOD. 4 LSB bit for the timer 0 and 4MSB for the timer 1.
In each case lower 2 bits set the mode of the timer
Upper two bits set the operations.
GATE: Gating control when set. Timer/counter is enabled only while the INTXpin is high and the TRx control pin is set. When cleared, the timer is enabled wheneverthe TRx control bit is set
C/T : Timer or counter selected cleared for timer operation ( input from internalsystem clock)
M1 Mode bit 1
M0 Mode bit 0
M1 M0 MODE OPERATING MODE
47
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
48/103
0 0 0 13 BIT TIMER/MODE
0 1 1 16 BIT TIMER MODE
1 0 2 8 BIT AUTO RELOAD
1 1 3 SPLIT TIMER MODE
PSW ( PROGRAM STATUS WORD)
CY PSW.7 CARRY FLAG
AC PSW.6 AUXILIARY CARRY
F0 PSW.5 AVAILABLE FOR THE USER FRO GENERAL PURPOSE
RS1 PSW.4 REGISTER BANK SELECTOR BIT 1
RS0 PSW.3 REGISTER BANK SELECTOR BIT 0
0V PSW.2 OVERFLOW FLAG
-- PSW.1 USER DEFINABLE BIT
P PSW.0 PARITY FLAG SET/CLEARED BY HARDWARE
PCON REGISATER ( NON BIT ADDRESSABLE)
If the SMOD = 0 ( DEFAULT ON RESET)
48
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
49/103
TH1 = CRYSTAL FREQUENCY
256---- ____________________
384 X BAUD RATE
If the SMOD IS = 1 CRYSTAL FREQUENCY
TH1 = 256--------------------------------------
192 X BAUD RATE
There are two ways to increase the baud rate of data transfer in the 8051
1. To use a higher frequency crystal
2. To change a bit in the PCON register
PCON register is an 8 bit register . Of the 8 bits, some are unused, and some are used forthe power control capability of the 8051. the bit which is used for the serial
communication is D7, the SMOD bit. When the 8051 is powered up, D7 ( SMOD BIT)
OF PCON register is zero. We can set it to high by software and thereby double the
baud rate
BAUD RATE COMPARISION FOR SMOD = 0 AND SMOD =1
TH1 ( DECIMAL) HEX SMOD =0 SMOD =1
-3 FD 9600 19200
-6 FA 4800 9600
-12 F4 2400 4800
-24 E8 1200 2400
XTAL = 11.0592 MHZ
IE ( INTERRUPT ENABLE REGISTOR)
49
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
50/103
EA IE.7 Disable all interrupts if EA = 0, no interrupts is acknowledgedIf EA is 1, each interrupt source is individually enabled or disbaledBy sending or clearing its enable bit.
IE.6 NOT implemented
ET2 IE.5 enables or disables timer 2 overflag in 89c52 only
ES IE.4 Enables or disables all serial interrupt
ET1 IE.3 Enables or Disables timer 1 overflow interrupt
EX1 IE.2 Enables or disables external interrupt
ET0 IE.1 Enables or Disbales timer 0 interrupt.
EX0 IE.0 Enables or Disables external interrupt 0
INTERRUPT PRIORITY REGISTER
If the bit is 0, the corresponding interrupt has a lower priority and if the bit is 1 thecorresponding interrupt has a higher priority
IP.7 NOT IMPLEMENTED, RESERVED FOR FUTURE USE.
IP.6 NOT IMPLEMENTED, RESERVED FOR FUTURE USE
PT2 IP.5 DEFINE THE TIMER 2 INTERRUPT PRIORITY LELVEL
50
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
51/103
PS IP.4 DEFINES THE SERIAL PORT INTERRUPT PRIORITY LEVEL
PT1 IP.3 DEFINES THE TIMER 1 INTERRUPT PRIORITY LEVEL
PX1 IP.2 DEFINES EXTERNAL INTERRUPT 1 PRIORITY LEVEL
PT0 IP.1 DEFINES THE TIMER 0 INTERRUPT PRIORITY LEVEL
PX0 IP.0 DEFINES THE EXTERNAL INTERRUPT 0 PRIORITY LEVEL
SCON: SERIAL PORT CONTROL REGISTER , BIT ADDRESSABLE
SCON
SM0 : SCON.7 Serial Port mode specifier
SM1 : SCON.6 Serial Port mode specifier
SM2 : SCON.5
REN : SCON.4 Set/cleared by the software to Enable/disable reception
TB8 : SCON.3 The 9th bit that will be transmitted in modes 2 and 3, Set/clearedBy software
51
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
52/103
RB8 : SCON.2 In modes 2 &3, is the 9th data bit that was received. In mode 1,If SM2 = 0, RB8 is the stop bit that was received. In mode 0RB8 is not used
T1 : SCON.1 Transmit interrupt flag. Set by hardware at the end of the 8th
bitTime in mode 0, or at the beginning of the stop bit in the otherModes. Must be cleared by software
R1 SCON.0 Receive interrupt flag. Set by hardware at the end of the 8th bitTime in mode 0, or halfway through the stop bit time in the otherModes. Must be cleared by the software.
TCON TIMER COUNTER CONTROL REGISTER
This is a bit addressable
TF1 TCON.7 Timer 1 overflow flag. Set by hardware when the Timer/Counter 1Overflows. Cleared by hardware as processor
TR1 TCON.6 Timer 1 run control bit. Set/cleared by software to turn TimerCounter 1 On/off
TF0 TCON.5 Timer 0 overflow flag. Set by hardware when the timer/counter 0
Overflows. Cleared by hardware as processor
TR0 TCON.4 Timer 0 run control bit. Set/cleared by software to turn timerCounter 0 on/off.
IE1 TCON.3 External interrupt 1 edge flag
ITI TCON.2 Interrupt 1 type control bit
52
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
53/103
IE0 TCON.1 External interrupt 0 edge
IT0 TCON.0 Interrupt 0 type control bit.
- 8051 Instruction Set
Arithmetic Operations
Mnemonic Description Size Cycles
ADD A,Rn Add register to Accumulator (ACC). 1 1
ADD A,direct Add direct byte to ACC. 2 1
ADD A,@Ri Add indirect RAM to ACC . 1 1
ADD A,#data Add immediate data to ACC . 2 1
ADDC A,Rn Add register to ACC with carry . 1 1
ADDC A,direct Add direct byte to ACC with carry. 2 1
ADDC A,@Ri Add indirect RAM to ACC with carry. 1 1
ADDC A,#data Add immediate data to ACC with carry. 2 1
SUBB A,Rn Subtract register from ACC with borrow. 1 1
SUBB A,direct Subtract direct byte from ACC with borrow 2 1
SUBB A,@Ri Subtract indirect RAM from ACC with borrow. 1 1
SUBB A,#data Subtract immediate data from ACC with borrow. 2 1
INC A Increment ACC. 1 1
INC Rn Increment register. 1 1
INC direct Increment direct byte. 2 1
INC @Ri Increment indirect RAM. 1 1
DEC A Decrement ACC. 1 1
53
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
54/103
DEC Rn Decrement register. 1 1
DEC direct Decrement direct byte. 2 1
DEC @Ri Decrement indirect RAM. 1 1
INC DPTR Increment data pointer. 1 2
MUL AB Multiply A and B Result: A
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
55/103
XRL A,direct Exclusive OR direct byte to ACC. 2 1
XRL A,@Ri Exclusive OR indirect RAM to ACC. 1 1
XRL A,#data Exclusive OR immediate data to ACC. 2 1
XRL direct,A Exclusive OR ACC to direct byte. 2 1
XRL direct,#data XOR immediate data to direct byte. 3 2
CLR A Clear ACC (set all bits to zero). 1 1
CPL A Compliment ACC. 1 1
RL A Rotate ACC left. 1 1
RLC A Rotate ACC left through carry. 1 1
RR A Rotate ACC right. 1 1
RRC A Rotate ACC right through carry. 1 1
SWAP A Swap nibbles within ACC. 1 1
Data Transfer
Mnemonic Description Size Cycles
MOV A,Rn Move register to ACC. 1 1
MOV A,direct Move direct byte to ACC.2 1
MOV A,@Ri Move indirect RAM to ACC. 1 1
MOV A,#data Move immediate data to ACC. 2 1
MOV Rn,A Move ACC to register. 1 1
MOV Rn,direct Move direct byte to register. 2 2
MOV Rn,#data Move immediate data to register. 2 1
55
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
56/103
MOV direct,A Move ACC to direct byte. 2 1
MOV direct,Rn Move register to direct byte. 2 2
MOV direct,direct Move direct byte to direct byte. 3 2
MOV direct,@Ri Move indirect RAM to direct byte. 2 2
MOV direct,#data Move immediate data to direct byte. 3 2
MOV @Ri,A Move ACC to indirect RAM. 1 1
MOV @Ri,direct Move direct byte to indirect RAM. 2 2
MOV @Ri,#data Move immediate data to indirect RAM. 2 1
MOV DPTR,#data16 Move immediate 16 bit data to data pointer register. 3 2
MOVC A,@A+DPTR Move code byte relative to DPTR to ACC (16 bit address).1 2
MOVC A,@A+PC Move code byte relative to PC to ACC (16 bit address).1 2
MOVX A,@Ri Move external RAM to ACC (8 bit address). 1 2
MOVX A,@DPTR Move external RAM to ACC (16 bit address). 1 2
MOVX @Ri,A Move ACC to external RAM (8 bit address). 1 2
MOVX @DPTR,A Move ACC to external RAM (16 bit address). 1 2
PUSH direct Push direct byte onto stack. 2 2
POP direct Pop direct byte from stack. 2 2
XCH A,Rn Exchange register with ACC. 1 1
XCH A,direct Exchange direct byte with ACC. 2 1
XCH A,@Ri Exchange indirect RAM with ACC. 1 1
XCHD A,@Ri Exchange low order nibble of indirectRAM with low order nibble of ACC 1 1
Boolean Variable Manipulation
56
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
57/103
Mnemonic Description Size Cycles
CLR C Clear carry flag. 1 1
CLR bit Clear direct bit. 2 1
SETB C Set carry flag. 1 1
SETB bitSet direct bit 2 1
CPL C Compliment carry flag. 1 1
CPL bit Compliment direct bit. 2 1
ANL C,bit AND direct bit to carry flag. 2 2
ANL C,/bit AND compliment of direct bit to carry. 2 2
ORL C,bit OR direct bit to carry flag. 2 2
ORL C,/bit OR compliment of direct bit to carry. 2 2
MOV C,bit Move direct bit to carry flag. 2 1
MOV bit,C Move carry to direct bit. 2 2
JC rel Jump if carry is set. 2 2
JNC rel Jump if carry is not set. 2 2
JB bit,rel Jump if direct bit is set. 3 2
JNB bit,rel Jump if direct bit is not set. 3 2
JBC bit,rel Jump if direct bit is set & clear bit. 3 2
Program BranchingMnemonic Description Size Cycles
ACALL addr11 Absolute subroutine call. 2 2
LCALL addr16 Long subroutine call. 3 2
57
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
58/103
RET Return from subroutine. 1 2
RETI Return from interrupt. 1 2
AJMP addr11 Absolute jump. 2 2
LJMP addr16 Long jump. 3 2
SJMP rel Short jump (relative address). 2 2
JMP @A+DPTR Jump indirect relative to the DPTR. 1 2
JZ rel Jump relative if ACC is zero. 2 2
JNZ rel Jump relative if ACC is not zero. 2 2
CJNE A,direct,rel Compare direct byte to ACC and jump if not equal. 3 2
CJNE A,#data,rel Compare immediate byte to ACC and jump if not equal.3 2
CJNE Rn,#data,rel Compare immediate byte to register and jump if not equal.32
CJNE @Ri,#data,rel Compare immediate byte to indirect and jump if not equal.32
DJNZ Rn,rel Decrement register and jump if not zero. 2 2
DJNZ direct,rel Decrement direct byte and jump if not zero. 3 2
The RW line is the "Read/Write" control line. When RW is low (0), the information on
I
58
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
59/103
HOW TO PROGRAM BLANKCHIP.
8051 micro controller
The 8051
The 8051 developed and launched in the early 80`s, is one of the mostpopular micro controller in use today. It has a reasonably large amount ofbuilt in ROM and RAM. In addition it has the ability to access external
memory.
The generic term `8x51` is used to define the device. The value of x definingthe kind of ROM, i.e. x=0, indicates none, x=3, indicates mask ROM, x=7,indicates EPROM and x=9 indicates EEPROM or Flash.
Different micro controllers in market.
PIC One of the famous microcontrollers used in the
industries. It is based on RISC Architecture which makes themicrocontroller process faster than other microcontroller.
INTEL These are the first to manufacture
microcontrollers. These are not as sophisticated other microcontrollersbut still the easiest one to learn.
ATMEL Atmels AVR microcontrollers are one of the most
powerful in the embedded industry. This is the only microcontrollerhaving 1kb of ram even the entry stage. But it is unfortunate that inIndia we are unable to find this kind of microcontroller.
59
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
60/103
Intel 8051
Intel 8051 is CISC architecture which is easy to program in assemblylanguage and also has a good support for High level languages.
The memory of the microcontroller can be extended up to 64k.
This microcontroller is one of the easiest microcontrollers to learn.
The 8051 microcontroller is in the field for more than 20 years. There arelots of books and study materials are readily available for 8051.
First of all we select and open the assembler and wrote a program code in
the file. After wrote a software we assemble the software by using internal
assembler of the 8051 editor. If there is no error then assembler assemble
the software abd 0 error is show the output window.
60
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
61/103
now assembler generate a ASM file and HEX file. This hex file is useful for
us to program the blank chip.
Now we transfer the hex code into the blank chip with the help of serial
programmer kit. In the programmer we insert a blank chip 0f 89s51 series .
these chips are multi time programmable chip. This programming kit is
seperatally available in the market and we transfer the hex code into blank
chip with the help of the serial programmer kit
61
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
62/103
62
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
63/103
63
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
64/103
64
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
65/103
NOTES ONLCD
LCD DETAIL .
Frequently, an 8051 program must interact with the outside world using input and output
devices that communicate directly with a human being. One of the most common devices
attached to an 8051 is an LCD display. Some of the most common LCDs connected to
the 8051 are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20
characters per line by 2 lines, respectively.
65
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
66/103
HD44780U, which refers to the controller chip which receives data from an external
source (in this case, the 8051) and communicates directly with the LCD.
44780 BACKGROUND
AN EXAMPLE HARDWARE CONFIGURATION
DB0 EQU P1.0
DB1 EQU P1.1
DB2 EQU P1.2
DB3 EQU P1.3
DB4 EQU P1.4
DB5 EQU P1.5
DB6 EQU P1.6
DB7 EQU P1.7
EN EQU P3.7
RS EQU P3.6
RW EQU P3.5
DATA EQU P1Having established the above equates, we may now refer to our I/O lines by their 44780
name. For example, to set the RW line high (1), we can execute the following insutrction:
SETB RW
HANDLING THE EN CONTROL LINE
with the following instruction:
SETB EN
And once we've finished setting up our instruction with the other control lines and data
bus lines, we'll always bring this line back low:
CLR EN
66
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
67/103
Programming Tip: The LCD interprets and executes our command at the instant
the EN line is brought low. If you never bring EN low, your instruction will never
be executed. Additionally, when you bring EN low and the LCD executes your
instruction, it requires a certain amount of time to execute the command. The time
it requires to execute an instruction depends on the instruction and the speed of
the crystal which is attached to the 44780's oscillator input.
CHECKING THE BUSY STATUS OF THE LCD
As previously mentioned, it takes a certain amount of time for each instruction to be
executed by the LCD. The delay varies depending on the frequency of the we will usethis code every time we send an instruction to
WAIT_LCD:
SETB EN ;Start LCD command
CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET
Thus, our standard practice will be to send an instruction to the LCD and then call our
WAIT_LCD routine to wait until the instruction is completely executed by the LCD.
This will assure that our program gives the LCD the time it needs to execute instructions
and also makes our program compatible with any LCD, regardless of how fast or slow it
is.
Programming Tip: The above routine does the job of waiting for the LCD, but
were it to be used in a real application a very definite improvement would need to
be made: as written, if the LCD never becomes "not busy" the program will
67
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
68/103
effectively "hang," waiting for DB7 to go low. If this never happens, the program
will freeze. Of course, this should never happen and won't happen when the
hardware is working properly. But in a real application it would be wise to put
some kind of time limit on the delay--for example, a maximum of 256 attempts to
wait for the busy signal to go low. This would guarantee that even if the LCD
hardware fails, the program would not lock up.
INITIALIZING THE LCD
SETB ENCLR RSMOV DATA,#38hCLR ENLCALL WAIT_LCD
Programming Tip: The LCD command 38h is really the sum of a number of
option bits. The instruction itself is the instruction 20h ("Function set"). However,
to this we add the values 10h to indicate an 8-bit data bus plus 08h to indicate that
the display is a two-line display.
We've now sent the first byte of the initialization sequence. The second byte of the
initialization sequence is the instruction 0Eh. Thus we must repeat the initialization code
from above, but now with the instruction. Thus the next code segment is:
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
68
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
69/103
Programming Tip: The command 0Eh is really the instruction 08h plus 04h to
turn the LCD on. To that an additional 02h is added in order to turn the cursor on.
The last byte we need to send is used to configure additional operational parameters of
the LCD. We must send the value 06h.
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 06h is really the instruction 04h plus 02h to
configure the LCD such that every time we send it a character, the cursor position
automatically moves to the right.
So, in all, our initialization code is as follows:
INIT_LCD:
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
RET
69
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
70/103
Having executed this code the LCD will be fully initialized and ready for us to send
display data to it.
CLEARING THE DISPLAY
When the LCD is first initialized, the screen should automatically be cleared by the 447e,
it's a good idea to make it a subroutine:
CLEAR_LCD:
SETB EN
CLR RS
MOV DATA,#01h
CLR EN
LCALL WAIT_LCD
RET
How that we've written a "Clear Screen" routine, we may clear the LCD at any time by
simply executing an LCALL CLEAR_LCD.
Programming Tip: Executing the "Clear Screen" instruction on the LCD also
positions the cursor in the upper left-hand corner as we would expect.
WRITING TEXT TO THE LCD
Now we get to the real meat of what we're trying to do: All this effort is really so we can
display text on the LCD. Really, we're pretty much done.
Once again, writing text to the LCD is something we'll almost certainly want to do over
and over--so let's make it a subroutine.
WRITE_TEXT:
SETB EN
SETB RS
MOV DATA,A
CLR EN
70
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
71/103
LCALL WAIT_LCD
RET
The WRITE_TEXT routine that we just wrote will send the character in the accumulator
to the LCD which will, in turn, display it. Thus to display text on the LCD all we need to
do is load the accumulator with the byte to display and make a call to this routine. Pretty
easy, huh?
A "HELLO WORLD" PROGRAM
Now that we have
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
71
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
72/103
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
The above "Hello World" program should, when executed, initialize the LCD, clear the
LCD screen, and display "Hello World" in the upper left-hand corner of the display.
CURSOR POSITIONING
The
Thus, the
SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
The above code will position the cursor on line 2, character 10. To display "Hello" in the
upper left-hand corner with the word "World" on the second line at character position 10
just requires us to insert the above code into our existing "Hello World" program. This
results in the following:
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
72
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
73/103
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
PIN WISE DETAIL OF LCD
1. Vss GROUND
2. Vcc +5VOLT SUPPLY
3 Vee POWER SUPPLY TO CONTROL CONTRAST
4. RS RS = 0 TO SELECT COMMAND REGISTER RS = 1 TO SELECT DATA REGISTER
5. R/W R/W = 0 FOR WRITER/W = 1 FOR READ
73
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
74/103
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
75/103
F. DISPLAY ON CURSOR BLINKING.
10. SHIFT CURSOR POSITION TO LEFT
14. SHIFT CURSOR POSITION TO RIGHT
18. SHIFT THE ENTIRE DISPLAY TO THE LEFT
1C SHIFT THE ENTIRE DISPLAY TO THE RIGHT
80 FORCE CURSOR TO BEGINNING OF IST LINE
C0 FORCE CURSOR TO BEGINNING OF 2ND LINE
38 2 LINES AND 5 X 7 MATRIX
75
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
76/103
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
77/103
org 000bh
reti
org 0013h
reti
org 001bh
reti
org 0023h
reti
da
a
mov pulse_cont0_hi,a
mov a,pulse_cont0_hi
cjne a,#10h,inte0_end
mov pulse_cont0_lo,#00h
mov pulse_cont0_hi,#00h
inte0_end:
mov a,pulse_cont0_lo
mov 1ah,a
77
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
78/103
mov 1bh,#0d
lcall DELAY_RM
LCALL write
mov a,pulse_cont0_hi
mov 1ah,a
mov 1bh,#1d
lcall DELAY_RM
LCALL write
setb ex0
pop acc
pop psw
reti
TIMER_0:
push psw
push acc
clr tr0
mov tl0,#0b2h
mov th0,#06Ch
mov a,cont
add a,#01h
78
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
79/103
mov cont,a
cjne a,#20d,TIMER_NXT
mov cont,#0d
clr flag1
da
a
mov pulse_cont1_lo,a
mov a,pulse_cont1_hi
addc a,#0d
da
a
mov pulse_cont1_hi,a
mov a,pulse_cont1_hi
cjne a,#10h,inte1_end
mov pulse_cont1_lo,#00h
mov pulse_cont1_hi,#00h
inte1_end:
mov a,pulse_cont1_lo
mov 1ah,a
mov 1bh,#2d
79
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
80/103
lcall DELAY_RM
LCALL write
mov a,pulse_cont1_hi
mov 1ah,a
mov 1bh,#3d
lcall DELAY_RM
LCALL write
setb ex1
pop acc
pop psw
reti
main:
mov psw,#00h
mov sp,#070h
mov tmod,#21h
mov tcon,#05h
mov scon,#50h
anl pcon,#7fh
mov ie,#00h
mov ip,#00h
80
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
81/103
mov tl1,#0fdh
mov th1,#0fdh
mov tl0,#0b0h
mov th0,#03ch
mov p0,#0ffh
mov p1,#0ffh
mov p2,#0ffh
mov p3,#0ffh
mov pulse_cont0_lo,#00h
mov pulse_cont0_hi,#00h
mov pulse_cont1_lo,#00h
mov pulse_cont1_hi,#00h
clr lcd_rs
clr lcd_rw
clr lcd_en
lcall INIT_LCD
lcall CLR_LCD
lcall
data_cheke
mov dptr,#MSG0
81
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
82/103
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
83/103
lcall
DELAY
mov a,pulse_cont0_hi
anl a,#0fh
ADD a,#30h
lcall
TRANS
lcall
DELAY
mov a,pulse_cont0_lo
anl a,#0fh
ADD a,#30h
lcall
TRANS
lcall
DELAY
mov a,pulse_cont0_lo
anl a,#0fh
ADD a,#30h
83
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
84/103
lcall
TRANS
lcall
DELAY
mov a,pulse_cont1_hi
anl a,#0fh
ADD a,#30h
lcall
TRANS
lcall
DELAY
mov a,pulse_cont1_lo
anl a,#0fh
lcall
TRANS
lcall
DELAY
mov a,pulse_cont1_lo
anl a,#0fh
ADD a,#30h
84
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
85/103
lcall
TRANS
lcall
DELAY
mov
a,#13d
lcall
TRANS
lcall
DELAY
ljmp wait
display:
mov LCD_DATA,#08dh
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont0_hi
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
85
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
86/103
lcall DELAY41
mov LCD_DATA,#08eh
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont0_lo
swap a
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
lcall DELAY41
mov LCD_DATA,#08fh
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont0_lo
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
lcall DELAY41
86
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
87/103
mov LCD_DATA,#0cdh
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont1_hi
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
lcall DELAY41
mov LCD_DATA,#0ceh
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont1_lo
swap a
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
lcall DELAY41
mov LCD_DATA,#0cfh
87
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
88/103
lcall COMMAND_BYTE
lcall DELAY41
mov a,pulse_cont1_lo
anl a,#0fh
ADD a,#30h
mov LCD_DATA,a
lcall DATA_BYTE
lcall DELAY41
ret
TRANS:
mov
sbuf,a
jnb ti
lcall
ELAY_RM
ret
LINE_1:
88
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
89/103
mov LCD_DATA,#080h
lcall COMMAND_BYTE
lcall DELAY41
lcall WRITE_MSG
ret
LINE_2:
mov LCD_DATA,#0c0h
lcall COMMAND_BYTE
lcall DELAY41
lcall WRITE_MSG
ret
INIT_LCD:
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY41
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY41
mov LCD_DATA,#038h
lcall COMMAND_BYTE
89
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
90/103
lcall DELAY41
mov LCD_DATA,#038h
lcall COMMAND_BYTE
lcall DELAY41
mov LCD_DATA,#008h
lcall COMMAND_BYTE
lcall DELAY41
mov LCD_DATA,#00ch
lcall COMMAND_BYTE
lcall DELAY41
mov LCD_DATA,#006h
lcall COMMAND_BYTE
lcall DELAY41
ret
CLR_LCD:
mov LCD_DATA,#001h
lcall COMMAND_BYTE
lcall DELAY41
ret
WRITE_MSG:
90
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
91/103
mov a,#00h
movc a,@a+dptr
cjne a,#'$',WRITE_CONT
ret
WRITE_CONT:
mov LCD_DATA,a
lcall DATA_BYTE
ljmp WRITE_MSG
COMMAND_BYTE:
clr lcd_rs
lcall DELAY
ljmp CMD10
DATA_BYTE:
setb lcd_rs
lcall DELAY
CMD10:
clr lcd_rw
lcall DELAY
91
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
92/103
setb lcd_en
lcall DELAY
clr lcd_en
lcall DELAY
ret
DELAY:
mov r0,#10d
DEL:
djnz r0,DEL
ret
DELAY1:
mov r0,#0d
mov r1,#0d
DEL1:
djnz r0,DEL1
djnz r1,DEL1
ret
DELAY_RM:
mov r0,#0d
mov r1,#5d
92
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
93/103
DEL_RM:
djnz r0,DEL_RM
djnz r1,DEL_RM
ret
DELAY10:
mov r0,#0d
mov r1,#0d
mov r2,#10d
DEL10:
djnz r0,DEL10
djnz r1,DEL10
djnz r2,DEL10
ret
DELAY41:
mov r0,#0d
mov r1,#15d
DLP410:
djnz r0,DLP410
djnz r1,DLP410
ret
93
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
94/103
data_cheke:
mov 1bh,#4d
lcall DELAY_RM
lcall read
mov
a,19h
cjne
a,#0d,data_chanj
ljmp
data_load_eeprom
data_chanj:
mov
1ah,#0d
mov
1bh,#0d
lcall DELAY_RM
LCALL write
mov
1ah,#0d
94
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
95/103
mov
1bh,#1d
lcall DELAY_RM
LCALL write
mov
1ah,#0d
mov
1bh,#2d
lcall DELAY_RM
LCALL write
mov
1ah,#0d
mov
1bh,#3d
lcall DELAY_RM
LCALL write
mov
1ah,#0d
mov
1bh,#4d
95
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
96/103
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
97/103
ret
;;;;;;;;;;;;; for 24c04 ;;;;;;;;;;;;;;;
read: PUSH B
MOV B, A
ACALL START
JC NOBUS
MOV A, #00H
ORL A, #0A0H
ACALL SHOUT
JC XR1
MOV A,1bh
ACALL SHOUT
JC XR1
MOV A, B
lCALL R_CRNT
lJMP XR2
XR1: lCALL STOP
NOBUS: SETB 1
XR2:
MOV 19h, A
97
-
7/28/2019 Wireless Energy Meter Data Logger on Pc
98/103
POP B
RET
STAR