Professional Documents
Culture Documents
Design and Implementation of Low Cost D
Design and Implementation of Low Cost D
INTRODUCTION
Secondary:
12V-0-12V
1A/50Hz
GSM SIM900
3.3V/1A
AT Commands
FAN(BLDC MOTOR) 5v/100Ma
BUZZER Sound 5dB
5V/30mA
TEMPERATURE SENSOR LM35
Voltage +35V to −0.2V
Output Voltage +6V to −1.0V
Output Current 10 Ma
Storage Temp.;
TO-46 Package, −60˚C to +180˚C
TO-92 Package, −60˚C to +150˚C
TO-8 Package, −65˚C to +150˚C
TO-220 Package, −65˚C to +150˚C
VOLTAGE SENSOR
GEAR MOTORS 60RPM 12V/1A/50Hz
Department of EEE, TOCE - 2016 Page 5
60RPM 12V/1A/50Hz
10RPM 12V/1A/50Hz
MICROCONTROLLER
LCD DISPLAY 16×2 Text type LCD
RELAY Single channel ,5V/42mA
FIG.2.2.PSU
Circuit performance:
Very stable +5V output voltage, reliable operation Availability of components: Easy to get, uses only very
common basic components Design testing: Based on datasheet example circuit, I have used this circuit
however, notice that, in our case we have a more sophisticated rectifier ( Diode bridge) which gives a full-wave
rectified output. So, the discharge time will be
Now, at the beginning of each discharge period our capacitor is charged up to Vmax=15V. In order to prevent our
capacitor voltage going below Vmin = 7 V (which is the lowest input operating point for LM7805 voltage
regulator) in the end of the discharge period, our capacitor value should be chosen with the equation:
C >= (I_max*T_discharge)/(V_beforedischarge-V_afterdischarge)
We can see that if we use a step down transformer which reduces the 230 V input into 20 V instead of 15 V and if
your power supply will require at most Imax = 0.5 A current, we can use an even smaller capacitance with the
value: Cmin = (0.5 A)*(8.3 ms)/(20 V - 7 V) = 0.32 mF
we can see an example design which uses LM7805 just like you are, and they picked a capacitor value of 0.47
mF, which is close to the values we calculated above.Capacitor value should be large enough that it can provide
enough voltage(+2 volts means 7v for 7805) to the regulator IC, means voltage across capacitor should not go
below 7v. I have found a article where Capacitance calculation has been explained well,it may be useful for
others,
Circuit description
This circuit is a small +5V power supply, which is useful when experimenting with digital electronics, and
easy to build. Small inexpensive wall tranformers with variable output voltage are available from any electronics
shop and supermarket. Those transformers are easily available, but usually their voltage regulation is very poor,
which makes then not very usable for digital circuit experimenter unless a better regulation can be achieved in
some way. The following circuit is the answer to the problem.
This circuit can give +5V output at about 150 mA current, but it can be increased to 1 A when good cooling
is added to 7805 regulator chip. The circuit has over overload and terminal protection.
The capacitors must have enough high voltage rating to safely handle the input voltage feed to circuit. The circuit
is very easy to build for example into a piece of veroboard
Component list
1. 7805 regulator IC
2. 100 uF electrolytic capacitor, at least 25V voltage rating
3. 10 uF electrolytic capacitor, at least 6V voltage rating
4. 100 nF ceramic or polyester capacitor
5. If you need more than 150 mA of output current, you can update the output current up to 1A doing the
following modifications.
6. Change the transformer from where you take the power to the circuit to a model which can give as much
current as you need from output.
7. Put a heatsink to the 7805 regulator (so big that it does not overheat because of the extra losses in the
Department of EEE, TOCE - 2016 Page 9
regulator)
The Cooling Fans are designed for long and dependable service for use in cooling transformers
and other equipment. The Fans are intended mainly for outside use and are designed and
manufactured to withstand harsh weather conditions. They have an excellent performance record
and proven reliability. These are operated only if transformer gets overheated ,the program is
made to run the fan for the predefined voltage practically these fans are fitted to transformers as
shown in below figure.
Pin Diagram:
GSM (Global System for Mobile) / GPRS (General Packet Radio Service) TTL -Modem is SIM900 Quad-
band GSM / GPRS device, works on frequencies 850 MHZ, 900 MHZ, 1800 MHZ and 1900 MHZ. It is very
compact in size and easy to use as plug in GSM Modem. The Modem is designed with 3V3 and 5V DC TTL
interfacing circuitry, which allows User to directly interface with 5V Microcontrollers (PIC, AVR, Arduino, 8051,
etc.) as well as 3V3 Microcontrollers (ARM, ARM Cortex XX, etc.). The baud rate can be configurable from
9600115200 bps through AT (Attention) commands. This GSM/GPRS TTL Modem has internal TCP/IP stack to
enable User to connect with internet through GPRS feature. It is suitable for SMS as well as DATA transfer
application in mobile phone to mobile phone interface. The modem can be interfaced with a Microcontroller using
USART (Universal Synchronous Asynchronous Receiver and Transmitter) feature (serial communication). Global
system for mobile communication (GSM) is a globally accepted standard for digital cellular communication. GSM is
the name of a standardization group established in 1982 to create a common European mobile telephone standard that
would formulate specifications for a pan-European mobile cellular radio system operating at 900 MHz. It is
estimated that many countries outside of Europe will join the GSM Partnership. GSM was devised as a cellular
system specific to the 900 MHz band, called "The Primary Band". The primary band includes two sub bands of 25
MHz each, 890 to 915 MHz and 935 MHz to 960 MHz. GSM-PLMN has allocated 124 duplex carrier frequencies
over the following bands of operation.
The mobile station (MS) consists of the mobile equipment (the terminal) and a smart card called the Subscriber
Identity Module (SIM). The SIM provides personal mobility, so that the user can have access to subscribed services
irrespective of a specific terminal. By inserting the SIM card into another GSM terminal, the user is able to receive
calls at that terminal, make calls from that terminal, and receive other subscribed services.
The mobile equipment is uniquely identified by the International Mobile Equipment Identity (IMEI). The SIM
card contains the International Mobile Subscriber Identity (IMSI) used to identify the subscriber to the system, a
secret key for authentication, and other information. The IMEI and the IMSI are independent, thereby allowing
personal mobility. The SIM card may be protected against unauthorized use by a password or personal identity
number.
The Base Station Subsystem is composed of two parts, the Base Transceiver Station (BTS) and the Base Station
Controller (BSC). These communicate across the standardized Abis interface, allowing (as in the rest of the system)
operation between components made by different suppliers.
The Base Transceiver Station houses the radio transceivers that define a cell and handles the radio-link
protocols with the Mobile Station. In a large urban area, there will potentially be a large number of BTSs
deployed, thus the requirements for a BTS are ruggedness, reliability, portability, and minimum cost.
Network Subsystem
The central component of the Network Subsystem is the Mobile services Switching Center (MSC). It acts like
a normal switching node of the PSTN or ISDN, and additionally provides all the functionality needed to handle a
mobile subscriber, such as registration, authentication, location updating, handovers, and call routing to a roaming
subscriber. The MSC provides the connection to the fixed networks (such as the PSTN or ISDN). Signaling between
functional entities in the Network Subsystem uses Signaling System Number 7 (SS7), used for trunk signaling in
ISDN and widely used in current public networks.
The Home Location Register (HLR) and Visitor Location Register (VLR), together with the MSC,
provide the call-routing and roaming capabilities of GSM. The HLR contains all the administrative
information of each subscriber registered in the corresponding GSM network, along with the current
location of the mobile. The location of the mobile is typically in the form of the signalling address of the
VLR associated with the mobile station. There is logically one HLR per GSM network, although it may be
implemented as a distributed database.
The Visitor Location Register (VLR) contains selected administrative information from the HLR,
necessary for call control and provision of the subscribed services, for each mobile currently located in the
geographical area controlled by the VLR. The geographical area controlled by the MSC corresponds to that
controlled by the VLR. Note that the MSC contains no information about particular mobile stations --- this
information is stored in the location registers.
The other two registers are used for authentication and security purposes. The Equipment Identity
Register (EIR) is a database that contains a list of all valid mobile equipment on the network, where each
mobile station is identified by its International Mobile Equipment Identity (IMEI). An IMEI is marked as
invalid if it has been reported stolen or is not type approved. The Authentication Center (AuC) is a
protected database that stores a copy of the secret key stored in each subscriber's SIM card, which is used
for authentication and encryption over the radio channel.
Hardware Description
This is actual SIM900 GSM module which is manufactured by SIMCom. Designed for global market,
SIM900 is a quad-band GSM/GPRS engine that works on frequencies GSM 850MHz, EGSM 900MHz,
DCS 1800MHz and PCS 1900MHz. SIM900 features GPRS multislot class 10/ class 8 (optional) and
supports the GPRS coding schemes CS-1, CS-2, CS-3 and CS-4. With a tiny configuration of 24mm x
24mm x 3mm, SIM900 can meet almost all the space requirements in User’s applications, such as M2M,
smart phone, PDA and other mobile devices.
MAX232 IC:
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port to signals
suitable for use in TTL compatible digital logic circuits, so that devices works on TTL logic can share the
data with devices connected through Serial port (DB9 Connector).
This power supply socket which actually named as AC/DC Socket provides the functionality to user to
connect external power supply from Transformer, Battery or Adapter through DC jack. User can provide
maximum of 12V AC/DC power supply through AC/DC socket. This is power supply designed into
maximum protection consideration so that it can even prevent reverse polarity DC power supply as well as
DC conversion from AC power Supply. It also includes LM317 Voltage Regulator which provides an
output voltage adjustable over a1.2V to 37
Power On/Off switch is type of push-on push-off DPDT switch which is used for only make power
supply on/off provided through AC/DC Socket indicated by ‘Power LED’. GSM On Switch is type of Push
on DPST tactile switch which is used for only to make GSM module ‘On’ indicated by ‘Module On/Off
LED’ while initiating with Network indicated by ‘Network Indication LED’.
This onboard SIM card slot provide User functionality of insert a SIM (GSM only) card of any
service provider. Process of inserting and locking SIM card into SIM card slot is given in this manual.
While inserting in and removing out SIM card from SIM card slot, User needs to take precaution that
power supply should be OFF so that after making Power supply ON it will be easy to reinitialize with SIM
for this module.
Indicator LEDs:
Indicator LEDs just used to indicate status accordingly. These are three LEDs represents Power
On/Off Status, Network Status and Module On/Off Status respectively. Power LED will keep on until the
power supply is enable to this board by using push-on push-off switch. Network Status LED will show
whether inserted SIM card successfully connected to service provider’s Network or not, in short signal
strength. Module On/Off indicator LED will show status of GSM module’s power on/off.
These pins are used to connect devices which needs to be connected to GSM module through USART
(Universal Synchronous Asynchronous Receiver and Transmitter) communication. Devices may be like
Desktop or Laptop Computer System, Microcontrollers, etc. RXD (Receive Data) should be connected to
TXD (Transmit Data) of other device and viceversa, whereas GND (Ground) should be connected to other
device’s GND pin to make ground common for both systems
Audio Connectors:
Audio Connectors deals with Audio related operations. These pins already shown in hardware description
diagram. These are eight pins in a group of two each denoted by SV4. GND (0V Supply) and VCC (+5V Supply)
are used to have source for external device. MIC+ and MIC- used to connect Microphone (abbr. as Mic) through
which user can give audio input while calling. SP- and SP+ used to connect Speaker (can be connected to
amplifier circuit if necessary) through which User can hear audio output. LN-L and LN-R used to connect Line in
to GSM module.
Note: If message sending, receiving, calling functions are failed due to weak signal strength then User needs to
check SIM card’s service provider’s availability in coverage area, its not mean that GSM Module is not working
properly
Connecting GSM Module with Serial to USB converter through RXD, TXD and GND:
Connect three Single Berg Wires to CP2102 modules’s RXD, TXD and GND pin. Then connect RXD wire to
TXD of GSM module and TXD wire to RXD of GSM module. Make GND common by connecting GND wire to
GND pin of GSM module.
Testing GSM Module on Terminal Software: Terminal software used share the data through Serial port.
Hence here also User need this software to test GSM module. For demo purpose we are going to show demo for
how to send SMS and how to dial a call through ‘Realterm’ software. First of all install Realterm, it will create
its own shortcut on Desktop. Then double click on Realterm icon.
To initialize GSM module type ‘AT’ in capital letters and then press enter key on keyboard. If there are no errors
occur in this communication then it will send ‘OK
Relay Controller
This board allows you to control high voltage and high current loads with your microcontroller project. This
board is fully assembled with standard spaced mounting holes for easy integration into your new or existing
projects. Simply connect your low voltage and high voltage leads, and start controlling your robotics, household
automation, or other controller dependent projects right out of the box! This board is great for applications where
you want to safely isolate your microcontroller logic from your high voltage or high current circuits (and the
noise they create for) up to 2 channels. The Quick-Relay 2 board is small (2” x 2” x 0.75“ tall), with an integrated
circuit that protects your microcontroller from any kickback voltages that may occur from inductive loads in your
switched circuits. This board is capable of controlling two channels, using up to 12 volts to switch 120VAC,
Features:
• High quality components.
• Heavy duty PCB and traces to ensure reliable performance.
• High capacity connectors to accommodate larger gauge wire.
• Small form factor (2” x 2” x 0.75”) featuring four (4) 0.15” mounting holes.
• LED indicator for each channel
• Made in the U.S.A.
Specifications:
2.3.7. BUZZER
Features
sealed: yes
operating power: 3-6V DC / 25mA
extremely compact, ultrathin construction
no electrical noise
low current consumption yet high sound pressure level
Specifications
2.3.8 SENSORS
TEMPRATURE SENSOR(LM35)
PIN DIAGRAM:-
Pin Description:
LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor
circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can
be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than
0.1 oC temperature rise in still air.
The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to
every oC rise/fall in ambient temperature,i.e., its scale factor is 0.01V/ oC.
The LM35 can be applied easily in the same way as other integrated-circuit temperature sensors.
It can be glued or cemented to a surface and its temperature will be within about 0.01˚C of the
surface temperature. This presumes that the ambient air temperature is almost the same as the
surface temperature; if the air temperature were much higher or lower than the surface
temperature, the actual temperature of the LM35 die would be at an intermediate temperature
between the surface temperature and the air temperature. This is expecially true for the TO-92
plastic package, where the copper leads are the principal thermal path to carry heat into the
device, so its temperature might be closer to the air temperature than to the surface temperature.
To minimize this problem, be sure that the wiring to the LM35, as it leaves the device, is held at
the same temperature as the surface of interest. The easiest way to do this is to cover up these
These devices are sometimes soldered to a small light-weight heat fin, to decrease the
thermal time constant and speed up the response in slowly-moving air. On the other hand, a small
thermal mass may be added to the sensor, to give the steadiest reading despite small deviations in
the air temperature.
What is a Microcontroller?
A single chip computer or A CPU with all the peripherals like RAM, ROM, I/O Ports, Timers ,
ADCs etc... on the same chip. For ex: Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X etc…
A microcontroller is a highly integrated single chip, which consists of on chip CPU (Central Processing
Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable Programmable Read Only Memory),
I/O (input/output) – serial and parallel, timers, interrupt controller. For example, Intel 8051 is 8-bit
microcontroller and Intel 8096 is 16-bit microcontroller. The block diagram of Microcontroller is shown in Fig.2.
Description
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system
programmable Flash memory. The device is manufactured using Atmel’s high-density nonvolatile memory
technology and is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip Flash
allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory
programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the
Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to
many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash,
256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-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 operation down to zero frequency and supports two software selectable
2. Pin Configurations
Block Diagram
5. Port 2
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers cansink/source four TTL
inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pull-ups and can be used as inputs.
As inputs, Port 2 pins that are externally being pulled low will source current (I IL ) because of the internal
pullups.Port 2 emits the high-order address byte during fetches from external program memory and during
accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses
strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.Port 2 also receives the high-order
address bits and some control signals during Flash programming and verification.
Port Pin Alternate Functions
P1.0 T2 (external count input to Timer/Counter 2), clock-out
P1.1 T2EX (Timer/Counter 2 capture/reload trigger and direction control)
P1.5 MOSI (used for In-System Programming)
P1.6 MISO (used for In-System Programming)
P1.7 SCK (used for In-System Programming)
6. Port 3
Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL
inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pull-ups and can be used as inputs.
As inputs, Port 3 pins that are externally being pulled low will source current (I IL ) because of the pullups. Port 3
Department of EEE, TOCE - 2016 Page 40
receives some control signals for Flash programming and verification.Port 3 also serves the functions of various
special features of the AT89S52, as shown in the following table.
7. RST
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin
drives high for 98 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH)
can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.
8. ALE/PROG
Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during
accesses to external memory. This pin is also the program pulse input (PROG) during Flash
programming.In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator
frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is
skipped during each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of
SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin
is weakly pulled high Setting the ALE-disable bit has no effect if the microcontroller is in external execution
mode.
9. PSEN
Program Store Enable (PSEN) is the read strobe to external program memory.When the AT89S52 is executing
code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN
activations are skipped during each access to external data memory.
10. EA/VPP
Department of EEE, TOCE - 2016 Page 41
External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external
program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA
will be internally latched on reset. EA should be strapped to V CC for internal program executions.This pin also
receives the 12-volt programming enable voltage (V PP ) during Flash programming.
11. XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
12. XTAL2
Output from the inverting oscillator amplifier.
Timer 2 Registers:
Control and status bits are contained in registers T2CON (shown in Table 5-2) and T2MOD (shown in Table 10-
2) for Timer 2. The register pair (RCAP2H, RCAP2L) are the Capture/Reload registers for Timer 2 in 16-bit
capture mode or 16-bit auto-reload mode.Interrupt Registers: The individual interrupt enable bits are in the IE
register. Two priorities can be set for each of the six interrupt sources in the IP register
Memory Organization
MCS-51 devices have a separate address space for Program and Data Memory. Up to 64K
bytes each of external Program and Data Memory can be addressed.
Program Memory
If the EA pin is connected to GND, all program fetches are directed to external memory.On the AT89S52, if EA
Department of EEE, TOCE - 2016 Page 42
is connected to V CC , program fetches to addresses 0000H through 1FFFH are directed to internal memory and
fetches to addresses 2000H through FFFFH are to external memory.
Data Memory
The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the
Special Function Registers. This means that the upper 128 bytes have the same addresses as the SFR space but
are physically separate from SFR space.When an instruction accesses an internal location above address 7FH, the
address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR
space. Instructions which use direct addressing access the SFR space. For example, the following direct
addressing instruction accesses the SFR at location 0A0H(which is P2).
MOV 0A0H, #data
Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, thefollowing indirect
addressing instruction, where R0 contains 0A0H, accesses the data byte ataddress 0A0H, rather than P2 (whose
address is 0A0H).
MOV @R0, #data
Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available
as stack space.
UART
The UART in the AT89S52 operates the same way as the UART in the AT89C51 and AT89C52.
Timer 0 and 1
Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in the AT89C51 and
AT89C52
In the Counter function, the register is incremented in response to a 1-to-0 transition at its corresponding external
input pin, T2. In this function, the external input is sampled during S5P2 of every machine cycle. When the
samples show a high in one cycle and a low in the next cycle, The count is incremented. The new count value
appears in the register during S3P1 of the cycle following the one in which the transition was detected. Since two
machine cycles (24 oscillator periods) are required to recognize a 1-to-0 transition, the maximum count rate is
1/24 of the oscillator frequency. To ensure that a given level is sampled at least once before it changes, the
level should be held for at least one full machine cycle.
Capture Mode
In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 is a 16-bit timer
or counter which upon overflow sets bit TF2 in T2CON. This bit can then be used to generate an interrupt. If
EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0 transition at external input T2EX also causes the
current value in TH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, the transition
at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt. The capture
mode is illustrated in Figure 10-1.
Figure Timer 2 automatically counting up when DCEN = 0. In this mode, two options are selected by bit EXEN2
in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow
also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in
Timer in Capture ModeRCAP2H and RCAP2L are preset by software. If EXEN2 = 1, a 16-bit reload can be
triggered either by an overflow or by a 1-to-0 transition at external input T2EX. This transition also sets the EXF2
bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled. Setting the DCEN bit enables Timer 2 to
count up or down, as shown in Figure 10-2. In this mode, the T2EX pin controls the direction of the count. A
logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow
Interrupts
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts
(Timers 0, 1, and 2), and the serial port interrupt. These interrupts are all shown in Figure 13-1. Each of these
interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register
IE. IE also contains a global disable bit, EA, which disables all interrupts at once. Note that Table 13-1 shows that
bit position IE.6 is unimplemented. User software should not write a 1 to this bit position, since it may be used in
future AT89 products. Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON.
Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine
may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be
cleared in software.The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers
overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag,TF2, is set at
S2P2 and is polled in the same cycle in which the timer overflows.
sbit enable=P3^4;
sbit regsel=P3^5;
sbit SWITCH=P0^1;
sbit relay11=P0^7;
sbit fan=P0^5;
sbit m1=P2^0;
sbit m2=P2^1;
sbit m3=P2^2;
#define LCD_PORT P1
#define CLR_LCD cmd_lcd(0x01); delay_ms(5)
#define RETURN_HOME_LCD cmd_lcd(0x02); delay_ms(5)
void voltage()
{ int i;
for(i=0;i<=5;i++)
{
void temp()
{ int i;
for(i=15;i<=17;i++)
{
SBUF = v[i];
while(!TI);
TI = 0;
}
}
void receive_OK()
{
do
{
}while(ok!='K');
}
void check_sim_status()
{
cmd_lcd(0x01);
printlcd(" VERIFING FOR",0,0);
printlcd(" SIM",1,0);
delay_ms(3000);
transmit(CHECK_READY);
receive_OK();
}
void wait_for_prompt()
{
do
}while(enter!='>');
}
void send_sms()
{
cmd_lcd(0x01);
printlcd(" SENDING SMS TO",0,0);
printlcd("MAPPING SERVER",1,0);
delay_ms(3000);
transmit(SEND_SMS_CMD);
transmit(PHONE_NO);
transmit(END_SMS_CMD);
wait_for_prompt();
transmit("voltage: ");
voltage();
transmit(" volt ");
transmit(" ");
transmit("\r");
transmit("current: ");
current();
transmit(" mA ");
transmit(" ");
transmit("\r");
transmit("Temp: ");
temp();
transmit(" cel ");
transmit("\r");
void rx()interrupt 4
{
wordstr=SBUF;
if(wordstr=='K')
{ok='K'; RI=0; enter='M';}
else if(wordstr=='>')
{enter='>';RI=0; ok='k';}
if(wordstr=='N')
{relay11=1;RI=0;}
if(wordstr=='F')
{relay11=0;RI=0;}
RI=0;
serial_init();
transmit(MSG_FORMAT);
while(1)
{
cmd_lcd(0x01);
printlcd(" reading",0,0);
printlcd(" values",1,0);
delay_ms(3000);
delay_ms(3000);
i2c_read(0x9E,0x43,&d[0]); //read ADC RESULT from channel 0
PUT 0X44
i2c_read(0x9E,0x42,&d[1]);
i2c_read1(0x9E,0x41,&d[2]); //read ADC RESULT from channel 0
PUT 0X44
//i2c_read(0x9E,0x41,&d[3]);
delay_ms(3000);
printnum_lcd(d[0], 1, 6);
// printnum_lcdm(d[1], 0, 6);
printnum_lcd1(d[2], 1, 6);
// printnum_lcdm1(d[3], 0, 6);
if(d[2]>=40)
}
}
//----------------------------------Ascii to decimal--------------------------------------//
void printnum_lcd(unsigned char num, unsigned char row, unsigned char col)
{
void function()
{
f=a+b+c;
v[6]=f+0x30;
v[7]=0+0x30;
v[8]=0+0x30;
if(f==6)
{
relay11=1;
}
else
relay11=0;
}
}
void printnum_lcdm(unsigned char num, unsigned char row, unsigned char col)
{
}
void printnum_lcd1(unsigned char num, unsigned char row, unsigned char col)
{
}
//----------------------------------initialise lcd--------------------------------------//
void initlcd()
{
enable=0;
delay_ms(20);
cmd_lcd(0x30);
delay_ms(5);
cmd_lcd(0x30);
cmd_lcd(0x30);
cmd_lcd(0x38);
cmd_lcd(0x08);
CLR_LCD;
cmd_lcd(0x06);
cmd_lcd(0x0e);
}
lcd_shortdelay();enable=0;
}
void lcd_shortdelay(void)
{
unsigned char t=23;
while(t--);
}
void printlcd(unsigned char *message, unsigned char row, unsigned char col)
{
cmd_lcd(0x80 + (0x40*row) + col);
void printlcd1(unsigned char *message, unsigned char row, unsigned char col)
{
cmd_lcd(0x94 + (0x40*row) + col);
void printchar(unsigned char message1, unsigned char row, unsigned char col)
{
cmd_lcd(0x80 + (0x40*row) + col);
data_lcd(message1);