Prepaid Energy Meter

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 131

INTODUCTION

GSM modem 8051 microcontroller

Energy meter

FIG.1. BLOCK DIAGRAM OF PRE PAID ENERGY METER


The aim of this project is to design a prepaid energy meter to monitor the consumption of electricity in domestic needs. The standard business model of electricity retailing involves the electricity company billing the customer for the amount of energy used in the previous month or quarter. In some countries, if the retailer believes that the customer may not pay the bill for what ever reason a prepayment meter may be installed. This requires the customer to make advance payment before using the electricity. If the available credit is exhausted then the supply of electricity is automatically cut off by a relay. Here analog energy meter is replaced by a digital energy meter. The digital energy meter used here is a high accuracy, low cost, single phase power meter based on the ADE7757.The meter is designed for use in single phase 2 wire distribution system. A relay is connected in between power lines and the load. The relay is controlled by the primary controller. Microcontroller 89C51 acts as the primary controller. The primary controller collects information from digital energy meter as well as from the smart card. Smart gives information about the limitation of units. The digital energy meter reading is compared with the smart card information by the primary controller and hence suitably primary controller controls the relay.

CIRCUIT DIAGRAM:-

FIG. 02.BLOCK DIAGRAM

COMPONENTS DESCRIPTION:1. I.C.S:(A.) AT89S52:-

FIG. 03.I.C.AT89S52
Description:-

The ISL8200MMREP is a simple and easy to use high power, current-sharing DC\DC power module for Datacom\Telecom\FPGA power hungry applications. All that is needed is the ISL8200MMREP, a few passive components and one VOUT setting resistor to have a complete 10A design ready for market.The ease of use virtually eliminates the design and manufacturing risks while dramatically improving time to market.Need more output current? Just simply parallel up to six ISL8200MMREP modules to scale up to a 60A solution.The simplicity of the ISL8200MMREP is in its Off The Shelf, unassisted implementation. Patented current sharing in multi-phase operation greatly reduces ripple currents, BOM cost andcomplexity. The ISL8200MMREPs thermally enhanced, compact QFN package, operates at full load and over-temperature, without requiring forced air cooling. It's so thin it can even fit on the back side of the PCB. Easy access to all pins with few external components, reduces the PCB design to a component layer and a simple ground layer.

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8Kbytes of in-system programmable Flash memory. The device is manufactured usingAtmels high3

density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip Flash allows the programmemory to be reprogrammed in-system or by a conventional nonvolatile memory programmer.By combining a versatile 8bit CPU with in-system programmable Flash ona monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides ahighly-flexible and cost-effective solution to many embedded control applications.The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytesof RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, asix-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator,and clock circuitry. In addition, the AT89S52 is designed with static logic for operationdown to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, andinterrupt system to continue functioning. The Power-down mode saves the RAM contentsbut freezes the oscillator, disabling all other chip functions until the next interruptor hardware reset.

Pin Description:Pin Description

Pin Number 1-8 9 10 - 17 18 19 20 21 - 28 29 30 31 32 - 39 40

Description P1.0 - P1.7 - Port 1 RST - Reset P3.0 - P3.7 - Port 3 XTAL2 - Crystal XTAL1 - Crystal GND - Ground P2.0 - P2.7 - Port 2 PSEN - Program Store Enable ALE - Address Latch Enable EA - External Access Enable P0.7 - P0.1 - Port 0 Vcc - Positive Power Supply

TABLE 1. I.C.DESCRIPTION
4

Features:1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

Specifications per DSCC VID V62/10608 Full Mil-Temp Electrical Performance from -55C to +125C Full Traceability Through Assembly and Test by Date/Trace Code Assignment Enhanced Process Change Notification Enhanced Obsolescence Management Complete Switch Mode Power Supply in One Package Patented Current Share Architecture Reduces Layout Sensitivity When Modules are Paralleled Programmable Phase Shift (1, 2, 3, 4, and 6 phase) Extremely Low Profile (2.2mm height) Input Voltage Range +3.0 V to +20V at 10A, Current Share up to 60A A Single Resistor Sets VOUT from +0.6V to +6V

(B.) IC AT24C02:-

FIG.4
5

Description:T24C02 is an electrically erasable and programmable ROM. It has a 2Kbits of memory size arranged in 32 pages of 8 byte each. There are 256 (32 x 8) words each of one byte. The data is transferred and received serially through serial data (SDA) pin. The SCL is clock input and is used to synchronize EEPROM with microcontroller for various operations. When data is to be read or write, first a start condition is created followed by device address, byte address and the data itself. Finally a stop condition is provided. The start condition occurs when SDA and SCL get high to low simultaneously. The stop condition is when SDA remains low while SCL goes from high to low. The data is read or written between the start and stop conditions on every transition of SCL from high to low. For more details on different operations and addressing, refer interfacing 24C02 with 8051. A total of eight EEPROMs can be connected through a bus. There are three address pins in AT24C02 for selecting a particular chip. The device can be addressed serially by the software. It makes use of an internal register of the EEPROM whose 4 MSB bits are 1010, the next three are the EEPROM address bits and the LSB signifies whether data is to be read or written. This last bit is 1 for write and 0 for read operation. For example, if in an EEPROM all address bits are grounded, then for write operation a hex value 0xA1 (1010 0001) will be sent. Here 000, in last bits, addresses the EEPROM and 1 in LSB indicates a write operation. Similarly for read operation the device address to be sent is 0xA0 (1010 0000). Next, the byte or page address is sent followed by the data byte. This data byte is to be written on or read by the microcontroller.

Pin Description:-

Pin No 1 2 3 4 5 6 7 8

Function Address input pins; Provide addresses when more than one EEPROM is interfaced to a single microcontroller; Ground when only one EEPROM is used Ground (0V) Bi-directional pin for serial data transfer Provides clock signals Ground allows normal read/write functions; Vcc enables write protection Supply voltage; 5V (up to 5.5V)

Name AD0 AD1 AD2 Ground Serial Data Serial Clock Write protect Vcc

TABLE 2.
6

(C.)ULN2003:-

FIG.5.1

Description:The ULN2002A, ULN2003A, ULN2003AI, ULN2004A, ULQ2003A, and ULQ2004A are high-voltage high-current Darlington transistor arrays. Each consists of seven npn Darlington pairs that feature high-voltage outputs with common-cathode clamp diodes for switching inductive loads. The collector-current rating of a single Darlington pair is 500 mA. The Darlington pairs can be paralleled for higher current capability. Applications include relay drivers, hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers, and logic buffers.For 100-V (otherwise interchangeable) versions of the ULN2003A and ULN2004A, see the SN75468 and SN75469, respectively.The ULN2001A is a generalpurpose array and can be used with TTL and CMOS technologies.

Features:

500-mA-Rated Collector Current (Single Output) High-Voltage Outputs: 50 V Output Clamp Diodes Inputs Compatible With Various Types of Logic Relay-Driver Applications

Parametrics:Output Voltage(Max)(V) 50 Switching Voltage(Max)(V) 50 Peak Output Current(mA) 500 Drivers Per Package 7 Input Compatibility CMOS, TTL Delay Time(Typ)(ns) 250 Operating Temperature Range(C) -20 to 70 Pin/Package 16PDIP, 16SO, 16SOIC, 16TSSOP Approx. Price (US$) 0.21 | 1ku Rating Catalog TABLE 3.1
The ULN2001A, ULN2002A, ULN2003 and ULN2004A are high voltage, high current darlington arrays each containing seven open collector darlington pairs with common emitters. Each channel rated at 500mA and can withstand peak currents of 600mA. Suppression diodes are included for inductive load driving and the inputs are pinned opposite the outputs to simplify board layout. The four versions interface to all common logic families 1. ULN2001A General Purpose, DTL, TTL, PMOS, 2. CMOS 3. ULN2002A 14-25V PMOS 4. ULN2003A 5V TTL, CMOS 5. ULN2004A 615V CMOS, PMOS These versatile devices are useful for driving a wide range of loads including solenoids, relays DC motors, LED displays filament lamps, thermal printheads and high power buffers. The ULN2001A/2002A/2003A and 2004A are supplied in 16 pin plastic DIP packages with a copper leadframe to reduce thermal resistance. They are available also in small outline package (SO-16) as ULN2001D/2002D/2003D/2004D.

:-

FIG.5.1.2
10

:-

TABLE 3.1.1

11

12

ULN2003 I.C.

13

:-

FIG.5.1.4
14

FIG 5.1.5
15

16

17

(3.)RESISTOR:-

FIG. 6.1

DESCRIPTION:Resistor is a passive component used to control current in a circuit. Its resistance is given by theratio of voltage applied across its terminals to the current passing through it. Thus a particularvalue of resistor, for fixed voltage, limits the current through it. They are omnipresent in electronic circuits. The different value of resistances are used to limit the currents or get the desired voltage drop according to the current-voltage rating of the device to be connected in the circuit. For example, if an LED of rating 2.3V and 6mA is to be connected with a supply of 5V, a voltage drop of 2.7V (5V-2.3V) and limiting current of 6mA is required. This can be achieved by providing a resistor of 450 connected in series with the LED. Resistors can be either fixed or variable. The low power resistors are comparatively smaller in size than high power resistors. The resistance of a resistor can be estimated by their colour codes or can be measured by a multimeter. There are some non linear resistors also whose resistance changes with temperature or light. Negative temperature coefficient (NTC), positive temperature coefficient (PTC) and light dependent resistor (LDR) are some such resistors. These special resistors are commonly used as sensors. Resistors, like diodes and relays, are another of the electronic parts that should have a section in the installer's parts bin. They have become a necessity for the mobile electronics installer, whether it be for door locks, praking lights, timing circuits, remote starts, LED's, or just to
18

discharge a stiffening capacitor. Resistors "resist" the flow of electrical current. The higher the value of resistance (measured in ohms) the lower the current will be. Resistors are color coded. To read the color code of a common 4 band 1K ohm resistor with a 5% tolerance, start at the opposite side of the GOLD tolerance band and read from left to right. Write down the corresponding number from the color chart below for the 1st color band (BROWN). To the right of that number, write the corresponding number for the 2nd band (BLACK) . Now multiply that number (you should have 10) by the corresponding multiplier number of the 3rd band (RED)(100). Your answer will be 1000 or 1K. It's that easy. * If a resistor has 5 color bands, write the corresponding number of the 3rd band to the right of the 2nd before you multiply by the corresponding number of the multiplier band. If you only have 4 color bands that include a tolerance band, ignore this column and go straight to the multiplier. The tolerance band is usually gold or silver, but some may have none. Because resistors are not the exact value as indicated by the color bands, manufactures have included a tolorance color band to indicate the accuracy of the resistor. Gold band indicates the resistor is within 5% of what is indicated. Silver = 10% and None = 20%. Others are shown in the chart below. The 1K ohm resistor in the example (left), may have an actual measurement any where from 950 ohms to 1050 ohms. If a resistor does not have a tolerance band, start from the band closest to a lead. This will be the 1st band. If you are unable to read the color bands, then you'll have to use your multimeter. Be sure to zero it out first!

Resistor Color Codes Band Color Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver None 1st Band # 0 1 2 3 4 5 6 7 8 9 2nd Band # 0 1 2 3 4 5 6 7 8 9 *3rd Band # 0 1 2 3 4 5 6 7 8 9 Multiplier x 1 10 100 1000 10,000 100,000 1,000,000 10,000,000 100,000,000 1,000,000,000 0.1 0.01 5% 10 % 20 % 0.5 % 0.25 % 0.10 % 0.05 % 1% 2% Tolerances %

TABLE-4
19

(4.) CRYSTAL OSCILLATOR:-

FIG.7.1 DESCRIPTION:A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency. This frequency is commonly used to keep track of time (as in quartz wristwatches), to provide a stable clock signal for digital integrated circuits, and to stabilize frequencies for radio transmitters and receivers. The most common type of piezoelectric resonator used is the quartz crystal, so oscillator circuits designed around them became known as "crystal oscillators." Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of megahertz. More than two billion (2109) crystals are manufactured annually. Most are small devices for consumer devices such as wristwatches, clocks, radios, computers, and cellphones. Quartz crystals are also found inside test and measurement equipment, such as counters, signal generators,and oscilloscopes.

Pierce Oscillator:A simplified schematic of the oscillator circuit used in Figure 1. Note that the typical 2-pin crystal has been replaced by its equivalent circuit model. Co is the pin-to-pin capacitance. Its value is associated with the crystal electrode design and the crystal holder.
20

Rs is the motion resistance. Its value is specified by the crystal manufacturer. Cs is the motion capacitance and Ls is the motion inductance, which are not specified, and are functions of the crystal frequency. Rbias is a feedback resistor, implemented on-chip in Chrontel products, which provides DC bias to the inverting amplifier. C1 and C2 are total capacitance-to-ground at the input and output nodes of the amplifier, respectively. If external capacitance is not added, the values of the internal capacitance C1 and C2, including pin parasitic capacitance, are each approximately 15pF to 20pF.

21

Series and Parallel Resonance:There is no such thing as a series cut crystal as opposed to a parallel cut crystal. The same crystal can be made to oscillate in series resonance mode or parallel resonance mode. The frequency of osillation of a crystal is usually specified by the manufacturer as either the series resonance frequency or the parallel resonance frequency. A crystal can oscillate in series resonance, meaning that Ls is resonating with Cs, and the resonance frequency is then simply

Some oscillator circuits are designed for series resonance and the oscillation frequency shall equal the specified series resonance value. These series mode oscillators, however, are more sensitive to temperature and component variations. In fact, most crystals oscillators in today's ICs are of the parallel resonance type. The oscillation frequency of a parallel mode oscillator is always higher than fseries. The actual oscilation frequency of a parallel mode oscillator is dependent on the equivalent capacitance seen by the crystal.

22

Where

At parallel resonance, the crystal behaves inductively and resonates with capacitance shunting the crystal terminals. Depending on the application, especially in microprocessors where Pierce oscillators are used predominantly, a crystal manufacturer may specify parallel resonance frequency instead of series resonance frequency. Since fparallel is a function of the load capacitance Ceq, it should also be specified along with fparallel. For PC CPU clock and VGA clock applications, the frequency accuracy required is usually not very stringent and can easily be satisfied with a 14.318 MHz crystal that has been specified for operation in either series or parallel resonance modes.

Crystal Power Dissipation:This is one of the more important specifications for a crystal. In operation, if the power dissipated in the crystal exceeds the specified drive level, the crystal may have long term reliability problems. The oscillation frequency may shift from the desired value, and in extreme cases the crystal may crack and stop oscillating altogether. For the circuit in Figure 1, crystal dissipation is given by

Using typical values for Rs, Ceq and V equals 5V, P equals approximately 876 W. Since increasing the value of C1 and C2 would result in increased power dissipation in the crystal, it is not recommended that extra capacitance be added to pins XTAL1 and XTAL2 of the clock chip unless it is absolutely necessary to tune the frequency to a desired value. In the case that additional capacitances are added, a crystal with a higher drive level should be chosen according to the above equation.

23

(5.) RELAY:-

FIG.8.1
DESCRIPTION:Relay is an electromagnetic device which is used to isolate two circuits electrically and connect them magnetically. They are very useful devices and allow one circuit to switch another one while they are completely separate. They are often used to interface an electronic circuit (working at a low voltage) to an electrical circuit which works at very high voltage. For example, a relay can make a 5V DC battery circuit to switch a 230V AC mains circuit. Thus a small sensor circuit can drive, say, a fan or an electric bulb. A relay can be divided into two parts: input and output. The input section has a coil which generates magnetic field when a small voltage from an electronic circuit is applied to it. This voltage is called the operating voltage. Commonly used relays are available in different configuration of operating voltages like 6V, 9V, 12V, 24V etc. The output section consists of contactors which connect or disconnect mechanically. In a basic relay there are three contactors: normally open (NO), normally closed (NC) and common (COM). At no input state, the COM is connected to NC. When the operating voltage is applied the relay coil gets energized and the COM changes contact to NO. Different relay configurations are available
24

like SPST, SPDT, DPDT etc, which have different number of changeover contacts. By using proper combination of contactors, the electrical circuit can be switched on and off. An electromagnetic switch, consist of a coil (terminals 85 & 86), 1 common terminal (30), 1 normally closed terminal (87a), and one normally open terminal (87) (Figure 1). When the coil of an SPDT relay (Figure 1) is at rest (not energized), the common terminal (30) and the normally closed terminal (87a) have continuity. When the coil is energized, the common terminal (30) and the normally open terminal (87) have continuity. The diagram below center (Figure 2) shows an SPDT relay at rest, with the coil not energized. The diagram below right (Figure 3) shows the relay with the coil energized. As you can see, the coil is an electromagnet that causes the arm that is always connected to the common (30) to pivot when energized whereby contact is broken from the normally closed terminal (87a) and made with the normally open terminal (87). When energizing the coil of a relay, polarity of the coil does not matter unless there is a diode across the coil. If a diode is not present, you may attach positive voltage to either terminal of the coil and negative voltage to the other, otherwise you must connect positive to the side of the coil that the cathode side (side with stripe) of the diode is connected and negative to side of the coil that the anode side of the diode is connected.

FIG.8.1.1

SPST Relay : (Single Pole Single Throw Relay) an electromagnetic switch, consist of a
coil (terminals 85 & 86), 1 common terminal (30), and one normally open terminal (87). It does not have a normally closed terminal like the SPDT relay, but may be used in place of SPDT relays in all diagrams shown on this site where terminal 87a is not used. Dual Make SPST Relay : (Single Pole Single Throw Relay) an electromagnetic switch, consist of a coil (terminals 85 & 86), 1 common terminal (30), and two normally open terminals (87 and 87b). Dual make SPST relays (Figure 4) are used to power two circuits at
25

the same time that are normally isolated from each other, such as parking lamp circuits on German automobiles.

The diagram below center (Figure 5) shows a dual make SPST relay at rest, with the coil not energized. The diagram below right (Figure 6) shows the relay with the coil energized. The coil is an electromagnet that causes the arms that are always connected to the common (30) to pivot when energized whereby contact is made with the normally open terminals (87 and 87b).

Diodes are most often used across the coil to provide a path for current when the current path to the relay is interrupted (i.e. switched off, coil no longer energized). This allows the coil field to collapse without the voltage spike that would otherwise be generated. The diode protects switch or relay contacts and other circuits that may be sensitive to voltage spikes.

26

(6.) L.C.D(Liquid Crystal Display ):-

FIG.9 LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

27

Pin Description:-

Pin No 1 2 3

Function Ground (0V) Supply voltage; 5V (4.7V 5.3V) Contrast adjustment; through a variable

Name Ground Vcc VEE

28

4 5 6 7 8 9 10 11 12 13 14 15 16

Selects command register when low; and data register when high Low to write to the register; High to read from the register Sends data to data pins when a high to low pulse is given

Register Select Read/write Enable DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 Led+ Led-

8-bit data pins

Backlight VCC (5V) Backlight Ground (0V)


TABLE.6

29

30

31

Schematic

Circuit Description
Above is the quite simple schematic. The LCD panel's Enable and Register Select is connected to the Control Port. The Control Port is an open collector / open drain output. While most Parallel Ports have internal pull-up resistors, there are a few which don't. Therefore by incorporating the two 10K external pull up resistors, the circuit is more portable for a wider range of computers, some of which may have no internal pull up resistors. We make no effort to place the Data bus into reverse direction. Therefore we hard wire the R/W line of the LCD panel, into write mode. This will cause no bus conflicts on the data lines. As a result we cannot read back the LCD's internal Busy Flag which tells us if the LCD has accepted and finished processing the last instruction. This problem is overcome by inserting known delays into our program. The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with all the examples, I've left the power supply out. You can use a bench power supply set to 5v or use a onboard +5 regulator. Remember a few de-coupling capacitors, especially if you have trouble with the circuit working properly.
32

The 2 line x 16 character LCD modules are available from a wide range of manufacturers and should all be compatible with the HD44780. The one I used to test this circuit was a Powertip PC1602F and an old Philips LTN211F-10 which was extracted from a Poker Machine! The diagram to the right, shows the pin numbers for these devices. When viewed from the front, the left pin is pin 14 and the right pin is pin 1.

Programming - Source Code


/* /* /* /* /* /* /* /* /* LCD Module Software */ 17th May 1997 */ Copyright 1997 Craig Peacock */ WWW - http://www.senet.com.au/~cpeacock */ Email - [email protected] */ */ Register Select must be connected to Select Printer (PIN 17) */ Enable must be connected to Strobe (PIN1) */ DATA 0:7 Connected to DATA 0:7 */

#include <dos.h> #include <string.h> #define PORTADDRESS 0x378 /* Enter Your Port Address Here */ #define DATA PORTADDRESS+0 #define STATUS PORTADDRESS+1 #define CONTROL PORTADDRESS+2 void main(void) { char string[] = {"Testing 1,2,3 "It' Works ! char init[10]; int count; int len; init[0] = 0x0F; /* Init Display */ init[1] = 0x01; /* Clear Display */ init[2] = 0x38; /* Dual Line / 8 Bits */

" "};

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port - Make sure Forward Direction */ outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer (Register Select) */
33

for (count = 0; count <= 2; count++) { outportb(DATA, init[count]); outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/ delay(20); /* Larger Delay for INIT */ outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe (Enable)*/ delay(20); /* Larger Delay for INIT */ } outportb(CONTROL, inportb(CONTROL) & 0xF7); Select) */ len = strlen(string); for (count = 0; count < len; count++) { outportb(DATA, string[count]); outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */ delay(2); outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */ delay(2); } } Above is the source code to get this example running. It's been written for Borland C, so if you are using a Microsoft compiler, then you will have to change the outportb() function to outp() and inportb() to inp(). The LCD panel requires a few instructions to be sent, to order to turn on the display and initialise it. This is what the first for loop does. These instructions must be sent to the LCD's Instruction Register which is controlled by the Register Select (Pin 4). When pin 4 is low the instruction register is selected, thus when high the data register must be selected. We connect this to the Parallel Port's Select Printer line which happens to be hardware inverted. Therefore if we write a '1' to bit 3 of the Control Register the Select Printer line goes low. We want to first send instructions to the LCD module. Therefore the Register Select line must be low. As it is hardware inverted, we will want to set bit 3 of the Control Register to '1'. However we don't want to upset any other bits on the Control Port. We achieve this by reading the Control Port and OR'ing 0x80 to it. e.g. outportb(CONTROL, inportb(CONTROL) | 0x08);This will only set bit 3. After we place a data byte on the data lines, we must then signal to the LCD module to read the data. This is done using theEnable line. Data is clocked into the LCD module on the high to low transition. The Strobe is hardware inverted, thus by setting bit 0 of the Control Register we get a high to low transition on the Strobe line. We then wait for a delay, and return the line to a high state ready for the next byte. After we initialize the LCD Module, we want to send text to it. Characters are sent to the LCD's Data Port, thus we want to clear bit 3. Once again we must only change the one bit, thus we use outportb(CONTROL, inportb(CONTROL) & 0xF7);. Then we set up
34

/* Reset Select Printer (Register

another for loop to read a byte from the string and send it to the LCD panel. This is repeated for the length of the string. The delays should be suitable for most machines. If the LCD panel is not initializing properly, you can try increasing the delays. Likewise if the panel is skipping characters, e.g. Tst ,2. On the other hand, If the LCD module is repeating characters e.g.TTTeessttiinngg then you may have a faulting Enable connection. Check your Enable to Strobe connection.

(7.) BUZZER:-

FIG.10.1 Description:The piezo buzzer produces sound based on reverse of the piezoelectric effect. The generation of pressure variation or strain by the application of electric potential across a piezoelectric material is the underlying principle. These buzzers can be used alert a user of an event corresponding to a switching action, counter signal or sensor input. They are also used in alarm circuits.

35

FIG.10.1

This novel buzzer circuit uses a relay in series with a small audio transformer and speaker. When the switch is pressed, the relay will operate via the transformer primary and closed relay contact. As soon as the relay operates the normally closed contact will open, removing power from the relay, the contacts close and the sequence repeats, all very quickly...so fast that the pulse of current causes fluctuations in the transformer primary, and hence secondary. The speakers tone is thus proportional to relay operating frequency. The capacitor C can be
36

used to "tune" the note. The nominal value is 0.001uF, increasing capacitance lowers the buzzers tone. The buzzer produces a same noisy sound irrespective of the voltage variation applied to it. It consists of piezo crystals between two conductors. When a potential is applied across these crystals, they push on one conductor and pull on the other. This, push and pull action, results in a sound wave. Most buzzers produce sound in the range of 2 to 4 kHz. The Red lead is connected to the Input and the Black lead is connected to Ground.

(8.)Energy meters:Energy meters, the only direct revenue interface between utilities and the consumers, have undergone several advancements in the last decade. The conventional electro-mechanical meters are being replaced with electronic meters to improve accuracy in meter reading. Asian countries are currently looking to introduce prepaid electricity meters across their distribution network, buoyed up by the success of this novel methodology in South Africa. The existing inherent problems with the post-paid system and privatization of state held power distribution companies are the major driving factors for this market in Asia. Over 40 countries have implemented prepaid meters in their markets. In United Kingdom the system, has been in use for well over 70 years with about 3.5 million consumers. The prepaid program in South Africa was started in 1992, since then they have installed over 6 million meters. Other African counties such as Sudan, Madagascar are following the South African success. The concept has found ground in Argentina and New Zealand with few thousands of installations. The prepaid meters in the market today are coming up with smart cards to hold information on units consumed or equivalent money value. When the card is inserted, the energy meter reads it, connects the supply to the consumer loads, and debits the value. The meters are equipped with light emitting diodes (LED) to inform consumers when 75 percent of the credit energy has been consumed. The consumer then recharges the prepaid card from a sales terminal or distribution point, and during this process any changes in the tariff can also be loaded in the smart card.

(9.) OPTOCOUPLERS
DESCRIPTION
37

The general purpose optocouplers consist of a gallium arsenide infrared emitting diode driving a silicon phototransistor in a 6-pin dual in-line package.

FEATURES
Also available in white package by specifying -M suffix UL recognized VDE recognized - Add option V for white package - Add option 300 for black package

APPLICATIONS
Power supply regulators Digital logic inputs Microprocessor inputs

38

39

40

FIG12.1.1

41

42

43

44

FIG.12.1.2

45

46

47

48

(10.)card reader:A card reader is a data input device that reads data from a card-shaped storage medium. Historically, paper or cardboard punched cardswere used throughout the first several decades of the computer industry to store information and write programs for computer system, and these were read by punched card readers. More modern card readers are electronic devices that use plastic cards imprinted with barcodes, magnetic strips, computer chips or other storage medium. A memory card reader is a device used for communication with a smart card or a memory card. A magnetic card reader is a device used to read magnetic stripe cards, such as credit cards. A business card reader is a device used to scan and electronically save printedbusiness cards.

Smart card readers

A smart card reader is an electronic device that reads smart cards. Some keyboards have a built-in card reader. There are external devices and internal drive bay card reader devices for PC. Some laptops have built-in smart card reader. Some have a flash upgradeable firmware. The card reader supplies the integrated circuit on the smart card with electricity. Communication is done via protocols and you can read and write to a fixed address on the card. If the card is not using any standard transmission protocol, but uses a custom/proprietary protocol it has the communication protocol designation T=14.[1] The latest PC/SC CCID specifications has defined a new smart card framework. It works with USB devices with the specific device class 0x0B. Readers with this class do not need device drivers when used with PC/SC-compliant operating systems, because the OS supplies it by default. PKCS#11 is an API, designed to be platform independent, defining a generic interface to cryptographic tokens such as smart cards, allowing applications to work without knowledge of the reader details.
[edit]Memory

card readers

49

FIG.13

A USB card reader like this one, will typically implement the USB mass storage device class. A memory card reader is a device, typically having a USB interface, for accessing the data on amemory card such as a CompactFlash (CF), Secure Digital (SD) or MultiMediaCard (MMC). Most card readers also offer write capability, and together with the card, this can function as a pen drive. [edit]Access control card reader Access control card readers are used in physical security systems to read a credential that allows access through access control points, typically a locked door. An access control reader can be amagnetic stripe reader, a bar code reader, a proximity reader, a smart card reader, or a biometricreader. Access control readers may be classified by functions they are able to perform and by identification technology: Barcode A barcode is a series of alternating dark and light stripes that are read by an optical scanner. The organization and width of the lines is determined by the bar code protocol selected. There are many different protocols but Code 39 is the most popular in the security industry. Sometimes the digits represented by the dark and light bars are also printed to allow people to read the number without an optical reader. The advantage of using bar code technology is that it is cheap and easy to generate the credential, and it can easily be applied to cards or other items. However the same affordability and simplicity makes the technology susceptible to fraud, because fake barcodes can also be created cheaply and easily, for example by photocopying real ones. One attempt to reduce fraud is to print the bar code using carbon-based ink and then cover the bar code with a dark red overlay. The bar code can then be read with an optical reader tuned to the infrared spectrum, but can not easily be copied by a copy machine. This does not

50

address the ease with which bar code numbers can be generated from a computer using almost any printer.

Biometric
There are several forms of biometric identification employed in access control: fingerprint, hand geometry, iris and face recognition. The use of biometric technology significantly increases security level of systems because it eliminates such problems as lost, stolen or loaned ID cards, and forgotten or guessed PINs[citation needed]. The operation of all biometric readers is alike: they compare the template stored in memory to the scan obtained during the process of identification. If the probability that the template in the memory and the live scan belong to the same person is high enough, the ID number of that person is sent to a control panel. The control panel then checks permissions of the user and makes the decision whether to grant access or not. The communication between the reader and the control panel is usually done in the industry standard Wiegand protocol. The only exception is intelligent biometric readers that do not require any panels and directly control all door hardware. Biometric templates may be stored in the memory of readers, in which case the number of users is limited by reader memory size. Readers currently available in the market may store up to 50,000 templates. Template of each user may also be stored in the memory of his/her smart card. This option removes all limits to the number of system users, but it requires each user to have a card and makes finger-only identification impossible. Biometric templates may also be stored in the memory of a central server PC. This option is called "server-based verification". Readers simply read biometric data of users and forward it to the main computer for processing. Such systems support large number of users, but they are very much dependent on the reliability of the central server and communication lines. 1-to-1 and 1-to-many are the two possible modes of operation of a biometric reader.

In the 1-to-1 mode a user must first identify himself/herself to the reader by either presenting an ID card or entering a PIN. The reader then looks up the template of the user in the database and compares it with the live scan. The 1-to-1 method is considered more secure and is generally faster as the reader needs to perform only one comparison. Most 1-to-1 biometric readers are "dual-technology" readers: they either have a built-in proximity, smart card or keypad reader, or they have an input for connecting an external card reader. In the 1-to-many mode a user presents his finger (or hand, eye, etc.) and reader needs to compare the live scan to all the templates stored in the memory. This method is preferred by most end-users, because it eliminates the need to carry ID cards or use PINs. On the other hand this method is slower, because the reader may have to perform thousands of comparison operations until it finds the match. An important technical characteristic of 1-to-many readers is the number of comparisons that can be performed in one second, which is considered the maximum time that users can wait at a door without noticing a delay. Currently most 1-to-many readers are capable of performing 20003000 matching operations per second. [edit]Magnetic stripe See also: Magnetic stripe card Magnetic stripe technology, usually called mag-stripe, is so named because of the stripe of magnetic oxide tape that is laminated on a card. There are three tracks of data on the
51

magnetic stripe. Typically the data on each of the tracks follows a specific encoding standard, but it is possible to encode any format on any track. A mag-stripe card is cheap compared to other card technologies and is easy to program. The magnetic stripe holds more data than a bar code can in the same space. While a mag-stripe is more difficult to generate than a bar code, the technology for reading and encoding data on a mag-stripe is widespread and easy to acquire. Magnetic stripe technology is also susceptible to misreads, card wear, and data corruption. [edit]Wiegand card Wiegand card technology is a patented technology using embedded ferromagnetic wires strategically positioned to create a unique pattern that generates the identification number. Like magnetic stripe or bar code, this card must be swiped through a reader to be read. Unlike those other technologies the identification media is embedded in the card and not susceptible to wear. This technology once gained popularity because of the difficulty in duplicating the technology creating a high perception of security. This technology is being replaced by proximity cards because of the limited source of supply, the relatively better tamper resistance of proximity readers, and the convenience of the touch-less functionality in proximity readers. [edit]Proximity card The Wiegand effect was used in early access cards. This method was abandoned in favor of other technologies. Card readers are still referred to as "Wiegand output readers" but no longer use the Wiegand effect. The new technologies retained the Wiegand upstream data so that the new readers were compatible with old systems. A proximity reader radiates a 1" to 20" electrical field around itself. Cards use a simple LC circuit. When a card is presented to the reader, the reader's electrical field excites a coil in the card. The coil charges a capacitor and in turn powers an integrated circuit (IC). The integrated circuit outputs the card number to the coil which transmits it to the reader. A common proximity format is 26-bit Wiegand. This format uses a facility code, sometimes also called a site code. The facility code is a unique number common to all of the cards in a particular set. The idea is that an organization will have their own facility code and a set of numbered cards incrementing from 1. Another organization has a different facility code and their card set also increments from 1. Thus different organizations can have card sets with the same card numbers but since the facility codes differ, the cards only work at one organization. This idea worked fine for a while but there is no governing body controlling card numbers, and different manufacturers can supply cards with identical facility codes and identical card numbers to different organizations. Thus there is a problem of duplicate cards. To counteract this problem some manufacturers have created formats beyond 26-bit Wiegand that they control and issue to organizations. In the 26-bit Wiegand format, bit 1 is an even parity bit. Bits 29 are a facility code. Bits 1025 are the card number. Bit 26 is an odd parity bit. 1/8/16/1. Other formats have a similar structure of a leading facility code followed by the card number and including parity bits for error checking, such as the 1/12/12/1 format used by some American access control companies. 1/8/16/1 gives as facility code limit of 255 and 65535 card number 1/12/12/1 gives a facility code limit of 4095 and 4095 card number. Wiegand was also stretched to 34 bits, 56 bits and many others.
52

[edit]Smart card There are two types of smart cards: contact and contactless. Both have an embedded microprocessor and memory. The smart card differs from the card typically called a proximity card in that the microchip in the proximity card has only one function: to provide the reader with the card's identification number. The processor on the smart card has an embedded operating system and can handle multiple applications such as a cash card, a pre-paid membership card, and even an access control card. The difference between the two types of smart cards is found in the manner with which the microprocessor on the card communicates with the outside world. A contact smart card has eight contacts, which must physically touch contacts on the reader to convey information between them. Since contact cards must be inserted into readers carefully and the orientation has be observed the speed and convenience of such transaction is not acceptable for most access control applications. The use of contact smart cards is physical access control is limited mostly to parking applications when payment data is stored in card memory and when the speed of transactions is not important. A contactless smart card uses the same radio-based technology as the proximity card with the exception of the frequency band used: higher frequency (13.56 MHz instead of 125 kHz) allows to transferring more data and communicating with several cards at the same time. A contactless card does not have to touch the reader or even be taken out from a wallet or purse. Most access control systems only read serial numbers of contactless smart cards and do not utilize the available memory. Card memory may be used for storing biometric data (i.e. fingerprint template) of a user. In such case a biometric reader first reads the template on the card and then compares it to the finger (hand, eye, etc.) presented by the user. This way biometric data of users does not have to be distributed and stored in the memory of controllers or readers, which simplifies the system and reduces memory requirements. Smartcard readers have been targeted successfully by criminals in what is termed a supply chain attack, in which the readers are tampered with during manufacture or in the supply chain before delivery. The rogue devices capture customers' card details before transmitting them to criminals.

53

(11.)Capacitor:-

FIG.14.1 Introduction to Capacitors


Just like the Resistor, the Capacitor, sometimes referred to as a Condenser, is a passive device, and one which stores its energy in the form of an electrostatic field producing a potential difference (Static Voltage) across its plates. In its basic form a capacitor consists of two or more parallel conductive (metal) plates that do not touch or are connected but are electrically separated either by air or by some form of insulating material such as paper, mica or ceramic called the Dielectric. The conductive plates of a capacitor can be either square, circular or rectangular, or be of a cylindrical or spherical shape with the shape and construction of a parallel plate capacitor depending on its application and voltage rating. When used in a direct-current or DC circuit, a capacitor blocks the flow of current through it, but when it is connected to an alternating-current or AC circuit, the current appears to pass straight through it with little or no resistance. If a DC voltage is applied to the capacitors conductive plates, a current flows charging up the plates with electrons giving one plate a positive charge and the other plate an equal and opposite negative charge. This flow of electrons to the plates is known as the Charging Current and continues to flow until the voltage across both plates (and hence the capacitor) is equal to the applied voltage Vc. At thispoint the capacitor is said to be fully charged with electrons with the strength of this charging current at its maximum when the plates are fully discharged and slowly reduces in value to zero as the plates charge up to a potential difference equal to the applied supply voltage and this is illustrated below.

54

Capacitor Construction

FIG.14.1.1 The parallel plate capacitor is the simplest form of capacitor and its capacitance value is fixed by the surface area of the conductive plates and the distance or separation between them. Altering any two of these values alters the the value of its capacitance and this forms the basis of operation of the variable capacitors. Also, because capacitors store the energy of the electrons in the form of an electrical charge on the plates the larger the plates and/or smaller their separation the greater will be the charge that the capacitor holds for any given voltage across its plates. In other words, larger plates, smaller distance, more capacitance. By applying a voltage to a capacitor and measuring the charge on the plates, the ratio of the charge Q to the voltage V will give the capacitance value of the capacitor and is therefore given as: C = Q/V this equation can also be re-arranged to give the more familiar formula for the quantity of charge on the plates as: Q = C x V Although we have said that the charge is stored on the plates of a capacitor, it is more correct to say that the energy within the charge is stored in an "electrostatic field" between the two plates. When an electric current flows into the capacitor, charging it up, the electrostatic field becomes more stronger as it stores more energy. Likewise, as the current flows out of the capacitor, discharging it, the potential difference between the two plates decreases and the electrostatic field decreases as the energy moves out of the plates.

55

The property of a capacitor to store charge on its plates in the form of an electrostatic field is called theCapacitance of the capacitor. Not only that, but capacitance is also the property of a capacitor which resists the change of voltage across it.

The Capacitance of a Capacitor


The unit of capacitance is the Farad (abbreviated to F) named after the British physicist Michael Faraday and is defined as a capacitor has the capacitance of One Farad when a charge of One Coulomb is stored on the plates by a voltage of One volt. Capacitance, C is always positive and has no negative units. However, the Farad is a very large unit of measurement to use on its own so sub-multiples of the Farad are generally used such as micro-farads, nano-farads and pico-farads, for example.

Units of Capacitance
Microfarad (F) 1F = 1/1,000,000 = 0.000001 = 10-6 F Nanofarad (nF) 1nF = 1/1,000,000,000 = 0.000000001 = 10-9 F Picofarad (pF) 1pF = 1/1,000,000,000,000 = 0.000000000001 = 10-12 F The capacitance of a parallel plate capacitor is proportional to the area, A of the plates and inversely proportional to their distance or separation, d (i.e. the dielectric thickness) giving us a value for capacitance of C = k( A/d ) where in a vacuum the value of the constant k is 8.84 x 10-12 F/m or 1/4..9 x 109, which is the permittivity of free space. Generally, the conductive plates of a capacitor are separated by air or some kind of insulating material or gel rather than the vacuum of free space.

56

The Dielectric of a Capacitor


As well as the overall size of the conductive plates and their distance or spacing apart from each other, another factor which affects the overall capacitance of the device is the type of dielectric material being used. In other words the "Permittivity" () of the dielectric. The conductive plates are generally made of a metal foil or a metal film but the dielectric material is an insulator. The various insulating materials used as the dielectric in a capacitor differ in their ability to block or pass an electrical charge. This dielectric material can be made from a number of insulating materials or combinations of these materials with the most common types used being: air, paper, polyester, polypropylene, Mylar, ceramic, glass, oil, or a variety of other materials. The factor by which the dielectric material, or insulator, increases the capacitance of the capacitor compared to air is known as the Dielectric Constant, k and a dielectric material with a high dielectric constant is a better insulator than a dielectric material with a lower dielectric constant. Dielectric constant is a dimensionless quantity since it is relative to free space. The actual permittivity or "complex permittivity" of the dielectric material between the plates is then the product of the permittivity of free space (o) and the relative permittivity (r) of the material being used as the dielectric and is given as: Complex Permittivity

As the permittivity of free space, o is equal to one, the value of the complex permittivity will always be equal to the relative permittivity. Typical units of dielectric permittivity, or dielectric constant for common materials are: Pure Vacuum = 1.0000, Air = 1.0005, Paper = 2.5 to 3.5, Glass = 3 to 10, Mica = 5 to 7, Wood = 3 to 8 and Metal Oxide Powders = 6 to 20 etc. This then gives us a final equation for the capacitance of a capacitor as:

One method used to increase the overall capacitance of a capacitor is to "interleave" more plates together within a single capacitor body. Instead of just one set of parallel plates, a capacitor can have many individual plates connected together thereby increasing the area, A of the plate. For example, a capacitor with 10 interleaved plates would produce 9 (10 - 1) mini capacitors with an overall capacitance nine times that of a single parallel plate.

57

Modern capacitors can be classified according to the characteristics and properties of their insulating dielectric:

Low Loss, High Stability such as Mica, Low-K Ceramic, Polystyrene. Medium Loss, Medium Stability such as Paper, Plastic Film, High-K Ceramic. Polarized Capacitors such as Electrolytic's, Tantalum's.

Voltage Rating of a Capacitor


All capacitors have a maximum voltage rating and when selecting a capacitor consideration must be given to the amount of voltage to be applied across the capacitor. The maximum amount of voltage that can be applied to the capacitor without damage to its dielectric material is generally given in the data sheets as: WV, (working voltage) or as WV DC, (DC working voltage). If the voltage applied across the capacitor becomes too great, the dielectric will break down (known as electrical breakdown) and arcing will occur between the capacitor plates resulting in a short-circuit. The working voltage of the capacitor depends on the type of dielectric material being used and its thickness. The DC working voltage of a capacitor is just that, the maximum DC voltage and NOT the maximum AC voltage as a capacitor with a DC voltage rating of 100 volts DC cannot be safely subjected to an alternating voltage of 100 volts. Since an alternating voltage has an r.m.s. value of 100 volts but a peak value of over 141 volts!. Then a capacitor which is required to operate at 100 volts AC should have a working voltage of at least 200 volts. In practice, a capacitor should be selected so that its working voltage either DC or AC should be at least 50 percent greater than the highest effective voltage to be applied to it. Another factor which affects the operation of a capacitor is Dielectric Leakage. Dielectric leakage occurs in a capacitor as the result of an unwanted leakage current which flows through the dielectric material. Generally, it is assumed that the resistance of the dielectric is extremely high and a good insulator blocking the flow of DC current through the capacitor (as in a perfect capacitor) from one plate to the other. However, if the dielectric material becomes damaged due excessive voltage or over temperature, the leakage current through the dielectric will become extremely high resulting in a rapid loss of charge on the plates and an overheating of the capacitor eventually resulting in premature failure of the capacitor. Then never use a capacitor in a circuit with higher voltages than the capacitor is rated for otherwise it may become hot and explode.
58

Introduction to Capacitors Summary


The job of a capacitor is to store charge onto its plates. The amount of electrical charge that a capacitor can store on its plates is known as its Capacitance value and depends upon three main factors.

The surface area, A of the two conductive plates which make up the capacitor, the larger the area the greater the capacitance. The distance, d between the two plates, the smaller the distance the greater the capacitance. The type of material which separates the two plates called the "dielectric", the higher the permittivity of the dielectric the greater the capacitance. The dielectric of a capacitor is a non-conducting insulating material, such as waxed paper, glass, mica different plastics etc, and provides the following advantages.

The dielectric constant is the property of the dielectric material and varies from one material to another increasing the capacitance by a factor of k. The dielectric provides mechanical support between the two plates allowing the plates to be closer together without touching. Permittivity of the dielectric increases the capacitance. The dielectric increases the maximum operating voltage compared to air. All capacitors have a maximum working voltage rating, its WV DC so select a capacitor with a rating at least 50% more than the supply voltage. There are a large variety of capacitor styles and types, each one having its own particular advantage, disadvantage and characteristics. To include all types would make this tutorial section very large so in the next tutorial about The Introduction to Capacitors I shall limit them to the most commonly used types.

(12.)CARD PROGRAMMING:SDA1 EQU P3.4 SCL1 EQU P3.3 WTCMD EQU RDCMD EQU ;SDA=PIN5 ;SCL=PIN6 10100000B 10100001B ;WRITE DATA COMMAND Note 3 ;READ DATA COMMAND Note 3

59

RED EQU P3.7 GREEN EQU P1.0

KEYS EQU P1

ROW1 EQU P1.1 ROW2 EQU P1.2 ROW3 EQU P1.3 ROW4 EQU P1.4 COL1 EQU P1.7 COL2 EQU P1.6 COL3 EQU P1.5

DSEG ORG 20H

; This is internal data memory ; Bit adressable memory 1 1 1 1 1 1 1

KEY: DS N0: N1: N2: N3: N4: N5: DS DS DS DS DS DS

60

COUNT: PASS0: PASS1: PASS2: CHANGE: CSEG

DS DS DS DS DS

1 1 1 1 1

; Code begins here

; ---------==========----------==========---------=========--------; Main routine. Program execution starts here. 8889 ; ---------==========----------==========---------=========--------ORG 00H ; Reset

MOV SP,#60H

CLR RED CLR GREEN CALL DELAY CALL DELAY SETB RED SETB GREEN

MOV N1,#01H MOV N2,#0FFH

61

MOV N3,#0FFH MOV N4,#0FFH MOV N5,#0FFH

MOV R3,#01H ; ; ; MOV N2,#23H MOV N4,#45H CALL SAX

KEYBOARD: MOV KEY,#00H SETB COL1 SETB COL2 SETB COL3 K11: CLR ROW1 CLR ROW2 CLR ROW3 CLR ROW4 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,K11 K2: ACALL DEALAY MOV A,KEYS ANL A,#11100000B ;check till all keys released ;call 20 msec delay ;see if any key is pressed ;mask unused bits

62

CJNE A,#11100000B,OVER SJMP K2 OVER: ACALL DEALAY MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,OVER1 SJMP K2 OVER1: MOV A,KEYS

;key pressed, await closure

ORL A,#11111110B MOV KEYS,A CLR ROW1 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_1 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW2 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_2 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW3

63

MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_3 MOV A,KEYS ORL A,#11111110B MOV KEYS,A CLR ROW4 MOV A,KEYS ANL A,#11100000B CJNE A,#11100000B,ROW_4 LJMP K2

ROW_1:

RLC A

JC MAT1 MOV KEY,#01H AJMP K1 MAT1: RLC A

JC MAT2 MOV KEY,#02H AJMP K1 MAT2: JC K1 MOV KEY,#03H AJMP K1 RLC A

64

ROW_2:

RLC A

JC MAT3 MOV KEY,#04H AJMP K1 MAT3: RLC A

JC MAT4 MOV KEY,#05H AJMP K1 MAT4: JC K1 MOV KEY,#06H AJMP K1 RLC A

ROW_3:

RLC A

JC MAT5 MOV KEY,#07H AJMP K1 MAT5: RLC A

JC MAT6 MOV KEY,#08H AJMP K1 MAT6: JC K1 MOV KEY,#09H RLC A

65

AJMP K1

ROW_4:

RLC A

JC MAT7 MOV KEY,#0AH AJMP K1 MAT7: RLC A

JC MAT8 MOV KEY,#00H AJMP K1 MAT8: JC K1 MOV KEY,#0FH RLC A ;for 0

K1: CLR RED CALL DELAY CALL DELAY SETB RED

MOV A,KEY CJNE A,#0FH,G0

66

CJNE R3,#07H,G0 AJMP G8 G0: CJNE R3,#01H,G11 INC R3 MOV N0,KEY AJMP KEYBOARD G11: CJNE R3,#02H,G1 INC R3 MOV N1,KEY AJMP KEYBOARD G1: CJNE R3,#03H,G2 INC R3 MOV N2,KEY AJMP KEYBOARD G2: CJNE R3,#04H,G3 INC R3 MOV N3,KEY AJMP KEYBOARD G3: CJNE R3,#05H,G4 INC R3 MOV N4,KEY AJMP KEYBOARD G4: CJNE R3,#06H,G5 INC R3

67

MOV N5,KEY G5: AJMP KEYBOARD

G8:

MOV A,N2 SWAP A ORL A,N3 MOV N2,A MOV A,N4 SWAP A ORL A,N5 MOV N3,A ;LOWER DISITS IN N3 ;HIGHER DIGITSS IN N2

MOV A,N0 CJNE A,#01H,STR_AMT

MOV N1,#00H MOV R1,#N1 MOV R4,#20H EEPROM MOV R6,#3 CALL STORE_EEPROM ;STORE 2 BYTES ;store COUNT ;Starting Address IN

CALL DELAY

68

CALL DELAY AJMP CHK_DATA

BV1S: AJMP BV1 STR_AMT: CJNE A,#02H,BV1S

MOV N1,#01H MOV R1,#N1 MOV R4,#20H EEPROM MOV R6,#3 CALL STORE_EEPROM CALL DELAY CALL DELAY ;STORE 2 BYTES ;store COUNT ;Starting Address IN

; ---------==========----------==========---------=========--------;CHECK WITH DATA STORED IN MEMORY ; ---------==========----------==========---------=========--------CHK_DATA:

MOV R1,#PASS0 BYTES(RAM) MOV R4,#20H ADDRESS IN EEPROM

;GET

DATA

IN

;DATA

69

MOV R6,#3 CALL READ_EEPROM

;NUMBER OF BYTES

MOV A,N1 CJNE A,PASS0, BV1 MOV A,N2 CJNE A,PASS1,BV1 MOV A,N3 CJNE A,PASS2,BV1 CLR GREEN CALL DELAY1 CALL DELAY1 SETB GREEN CALL DELAY1 CALL DELAY1 CLR GREEN CALL DELAY1 CALL DELAY1 SETB GREEN MOV R3,#01H MOV N0,#0FFH MOV N1,#0FFH MOV N2,#0FFH MOV N3,#0FFH MOV N4,#0FFH

70

MOV N5,#0FFH AJMP KEYBOARD

BV1: CLR RED CALL DELAY1 CALL DELAY1 SETB RED CALL DELAY1 CALL DELAY1 CLR RED CALL DELAY1 CALL DELAY1 SETB RED MOV R3,#01H MOV N0,#0FFH MOV N1,#0FFH MOV N2,#0FFH MOV N3,#0FFH MOV N4,#0FFH MOV N5,#0FFH AJMP KEYBOARD

;(((((((((((((((((((((((((((((((( DEALAY: MOV R1,#50

71

REPP2:

NOP DJNZ R1,REPP2 RET

;(((((((((((((((((((((((((((((((( ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; READ DATA FROM EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% READ_EEPROM: MOV A,#WTCMD ADDRESS CALL OUTS MOV A,R4 CALL OUT MOV A,#RDCMD CALL OUTS BRDLP: CALL IN MOV @R1,a INC R1 DJNZ R6,AKLP CALL STOP RET AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT ;LOAD READ COMMAND ;SEND IT ;READ DATA ;STORE DATA ;INCREMENT DATA POINTER ;DECREMENT LOOP COUNTER ;IF DONE, ISSUE STOP CONDITION ;DONE, EXIT ROUTINE ;LOAD WRITE COMMAND TO SEND

72

NOP ;NOTE 1 NOP NOP NOP ;NOTE 2 NOP CLR SCL1 JMP BRDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; STORE DATA IN EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

STORE_EEPROM: MOV A,#WTCMD CALL OUTS MOV A,R4 CALL OUT BTLP: MOV A,@R1 CALL OUT INC R1 DJNZ R6,BTLP CALL STOP RET ;GET DATA ;SEND IT ;INCREMENT DATA POINTER ;LOOP TILL DONE ;SEND STOP CONDITION ;LOAD WRITE COMMAND ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT

73

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;*********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR ; to the EEPROM and includes START condition. Refer to the data sheets ; for discussion of START and STOP conditions. ;***********************************************************************

OUTS: MOV

R2,#8

;LOOP COUNT -- EQUAL TO BIT COUNT ;INSURE DATA IS HI ;INSURE CLOCK IS HI

SETB SDA1 SETB SCL1 NOP NOP NOP CLR NOP NOP NOP CLR SCL1 A SDA1

;NOTE 1

;START CONDITION -- DATA = 0 ;NOTE 1

;CLOCK = 0 ;SHIFT BIT

OTSLP: RLC JNC

BITLS ;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI

SETB SDA1 JMP OTSL1 SDA1

BITLS: CLR

OTSL1: SETB SCL1

74

NOP NOP NOP

;NOTE 1

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER ;TURN PIN INTO INPUT ;NOTE 1

DJNZ R2,OTSLP SETB SDA1 NOP

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

CLR RET

SCL1

;********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM ; without sending a START condition. ;**********************************************************************

OUT:

MOV

R2,#8 A

;LOOP COUNT -- EQUAL TO BIT COUNT ;SHIFT BIT

OTLP: RLC JNC

BITL

75

SETB SDA1 JMP OTL1 SDA1

;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI ;NOTE 1

BITL: CLR

OTL1: SETB SCL1 NOP NOP NOP

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER ;TURN PIN INTO INPUT ;NOTE 1

DJNZ R2,OTLP SETB SDA1 NOP

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

CLR RET

SCL1

STOP: CLR NOP NOP

SDA1

;STOP CONDITION SET DATA LOW ;NOTE 1

76

NOP

SETB SCL1 NOP NOP NOP

;SET CLOCK HI ;NOTE 1

SETB SDA1 RET

;SET DATA HIGH

;******************************************************************* ; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM ; From EEPROM current address pointer. ; Returns the data byte in R1 ;******************************************************************* CREAD: MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS CALL IN MOV R1,A

;SEND IT ;READ DATA ;STORE DATA ;SEND STOP CONDITION

CALL STOP RET

;********************************************************************** ; THIS ROUTINE READS IN A BYTE FROM THE EEPROM ; and stores it in the accumulator ;**********************************************************************

77

IN:

MOV

R2,#8

;LOOP COUNT ;SET DATA BIT HIGH FOR INPUT ;CLOCK LOW ;NOTE 1

SETB SDA1 INLP: CLR NOP NOP NOP NOP SCL1

SETB SCL1 CLR JNB CPL C

;CLOCK HIGH ;CLEAR CARRY ;JUMP IF DATA = 0

SDA1,INL1 C A

;SET CARRY IF DATA = 1 ;ROTATE DATA INTO ACCUMULATOR ;DECREMENT COUNTER ;CLOCK LOW

INL1: RLC

DJNZ R2,INLP CLR RET SCL1

;********************************************************************* ; This routine test for WRITE DONE condition ; by testing for an ACK. ; This routine can be run as soon as a STOP condition ; has been generated after the last data byte has been sent ; to the EEPROM. The routine loops until an ACK is received from ; the EEPROM. No ACK will be received until the EEPROM is done with

78

; the write operation. ;********************************************************************* ACKTST: MOV MOV CLR NOP NOP NOP A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS

R2,#8 SDA1

;LOOP COUNT -- EQUAL TO BIT COUNT ;START CONDITION -- DATA = 0 ;NOTE 1

CLR

SCL1 A

;CLOCK = 0 ;SHIFT BIT

AKTLP: RLC JNC

AKTLS ;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI

SETB SDA1 JMP AKTL1 SDA1

AKTLS: CLR

AKTL1: SETB SCL1 NOP NOP NOP

;NOTE 1

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER ;TURN PIN INTO INPUT ;NOTE 1

DJNZ R2,AKTLP SETB SDA1 NOP

79

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

JNB JMP

SDA1,EXIT ACKTST SCL1

;EXIT IF ACK (WRITE DONE) ;START OVER ;CLOCK LOW ;DATA LOW

EXIT: CLR CLR NOP NOP NOP

SDA1

;NOTE 1

SETB SCL1 NOP NOP SETB SDA1 RET

;CLOCK HIGH

;STOP CONDITION

;*********************************************************************

DELAY: INLOP:

MOV R0,#0FFH MOV R1,#0FFH DJNZ R1,$ DJNZ R0,INLOP RET

80

DELAY1: INLOP1:

MOV R0,#0FFH MOV R1,#0FFH DJNZ R1,$ DJNZ R0,INLOP1 RET

END

(13.)PRE-PAID ENERGY METER PROGRAMMING:-

RB0 RB1

EQU EQU

000H ; Select Register Bank 0 008H ; Select Register Bank 1 ...poke to PSW to use

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; PORT DECLERATION

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SDA1 EQU P2.1 SCL1 EQU P2.0 ;SDA=PIN5 ;SCL=PIN6

81

WTCMD EQU 10100110B RDCMD EQU 10100111B

;WRITE DATA COMMAND Note 3 ;READ DATA COMMAND Note 3

WTCMD1 EQU 10100000B RDCMD1 EQU 10100001B

;WRITE DATA COMMAND Note 3 ;READ DATA COMMAND Note 3

RELAY BUZZER

EQU P2.7 EQU P2.4

; ***LCD CONTROL*** LCD_RS LCD_E EQU EQU P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 ;LCD REGISTER SELECT LINE ;LCD ENABLE LINE ;PORT 1 IS USED FOR DATA ;USED FOR DATA ;FOR DATA ;FOR DATA

LCD_DB4 EQU LCD_DB5 EQU LCD_DB6 EQU LCD_DB7 EQU

; ***CURSOR CONTROL INSTRUCTIONS***

OFFCUR

EQU

0CH 0DH

BLINKCUR EQU

; ***DISPLAY CONTROL INSTRUCTIONS***

CLRDSP ONDSP

EQU EQU

01H 0CH

82

; ***SYSTEM INSTRUCTIONS***

CONFIG

EQU 28H

; 4-BIT DATA,2 LINES,5X7 MATRIX LCD ; INCREMENT CURSOR DON'T SHIFT DISPLAY

ENTRYMODE EQU 6

DSEG ORG 20H

; This is internal data memory ; Bit adressable memory

FLAGS1:

DS

1 FLAGS1.0 BIT BIT FLAGS1.1

BCDCARRY BIT CARRY TBIT TBIT1

FLAGS1.2

BIT FLAGS1.3

READING: AMOUNT: COUNTER: TEMP: PRICE: BALANCE:

DS DS DS DS DS DS DS DS

2 3 2 1 2 1 1 3 1 1 1

BUZZ_COUNT: READ_BYTE: F1: F2: F3: DS DS DS

83

STACK: CSEG

DS

; Code begins here

; ---------==========----------==========---------=========--------; Main routine. Program execution starts here. ; ---------==========----------==========---------=========--------ORG 00H ; Reset

AJMP MAIN

ORG 0003H PUSH PSW PUSH ACC MOV PSW,#RB1 ; Select register bank 0

CALL INC_COUNTER POP ACC POP PSW RETI ; ---------==========----------==========---------=========--------MAIN: MOV SP,#50H MOV PSW,#RB0 MOV IE,#10000001B CALL RESETLCD4 CALL TITLE1 ; Select register bank 0

84

CLR BUZZER SETB RELAY CLR TBIT1 MOV BUZZ_COUNT,#00H MOV READ_BYTE,#0FFH

CALL READ_COUNTER MOV A,COUNTER CJNE A,#0FFH,BYPASS

CALL RESET_READING CALL RESET_AMT CALL RESET_COUNTER CALL RESET_PRICE CALL RESET_BALANCE ; ; CALL STORE_UNIT_PRICE CALL AMT_RECHARGE CALL SYSTEM_RESET CALL DELAYYS ;RELAY ON/OFF BYTE

BYPASS: CALL READ_COUNTER CALL READ_PRICE CALL READ_BALANCE

85

MAINS:

CALL TITLE1 CALL DELAYY

MOV A,BALANCE CJNE A,#00H,FG1 CLR RELAY CALL RECHAGRE CALL DELAYY SETB BUZZER AJMP MAINS

FG1:

SETB RELAY MOV A,BUZZ_COUNT ;CHK TO SWITCH OFF

THE BUZZER CJNE A,#00H,AZX1 CLR BUZZER AJMP AZX2 AZX1: AZX2: MOV R1,#READING DATA IN BYTES(RAM) MOV R4,#05H ADDRESS IN EEPROM ;DATA ;GET DEC BUZZ_COUNT

86

MOV R6,#2 BYTES CALL READ_EEPROM CALL DISP_READING MOV TEMP,READING CALL SEP_DISP MOV TEMP,READING+1 CALL SEP_DISP

;NUMBER

OF

CALL DELAYY

MOV R1,#AMOUNT BYTES(RAM) MOV R4,#0AH ADDRESS IN EEPROM MOV R6,#3 BYTES CALL READ_EEPROM CALL AMT_READING MOV TEMP,AMOUNT CALL SEP_DISP MOV TEMP,AMOUNT+1 CALL SEP_DISP MOV R4,#'.' CALL WRLCDDATA

;GET DATA IN

;DATA

;NUMBER

OF

87

CALL MDELAY MOV TEMP,AMOUNT+2 CALL SEP_DISP

CALL DELAYY MOV R1,#COUNTER DATA IN BYTES(RAM) MOV R4,#0EH ADDRESS IN EEPROM MOV R6,#2 BYTES CALL READ_EEPROM CALL COUNT_READING MOV TEMP,COUNTER CALL SEP_DISP MOV TEMP,COUNTER+1 CALL SEP_DISP ;NUMBER OF ;DATA ;GET

CALL DELAYY MOV R1,#PRICE BYTES(RAM) MOV R4,#10H ADDRESS IN EEPROM ;DATA ;GET DATA IN

88

MOV R6,#2 BYTES CALL READ_EEPROM

;NUMBER

OF

CALL READ_PRICE CALL UNIT_PRICE MOV A,PRICE ADD A,#30h MOV R4,A CALL WRLCDDATA CALL MDELAY MOV R4,#'.' CALL WRLCDDATA CALL MDELAY MOV TEMP,PRICE+1 CALL SEP_DISP

CALL DELAYY AJMP MAINS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5

89

; ;

INCREMENT COUNTER BY 1 IF COUNT=3200 THEN INCREMENT READING

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5 INC_COUNTER: MOV A,COUNTER+1 ADD A,#01 DA A MOV COUNTER+1,A JNC DCV2 MOV A,COUNTER ADD A,#01 DA A MOV COUNTER,A CJNE A,#32h,DCV2 MOV COUNTER,#00H MOV COUNTER+1,#00H MOV R1,#COUNTER MOV R4,#0EH IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY AJMP DVB1 ;STORE 2 BYTES ;store COUNT ;Starting Address

90

DCV2:

MOV R1,#COUNTER MOV R4,#0EH

;store COUNT ;Starting Address

IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY RET ;STORE 2 BYTES

DVB1: MOV A,READING+1 ADD A,#01 DA A MOV READING+1,A JNC DCS1 MOV A,READING ADD A,#01 DA A MOV READING,A DCS1: MOV R1,#READING MOV R4,#05H IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY

;INCREMENT READING BY 1

;store READING ;Starting Address

;STORE 2 BYTES

91

MOV A,AMOUNT+2 ;SUBTRACT AMT0 FROM TOTAL0 CLR C SUBB A,PRICE+1 CALL BCD_CONV MOV AMOUNT+2,A MOV A,AMOUNT+1 ;SUBTRACT AMT1 FROM TOTAL1 SUBB A,PRICE CALL BCD_CONV MOV AMOUNT+1,A MOV A,AMOUNT AMT2 FROM TOTAL2 SUBB A,#00h CALL BCD_CONV MOV AMOUNT,A ;SUBTRACT

MOV R1,#AMOUNT MOV R4,#0AH IN EEPROM MOV R6,#3 CALL STORE_EEPROM CALL DELAY

;store AMOUNT ;Starting Address

;STORE 2 BYTES

MOV A,AMOUNT+1

92

CJNE A,#40H,FCX1 MOV BUZZ_COUNT,#02H SETB BUZZER FCX1: CJNE A,#38H,FAX1 MOV BUZZ_COUNT,#02H SETB BUZZER FAX1: CJNE A,#41H,FAAX1 MOV BUZZ_COUNT,#02H SETB BUZZER FAAX1: CJNE A,#20H,FCX2 MOV BUZZ_COUNT,#03H SETB BUZZER FCX2: CJNE A,#19H,FAX2 MOV BUZZ_COUNT,#03H SETB BUZZER FAX2: CJNE A,#21H,FAAX2 MOV BUZZ_COUNT,#03H SETB BUZZER FAAX2: CJNE A,#10H,FCX3 MOV BUZZ_COUNT,#04H SETB BUZZER FCX3: CJNE A,#11H,FCX4 MOV BUZZ_COUNT,#04H SETB BUZZER FCX4: CJNE A,#09H,FAX4

93

MOV BUZZ_COUNT,#04H SETB BUZZER FAX4: MOV A,AMOUNT+2 ;SUBTRACT AMT0 FROM TOTAL0 CLR C SUBB A,PRICE+1 CALL BCD_CONV MOV A,AMOUNT+1 ;SUBTRACT AMT1 FROM TOTAL1 SUBB A,PRICE MOV A,AMOUNT CLR TBIT JNC POP1

SETB TBIT POP1: CJNE A,#00H,BACK JNB TBIT, BACK MOV BALANCE,#00H MOV R1,#BALANCE MOV R4,#15H IN EEPROM MOV R6,#1 CALL STORE_EEPROM CALL DELAY ;STORE 2 BYTES ;store COUNT ;Starting Address

94

CLR RELAY SETB BUZZER BACK: RET

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&& BCD_CONV: CLR BCDCARRY CLR CARRY JNC LOP2 SETB CARRY LOP2: JNB AC,LOP1 SETB BCDCARRY CLR C SUBB A,#06H LOP1: JNB CARRY,LOP3 CLR C SUBB A,#60H LOP3: CLR C JNB CARRY,LOP4 SETB C LOP4: RET

;################################################# ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5 ; READ PULSE COUNTER FROM MEMORY

95

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5 READ_BALANCE: MOV R1,#BALANCE DATA IN BYTES(RAM) MOV R4,#15H ADDRESS IN EEPROM MOV R6,#1 BYTES CALL READ_EEPROM RET READ_COUNTER: MOV R1,#COUNTER DATA IN BYTES(RAM) MOV R4,#0EH ADDRESS IN EEPROM MOV R6,#2 BYTES CALL READ_EEPROM RET READ_PRICE: MOV R1,#PRICE BYTES(RAM) MOV R4,#10H ADDRESS IN EEPROM ;DATA ;GET DATA IN ;NUMBER OF ;DATA ;GET ;NUMBER OF ;DATA ;GET

96

MOV R6,#2 BYTES CALL READ_EEPROM RET

;NUMBER

OF

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5 SEP_DISP1: MOV A,AMOUNT ANL A,#0F0H SWAP A CJNE A,#00H,DAP1 MOV A,AMOUNT ANL A,#0FH AJMP DAP3

DAP1:

ADD A,#30H MOV R4,A

;BOTH NOT EQUAL TO ZERO

CALL WRLCDDATA CALL MDELAY DAP2: MOV A,AMOUNT ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY

97

DAP4:

MOV A,AMOUNT+1 ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A

CALL WRLCDDATA CALL MDELAY DAP5: MOV A,AMOUNT+1 ANL A,#0FH ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV R4,#'.' CALL WRLCDDATA CALL MDELAY MOV A,AMOUNT+2 ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV A,AMOUNT+2 ANL A,#0FH

98

ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY RET

DAP3:

CJNE A,#00H,DAP2 MOV A,AMOUNT+1 ANL A,#0F0H SWAP A CJNE A,#00H,DAP4 AJMP DAP5

;CHK 2 DIGIT

;CHK 3 DIGIT

SEP_DISP: MOV A,TEMP ANL A,#0F0H SWAP A ADD A,#30H MOV R4,A CALL WRLCDDATA CALL MDELAY MOV A,TEMP ANL A,#0FH ADD A,#30H

99

MOV R4,A CALL WRLCDDATA CALL MDELAY RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%5 AMT_RECHARGE: MOV READ_BYTE,#01H MOV READ_BYTE+1,#00H MOV READ_BYTE+2,#10H MOV R1,#READ_BYTE MOV R6,#3 MOV A,#WTCMD1 CALL OUTS MOV A,#20H CALL OUT BXLP: MOV A,@R1 CALL OUT INC R1 DJNZ R6,BXLP CALL STOP CALL DELAY RET ;store COUNT ;STORE 2 BYTES ;LOAD WRITE COMMAND ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT ;GET DATA ;SEND IT ;INCREMENT DATA POINTER ;LOOP TILL DONE ;SEND STOP CONDITION

STORE_UNIT_PRICE:

100

MOV READ_BYTE,#00H MOV READ_BYTE+1,#01H MOV READ_BYTE+2,#00H MOV R1,#READ_BYTE MOV R6,#3 MOV A,#WTCMD1 CALL OUTS MOV A,#20H CALL OUT BALP: MOV A,@R1 CALL OUT INC R1 DJNZ R6,BALP CALL STOP CALL DELAY RET ;store COUNT ;STORE 2 BYTES ;LOAD WRITE COMMAND ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT ;GET DATA ;SEND IT ;INCREMENT DATA POINTER ;LOOP TILL DONE ;SEND STOP CONDITION

RESET_BALANCE: MOV BALANCE,#0FFH MOV R1,#BALANCE MOV R4,#15H IN EEPROM MOV R6,#1 CALL STORE_EEPROM CALL DELAY ;STORE 2 BYTES ;store COUNT ;Starting Address

101

RET RESET_PRICE: MOV PRICE,#02H MOV PRICE+1,#00H MOV R1,#PRICE MOV R4,#10H IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY RET ;STORE 2 BYTES ;store COUNT ;Starting Address

RESET_COUNTER: MOV COUNTER,#00H MOV COUNTER+1,#10H MOV R1,#COUNTER MOV R4,#0EH IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY RET ;STORE 2 BYTES ;store COUNT ;Starting Address

RESET_AMT: MOV AMOUNT,#00H ;

102

MOV AMOUNT+1,#05H MOV AMOUNT+2,#00H MOV R1,#AMOUNT MOV R4,#0AH IN EEPROM MOV R6,#3 CALL STORE_EEPROM CALL DELAY RET RESET_READING: MOV READING,#00H MOV READING+1,#05H MOV R1,#READING MOV R4,#05H IN EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAY RET ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;STORE 2 BYTES ;store READING ;Starting Address ;STORE 2 BYTES ;store READING ;Starting Address

DELAYY: MOV F1,#0FH SEP3: MOV F2,#0fFH SEP2: MOV F3,#0FFH

103

SEP1: DJNZ F3,SEP1 DJNZ F2,SEP2 CALL CARD_READ MOV A,READ_BYTE CJNE A,#0FFH,DSP1 CLR TBIT1 DSP3A:DJNZ F1,SEP3 RET

DELAYYS: MOV F1,#0FH S5P3: MOV F2,#0fFH S5P2: MOV F3,#0FFH S5P1: DJNZ F3,S5P1 DJNZ F2,S5P2 DJNZ F1,S5P3 RET

DSP1: JB TBIT1,DSP3A CALL TITLE3 CALL DELAYS CALL DELAYS CALL CARD_READ MOV A,READ_BYTE

104

CJNE A,#00H,DSP2 CALL TITLE4 ; NEW UNIT PRICE

MOV PRICE,READ_BYTE+1 MOV PRICE+1,READ_BYTE+2 MOV R1,#PRICE MOV R4,#10H EEPROM MOV R6,#2 CALL STORE_EEPROM CALL DELAYS SETB TBIT1 AJMP RESETX_CHIP ;STORE 2 BYTES ;store COUNT ;Starting Address IN

DSP2: CJNE A,#01H,DSP3 CALL TITLE5 ; MOV R1,#AMOUNT ; NEW RECHARGE ;GET DATA IN

BYTES(RAM) ; MOV R4,#0AH ;DATA

ADDRESS IN EEPROM ; BYTES ; CALL READ_EEPROM MOV R6,#03h ;NUMBER OF

MOV A,AMOUNT ADD A,READ_BYTE+1

105

DA A MOV AMOUNT,A MOV A,AMOUNT+1 ADDC A,READ_BYTE+2 DA A MOV AMOUNT+1,A MOV R1,#AMOUNT MOV R4,#0AH EEPROM MOV R6,#03h CALL STORE_EEPROM CALL DELAYS SETB TBIT1 CALL RESET_BALANCE ;STORE 2 BYTES ;store READING ;Starting Address IN

RESETX_CHIP: MOV READ_BYTE,#0AAH MOV READ_BYTE+1,#0FFH MOV READ_BYTE+2,#0FFH MOV R1,#READ_BYTE MOV R6,#3 MOV A,#WTCMD1 CALL OUTS MOV A,#20H CALL OUT ;store COUNT ;STORE 2 BYTES ;LOAD WRITE COMMAND ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT ;ERASE AMOUNT

106

BBLP:

MOV A,@R1 CALL OUT INC R1 DJNZ R6,BBLP CALL STOP CALL DELAY RET

;GET DATA ;SEND IT ;INCREMENT DATA POINTER ;LOOP TILL DONE ;SEND STOP CONDITION

DSP3: CJNE A,#0AAH,DSP4 CALL TITLE6 CALL DELAYS SETB TBIT1 DSP4: RET ; NEW RECHARGE

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAY: MOV R6,#0FFH RE1: MOV R7,#0FFH RE: NOP DJNZ R7,RE DJNZ R6,RE1 RET ;**********************************************************

CARD_READ:

107

MOV R1,#READ_BYTE DATA IN BYTES(RAM) MOV R6,#3 BYTES MOV A,#WTCMD1 ADDRESS CALL OUTS MOV A,#20H CALL OUT MOV A,#RDCMD1 CALL OUTS BXDLP: CALL IN MOV @R1,a INC R1 DJNZ R6,AXLP CALL STOP RET AXLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 NOP ;NOTE 1 NOP NOP NOP ;NOTE 2 NOP CLR SCL1 ;SEND IT

;GET

;NUMBER

OF

;LOAD WRITE COMMAND TO SEND

;GET LOW BYTE ADDRESS ;SEND IT ;LOAD READ COMMAND ;SEND IT ;READ DATA ;STORE DATA ;INCREMENT DATA POINTER ;DECREMENT LOOP COUNTER ;IF DONE, ISSUE STOP CONDITION ;DONE, EXIT ROUTINE

108

JMP BXDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; READ DATA FROM EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% READ_EEPROM: MOV A,#WTCMD ADDRESS CALL OUTS MOV A,R4 CALL OUT MOV A,#RDCMD CALL OUTS BRDLP: CALL IN MOV @R1,a INC R1 DJNZ R6,AKLP CALL STOP RET AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK SETB SCL1 NOP ;NOTE 1 NOP NOP ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT ;LOAD READ COMMAND ;SEND IT ;READ DATA ;STORE DATA ;INCREMENT DATA POINTER ;DECREMENT LOOP COUNTER ;IF DONE, ISSUE STOP CONDITION ;DONE, EXIT ROUTINE ;LOAD WRITE COMMAND TO SEND

109

NOP ;NOTE 2 NOP CLR SCL1 JMP BRDLP ;CONTINUE WITH READS ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; STORE DATA IN EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

STORE_EEPROM: MOV A,#WTCMD CALL OUTS MOV A,R4 CALL OUT BTLP: MOV A,@R1 CALL OUT INC R1 DJNZ R6,BTLP CALL STOP RET ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;GET DATA ;SEND IT ;INCREMENT DATA POINTER ;LOOP TILL DONE ;SEND STOP CONDITION ;LOAD WRITE COMMAND ;SEND IT ;GET LOW BYTE ADDRESS ;SEND IT

110

;########################################################## ; DISPLAY ROUTINES

;########################################################## TITLE1: MOV DPTR,#MSAG1 CALL LCD_MSG RET MSAG1: DB 1H,84H,'PREPAID',0C2H,'ENERGY METER',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISP_READING: MOV DPTR,#MSAG2 CALL LCD_MSG RET MSAG2: DB 1H,82H,'METER READING',0C6H,00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AMT_READING: MOV DPTR,#MSAG3 CALL LCD_MSG RET MSAG3: DB 1H,81H,'BALANCE AMOUNT',0C3H,'Rs.',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ COUNT_READING:

111

MOV DPTR,#MSAG4 CALL LCD_MSG RET MSAG4: DB 1H,82H,'PULSE COUNT',0C6H,00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UNIT_PRICE: MOV DPTR,#MSAG14 CALL LCD_MSG RET MSAG14: DB 1H,83H,'UNIT PRICE',0C4H,'Rs ',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RECHAGRE: MOV DPTR,#MSAG5 CALL LCD_MSG RET MSAG5: DB 1H,80H,'Please Recharge',0C2H,'your Account',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE3: MOV DPTR,#MSAG6 CALL LCD_MSG RET MSAG6:

112

DB 1H,84H,'New Card',0C1H,'** DETECTED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE4: MOV DPTR,#MSAG7 CALL LCD_MSG RET MSAG7: DB 1H,81H,'NEW UNIT PRICE',0C1H,'** STORED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE5: MOV DPTR,#MSAG8 CALL LCD_MSG RET MSAG8: DB 1H,83H,'NEW AMOUNT',0C1H,'** RECHARGED **',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TITLE6: MOV DPTR,#MSAG9 CALL LCD_MSG RET MSAG9: DB 1H,82H,'INVALID CARD',0C0H,'****************',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SYSTEM_RESET: MOV DPTR,#MSAG91

113

CALL LCD_MSG RET MSAG91: DB 1H,80H,'System Restored',0C0H,'****************',00H ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;********************************************************** ; INITIALIZE THE LCD 4-BIT MODE ;********************************************************** INITLCD4: CLR CLR MOV LCD_RS LCD_E ; LCD REGISTER SELECT LINE ; ENABLE LINE

R4, #CONFIG; FUNCTION SET - DATA BITS, ; LINES, FONTS

CALL MOV CALL MOV CALL MOV CALL RET

WRLCDCOM4 R4, #ONDSP ; DISPLAY ON WRLCDCOM4 R4, #ENTRYMODE ; SET ENTRY MODE WRLCDCOM4 ; INCREMENT CURSOR RIGHT, NO SHIFT R4, #CLRDSP; CLEAR DISPLAY, HOME CURSOR WRLCDCOM4

; ********************************************************** ; SOFTWARE VERSION OF THE POWER ON RESET ; ********************************************************** RESETLCD4:

114

CLR CLR CLR CLR SETB SETB SETB CLR MOV CALL SETB CLR MOV CALL SETB CLR MOV CALL CLR SETB CLR MOV CALL MOV CALL

LCD_RS LCD_E LCD_DB7 LCD_DB6 LCD_DB5 LCD_DB4 LCD_E LCD_E A, #4

; LCD REGISTER SELECT LINE ; ENABLE LINE ; SET BIT PATTERN FOR... ; ... POWER-ON-RESET

; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 4 MILLISECONDS

MDELAY LCD_E LCD_E A, #1 ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND

MDELAY LCD_E LCD_E A, #1 ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND

MDELAY LCD_DB4 LCD_E LCD_E A, #1 ; SPECIFY 4-BIT OPERATION ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND

MDELAY R4, #CONFIG; FUNCTION SET WRLCDCOM4

115

MOV CALL MOV CALL MOV ACALL

R4, #08H ; DISPLAY OFF WRLCDCOM4 R4, #1 ; CLEAR DISPLAY, HOME CURSOR

WRLCDCOM4 R4,#ENTRYMODE ; SET ENTRY MODE WRLCDCOM4

JMP INITLCD4

; ********************************************************** ; SUB RECEIVES A COMMAND WORD TO THE LCD ; COMMAND MUST BE PLACED IN R4 BY CALLING PROGRAM ; ********************************************************** WRLCDCOM4: CLR CLR PUSH MOV MOV MOV MOV MOV MOV MOV MOV MOV LCD_E LCD_RS ACC A, R4 ; SELECT READ COMMAND ; SAVE ACCUMULATOR ; PUT DATA BYTE IN ACC

C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS LCD_DB4, C ; ONE BIT AT A TIME USING... C, ACC.5 ; BIT MOVE OPERATOINS LCD_DB5, C C, ACC.6 LCD_DB6, C C, ACC.7 LCD_DB7, C

116

SETB CLR MOV MOV MOV MOV MOV MOV MOV MOV CLR SETB CLR

LCD_E LCD_E

; PULSE THE ENABLE LINE

C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE LCD_DB4, C C, ACC.1 LCD_DB5, C C, ACC.2 LCD_DB6, C C, ACC.3 LCD_DB7, C LCD_E LCD_E LCD_E ; PULSE THE ENABLE LINE

CALL MADELAY POP RET ; ********************************************************** ; SUB TO RECEIVE A DATA WORD TO THE LCD ; DATA MUST BE PLACED IN R4 BY CALLING PROGRAM ; ********************************************************** WRLCDDATA: CLR SETB PUSH MOV LCD_E LCD_RS ACC A, R4 ; SELECT READ DATA ; SAVE ACCUMULATOR ; PUT DATA BYTE IN ACC ACC

117

MOV MOV MOV MOV MOV MOV MOV MOV SETB CLR MOV MOV MOV MOV MOV MOV MOV MOV CLR SETB CLR NOP NOP POP RET

C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS LCD_DB4, C ; ONE BIT AT A TIME USING... C, ACC.5 ; BIT MOVE OPERATOINS LCD_DB5, C C, ACC.6 LCD_DB6, C C, ACC.7 LCD_DB7, C LCD_E LCD_E C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE LCD_DB4, C C, ACC.1 LCD_DB5, C C, ACC.2 LCD_DB6, C C, ACC.3 LCD_DB7, C LCD_E LCD_E LCD_E ; PULSE THE ENABLE LINE ; PULSE THE ENABLE LINE

ACC

118

; ********************************************************** ; SUB TAKES THE STRING IMMEDIATELY FOLLOWING THE CALL AND ; DISPLAYS ON THE LCD. STRING MUST BE TERMINATED WITH A ; NULL (0). ; ********************************************************** LCD_MSG: CLR A MOVC A,@A+DPTR INC DPTR JZ LCD_Msg9 CJNE A,#01H,Lcd_Msg1 MOV R4,A CALL WRLCDCOM4 JMP LCD_MSG ;If yes, RECEIVE it as command to LCD ;Go get next byte from stringz ; Clear Index ; Get byte pointed by Dptr ; Point to the next byte ; Return if found the zero (end of stringz) ; Check if is a Clear Command

Lcd_Msg1: CJNE A,#0FFH,FLL MOV R4,A CALL WRLCDDATA JMP LCD_MSG FLL: CJNE A,#080h,$+3 JC Lcd_Msg_Data

;Check for displaying full character

; Data or Address? If => 80h then is address. ; Carry will be set if A < 80h (Data)

MOV R4,A CALL WRLCDCOM4 JMP Lcd_Msg ; Carry not set if A=>80, it is address

; Go get next byte from stringz

119

Lcd_Msg_Data: MOV R4,A

CALL WRLCDDATA JMP Lcd_Msg Lcd_Msg9:

; It was data, RECEIVE it to Lcd ; Go get next byte from stringz

RET

; Return to Caller

; ********************************************************** ; 1 MILLISECOND DELAY ROUTINE ; **********************************************************

MDELAY: PUSH MOV MD_OLP: INC NOP NOP NOP NOP NOP NOP NOP A ACC A,#0A6H

120

NOP JNZ NOP POP RET MADELAY: PUSH MOV MAD_OLP: INC NOP NOP NOP NOP NOP NOP NOP NOP JNZ NOP POP RET ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DELAYS: MOV R6, #00H ;One second delay routine ;put 0 in register R6 (R6 = 0) ACC MAD_OLP A ACC A,#036H ACC MD_OLP

121

MOV R5, #04H LOOPB: INC R6

;put 5 in register R5 (R5 = 4)

;increase R6 by one (R6 = R6 +1) ;call the routine above. It will run and return to here. ;move value in R6 to A ;if A is not 0, go to LOOPB ;decrease R5 by one. (R5 = R5 -1) ;move value in R5 to A ;if A is not 0 then go to LOOPB.

ACALL DELAYMS MOV A, R6 JNZ LOOPB DEC R5 MOV A, R5 JNZ LOOPB RET

;************************************************************************** DELAYMS: ; MOV R7,#00H LOOPA: INC R7 MOV A,R7 ;increase R7 by one (R7 = R7 +1) ;move value in R7 to Accumlator (also known as A) ;compare A to FF hex (256). If not equal go to LOOPA ; ;put value of 0 in register R7 ;millisecond delay routine

CJNE A,#0FFH,LOOPA RET

;return to the point that this routine was called from

;**************************************************************************

;*********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR ; to the EEPROM and includes START condition. Refer to the data sheets ; for discussion of START and STOP conditions.

122

;***********************************************************************

OUTS: MOV

R2,#8

;LOOP COUNT -- EQUAL TO BIT COUNT ;INSURE DATA IS HI ;INSURE CLOCK IS HI

SETB SDA1 SETB SCL1 NOP NOP NOP CLR NOP NOP NOP CLR SCL1 A SDA1

;NOTE 1

;START CONDITION -- DATA = 0 ;NOTE 1

;CLOCK = 0 ;SHIFT BIT

OTSLP: RLC JNC

BITLS ;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI

SETB SDA1 JMP OTSL1 SDA1

BITLS: CLR

OTSL1: SETB SCL1 NOP NOP NOP

;NOTE 1

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER

DJNZ R2,OTSLP

123

SETB SDA1 NOP

;TURN PIN INTO INPUT ;NOTE 1

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

CLR RET

SCL1

;********************************************************************** ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM ; without sending a START condition. ;**********************************************************************

OUT:

MOV

R2,#8 A

;LOOP COUNT -- EQUAL TO BIT COUNT ;SHIFT BIT

OTLP: RLC JNC

BITL ;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI ;NOTE 1

SETB SDA1 JMP OTL1 SDA1

BITL: CLR

OTL1: SETB SCL1 NOP NOP

124

NOP

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER ;TURN PIN INTO INPUT ;NOTE 1

DJNZ R2,OTLP SETB SDA1 NOP

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

CLR RET

SCL1

STOP: CLR NOP NOP NOP

SDA1

;STOP CONDITION SET DATA LOW ;NOTE 1

SETB SCL1 NOP NOP NOP

;SET CLOCK HI ;NOTE 1

125

SETB SDA1 RET

;SET DATA HIGH

;******************************************************************* ; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM ; From EEPROM current address pointer. ; Returns the data byte in R1 ;******************************************************************* CREAD: MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS CALL IN MOV R1,A

;SEND IT ;READ DATA ;STORE DATA ;SEND STOP CONDITION

CALL STOP RET

;********************************************************************** ; THIS ROUTINE READS IN A BYTE FROM THE EEPROM ; and stores it in the accumulator ;**********************************************************************

IN:

MOV

R2,#8

;LOOP COUNT ;SET DATA BIT HIGH FOR INPUT ;CLOCK LOW ;NOTE 1

SETB SDA1 INLP: CLR NOP NOP SCL1

126

NOP NOP

SETB SCL1 CLR JNB CPL C

;CLOCK HIGH ;CLEAR CARRY ;JUMP IF DATA = 0

SDA1,INL1 C A

;SET CARRY IF DATA = 1 ;ROTATE DATA INTO ACCUMULATOR ;DECREMENT COUNTER ;CLOCK LOW

INL1: RLC

DJNZ R2,INLP CLR RET SCL1

;********************************************************************* ; This routine test for WRITE DONE condition ; by testing for an ACK. ; This routine can be run as soon as a STOP condition ; has been generated after the last data byte has been sent ; to the EEPROM. The routine loops until an ACK is received from ; the EEPROM. No ACK will be received until the EEPROM is done with ; the write operation. ;********************************************************************* ACKTST: MOV MOV CLR NOP A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS

R2,#8 SDA1

;LOOP COUNT -- EQUAL TO BIT COUNT ;START CONDITION -- DATA = 0 ;NOTE 1

127

NOP NOP

CLR

SCL1 A

;CLOCK = 0 ;SHIFT BIT

AKTLP: RLC JNC

AKTLS ;DATA = 1 ;CONTINUE ;DATA = 0 ;CLOCK HI

SETB SDA1 JMP AKTL1 SDA1

AKTLS: CLR

AKTL1: SETB SCL1 NOP NOP NOP

;NOTE 1

CLR

SCL1

;CLOCK LOW ;DECREMENT COUNTER ;TURN PIN INTO INPUT ;NOTE 1

DJNZ R2,AKTLP SETB SDA1 NOP

SETB SCL1 NOP NOP NOP

;CLOCK ACK ;NOTE 1

JNB

SDA1,EXIT

;EXIT IF ACK (WRITE DONE)

128

JMP

ACKTST SCL1

;START OVER ;CLOCK LOW ;DATA LOW ;NOTE 1

EXIT: CLR CLR NOP NOP NOP

SDA1

SETB SCL1 NOP NOP SETB SDA1 RET

;CLOCK HIGH

;STOP CONDITION

;********************************************************************* END

(14.)Main manufacturer:Several companies have started high volume production of Pre-paid energy meter. Some of the best known industry given below : TRADEKEY
129

INDOTECH SKN GROUP OF COMPANY KARIGHAR R&D CENTER DAE INSTRUMENT CROP. RAMA. LTD

Reference
Internet www.how-an-pre-paid-energy-works.com www.engineersgarage.com www.ieeespectrum.com www.en.wikipedia.org www.pdf-search-engine.com
130

131

You might also like