Sei sulla pagina 1di 71

A Project report on SNR and BER calculation of OFDM Using MATLAB

Submitted for partial fulfillment of award of BACHLOR OF TECHNOLOGY (B.Tech) degree In Electronics &Telecommunication
Prof.GS Bakhshi HOD ET/EC Department

GAUTAM BUDH TECHNICAL UNIVERSITY, LUCKNOW, INDIA 2012-2013

Name of Students:RAVI KANT PANDEY ABHISHEK GUPTA ASHUTOSH PATHAK ASHISH SRIVASTAVA

Name of Guide:
ANUBHAV KUMAR (ET/EC DEPARTMENT)

CERTIFICATE

This is to certify that project report entitled "SNR and BER calculation of OFDM using MATLAb" which is submitted by RAVI KANT PANDEY ,ABHISHEK GUPTA, ASHUTOSH PATHAK and ASHISH SRIVASTAVA in partial fulfillment of the requirement for the award of Bachelor Of Technology (B.Tech) degree in Department of Electronics & Telecommunication from GautamBudh Technical University, Lucknow is a record of candidate's own work carried out by him under my/our supervision. . The project report embodies result of original work and studies carried out by Students himself and the contents of the project report do not form the basis for the award of any other degree to the candidate or to anybody else.

Date:22/04/2013

Name of Guide: Mr. Anubhav Kumar Designation: Asst. Prof. Address:Vishveshwarya Institute of Engineering and technology,Dadri,G.B.Nagar(203207)

TABLE OF CONTENTS
DECLARATION CERTIFICATE... ACKNOWLEDGEMENT.. ABSTRACT LIST OF FIGURES. LIST OF SYMBOLS... LIST OF TABLES CHAPTER 1- INTRODUCTION 1.1 BLOCK DIAGRAM.. 1.2 CIRCUIT DIAGRAM 1.3 WORKING PRINCIPLE CHAPTER 2- POWER SUPPLY OF THE SYSTEM 2.1 POWER SUPLLY 2.1.1 Need of power supply 2.2 DIODE. 2.2.1 Electronic symbols.. 2.3 USE OF DIODES IN RECTIFIERS.. 2.3.1 Rectification.

2.3.2 Full wave rectifier.. 2.3.3 Bridge rectifier 2.4 FILTRATION 2.4.1 Choke input filter.. 2.4.2 Capacitor input filter 2.4.3 Circuit diagram.. 2.5 TRANSFORMER.. 2.5.1 Overview.. 2.5.2 Coupling by mutual induction 2.5.3 Simplified analysis. 2.5.4 Analysis of the ideal transformer 2.5.5 DC voltages and currents 2.5.6 The universal EMF equation.. 2.5.7 Practical considerations.. 2.5.7.1 Classifications.. 2.6 CAPACITORS 2.6.1 Current-voltage relation. 2.6.2 Networks.. 2.6.2.1 For capacitors in parallel.. 2.6.2.2 For capacitors in series 2.7 TRANSISTOR. 2.7.1 NPN Transistors.. 2.7.2 PNP Transistor

2.7.3 The two types are 2.7.3.1 PNP type.. 2.7.3.2 NPN type. 2.7.4 Operation of pnp transistor. 2.8 RESISTERS 2.8.1 Theory of operation.. 2.8.1.1 Ohm's law 2.8.1.2Series and parallel resistors. 2.8.2Power dissipation. CHAPTER 3- IC HARDWARE. 3.1 MICROCONTROLLER IC 3.1.1 A brief introduction to microcontroller 3.1.1.1 Key features of microcontrollers 3.2MICROCONTROLLER(AT89S52) 3.2.1 Features.. 3.2.2 Block Diagram.. 3.2.3 Pin configuration. 3.2.3.1 Pin description. 3.3 OSCILLATOR CHARACTERISTICS. 3.4 THE 8051 REGISTERS 3.4.1 Program counter.

3.4.2 Psw (program status word) register. 3.4.3 Cy, the carry flag.. 3.4.4 Ac, the auxiliary carry flag. 3.4.5 P, the parity flag 3.4.6 Ov, the overflow flag.. 3.5 RAM MEMORY SPACE ALLOCATION IN THE 8051 3.6 REGISTER BANKS IN THE 8051. 3.7 STACK IN THE 8051.. 3.7.1 Pushing onto the stack. 3.7.2 Popping from the stack 3.8 ADDRESSING MODES.. 3.8.1 Direct addressing 3.8.2 Indirect addressing 3.8.3 Register instructions.. 3.8.4 Register-specific instructions. 3.8.5 Immediate constants.. 3.8.6 Indexed addressing 3.9 8051 INSTRUCTION SET.. 3.9.1 Mnemonic.. 3.9.2 Operation CHAPTER 4- SIM300 GSM MODULE 4.1 PRODUCT CONCEPT ..

4.1.1 SIM300 key features at a glance.. 4.2 APPLICATION INTERFACE .. 4.3 SIM300 PIN DESCRIPTION 4.4 OPERATING MODES 4.5 POWER SUPPLY . 4.5.1 Power supply pins on the board-to-board connector . 4.5.2 Minimizing power losses 4.5.3 Monitoring power supply 4.6 POWER UP AND POWER DOWN SCENARIOS 4.6.1 Turn on SIM300 . 4.6.1.1 Turn on SIM300 using the PWRKEY pin (Power on) 4.6.1.2 Turn on SIM300 using the RTC (Alarm mode). 4.6.2 Turn off SIM300 . 4.6.2.1 Turn off SIM300 using the PWRKEY pin (Power down) 4.6.2.2 Turn off SIM300 using AT command 4.6.2.3 Under-voltage automatic shutdown 4.6.2.4 Over-temperature automatic shutdown 4.6.3 Restart SIM300 us.ing the PWRKEY pin

4.7. POWER SAVING .. 4.7.1 Minimum functionality mode .. 4.7.2 Sleep mode (Slow Clocking mode) .. 4.7.3 Wake up SIM300 from SLEEP mode . CHAPTER 5- RELAYS AND DISPLAY UNIT... 5.1. RELAYS. 5.1.1 Choosing a relay.. 5.1.1.1 Physical size and pin arrangement.. 5.1.1.2Coil voltage.. 5.1.1.3 Coil resistance. 5.1.1.4 Switch ratings (voltage and current).. 5.1.1.5 Switch contact arrangement (SPDT, DPDT etc) 5.2 LCD INTERFACING.. 5.2.1 The bit descriptions for the different commands are 5.2.2 Moving LCD cursor CHAPTER 6- SOFTWARE AND PROGRAMMING. 6.1 SOFTWARE.. 6.1.1. Keil. 6.1.1.1Features 6.2. PROGRAMMING CHAPTER 7- APPLICATIONS AND CONCLUSION

APPENDIX 1 REFERENCES

ACKNOWLEDGEMENT
It gives us great sense of pleasure to present the report of B.Tech. undertaken during B.Tech. final year. We owe special debt of gratitude to Mr. Anubhav Kumar Department of Electronics& Telecommunication, VGI for his constant support and guidance throughout the course of our work. His sincerity, thoroughness and perseverance have been a constant source of inspiration for us. It is only his cognizant efforts that our endeavors have been light of the day. We also take the opportunity to acknowledge the contribution of Prof. G.S. Bakshi, Head of Department of "Electronics & Telecommunication", VGI for his full support and assistance during the development of the project. We also do not like miss the opportunity to acknowledge the contribution of the faculty members of the department for their kind assistance and cooperation during the development of our project. Last but not least, we acknowledge our friends for their contribution in the completion of the project.

Signature: Name: RAVI KANT PANDEY Roll No:0909610087 Date: 22/04/2013

Signature: Name: ABHISHEK GUPTA Roll No:0909633034 Date:22/04/2013

Signature: Name: ASHUTOSH PATHAK Roll No.:0909633034 Date:22/04/2013

Signature: Name: ASHISH SRIVASTAVA Roll No.:0909633034 Date:22/04/2013

LIST OF FIGURES
Figure 1.1 Block Diagram of the system Figure 1.2 Circuit Diagram of the alert device Figure 2.1 Typical diode package in same alignment diode symbol. Figure 2.2 Symbols of diode... Figure 2.3 Circuit diagram of power supply... Figure 2.4 A historical Stanley transformer Figure 2.5 A practical step down transformer showing magnetizing flux in the core Figure 2.6 Different capacitor.. Figure 2.7 Specific design for Transistor. Figure 2.8 Symbol of PNP transistor Figure 2.9 Symbol of NPN transistor.. Figure 2.10 Working of PNP transistor Figure 2.11 Resistor with wire leads for through hole mounting. Figure3.1 Blok diagram AT89S52 microcontroller Figure 3.2 Pin configuration of AT89S52 Figure 3.3 Oscillator connection Figure 3.4 RAM memory allocation of 8051 Figure 4.1 SIM300 GSM module Figure 4.2 VBAT input Figure 4.3 VBAT ripple wave at maximum power transmit phase Figure 4.4 Timing of turn on system Figure 4.5 Timing of turn off system Figure 4.6 Timing of restart system Figure 5.1 Circuit symbol for relay Figure 5.2 Relay coil Figure5.3 Moving LCD cursor

LIST OF TABLES
Table 2.1 Standard symbols Table 3.1 Resistor banks in 8051 Table 4.1 SIM300 key features Table 4.2 Coding scheme and maximum net data rate over air interface Table 4.3 Board to board connector pin description Table 4.4 Overview of operating modes Table 4.5 AT commands used in alarm mode Table 5.1 Pin description of LCD Table 5.2 The different instruction available for use with the 44780 Table 5.3 Layout of LCD

ABSTRACT
Orthogonal Frequency Division Multiplexing (OFDM) is a bandwidth efficient signalling scheme for wide band digital communications. A general problem found in high speed co mmunication is Inter-Symbol Interference (ISI). ISI occurs when a transmission interferes with itself and the receiver cannot decode the transmission correctly. Orthogonal frequency division multiplex (OFDM) modulation is being used more and more in telecommunica tion, wired and wireless. DVB and DAB already use this modulation technique and ADSL is based on it. The advantages of this modulation are the reason for its increasing usage.OFDM can be implemented easily, it is spectrally efficient and can provide high data rates with sufficient robustness to channel imperfections . The purpose of this paper is to use a Matlab simulation of OFDM to analyse the Bit Ratio (BER) of a transmission varies when Signal to Noise Ratio (S/N Ratio) and Multipropagation effects are changed on transmission channel. Our project is based on this technology and MATLAB software is used. MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software package, which is used extensively in both academia and industry. It is an interactive program for numerical computation and data visualization, which along with its programming capabilities provides a very useful tool for almost all areas of science and engineering.

CHAPTER 1 INTRODUCTION
1.1BLOCK DIAGRAM

Fig 1.1 Block Diagram of the OFDM model used

1.2 WORKING PRINCIPLE


Our project works on the principle of OFDM technology. Orthogonal frequency-division multiplexing (OFDM) is a method of encoding digital data on multiple carrier frequencies. OFDM has developed into a popular scheme for wideband digital communication, whetherwireless or over copper wires, used in applications such as digital television and audio broadcasting, DSL broadband internet access, wireless networks, and 4G mobile communications.The primary advantage of OFDM over single-carrier schemes is its ability to cope with severe channel conditions (for example, attenuation of high frequencies in a long copper wire, narrowband interference and frequency-selective fading due to multipath) without complex equalization filters. Channel equalization is simplified because OFDM may

be viewed as using many slowly modulated narrowband signals rather than one rapidly modulatedwideband signal. The low symbol rate makes the use of a guard interval between symbols affordable, making it possible to eliminate intersymbol interference (ISI) and utilize echoes and time-spreading (on analogue TV these are visible as ghosting and blurring, respectively) to achieve a diversity gain, i.e. a signal-to-noise ratio improvement. This mechanism also facilitates the design of single frequency networks (SFNs), where several adjacent transmitters send the same signal simultaneously at the same frequency, as the signals from multiple distant transmitters may be combined constructively, rather than interfering as would typically occur in a traditional single-carrier system.

CHAPTER 2 ABOUT OFDM


2.1 WHAT IS Orthogonality
Conceptually, OFDM is a specialized FDM, the additional constraint being: all the carrier signals are orthogonal to each other.In OFDM, the sub-carrier frequencies are chosen so that the sub-carriers are orthogonal to each other, meaning that cross-talk between the subchannels is eliminated and inter-carrier guard bands are not required. This greatly simplifies the design of both the transmitter and the receiver; unlike conventional FDM, a separate filter for each sub-channel is not required. The orthogonality requires that the sub-carrier spacing is Hertz, where TU seconds is

the useful symbol duration (the receiver side window size), and k is a positive integer, typically equal to 1. Therefore, with Nsub-carriers, the total passband bandwidth will be B Nf (Hz). The orthogonality also allows high spectral efficiency, with a total symbol rate near the Nyquist rate for the equivalent baseband signal (i.e. near half the Nyquist rate for the double-side band physical passband signal). Almost the whole available frequency band can be utilized. OFDM generally has a nearly 'white' spectrum, giving it benign electromagnetic interference properties with respect to other co-channel users. A simple example: A useful symbol duration TU = 1 ms would require a sub-carrier spacing of (or an integer multiple of that) for orthogonality. N = 1,000 sub-carriers

would result in a total passband bandwidth of Nf = 1 MHz. For this symbol time, the required bandwidth in theory according to Nyquist is N/2TU = 0.5 MHz (i.e., half of the achieved bandwidth required by our scheme). If a guard interval is applied (see below), Nyquist bandwidth requirement would be even lower. The FFT would result in N = 1,000 samples per symbol. If no guard interval was applied, this would result in a base band

complex valued signal with a sample rate of 1 MHz, which would require a baseband bandwidth of 0.5 MHz according to Nyquist. However, the passband RF signal is produced by multiplying the baseband signal with a carrier waveform (i.e., double-sideband quadrature amplitude-modulation) resulting in a passband bandwidth of 1 MHz. A single-side band (SSB) or vestigial sideband (VSB) modulation scheme would achieve almost half that bandwidth for the same symbol rate (i.e., twice as high spectral efficiency for the same symbol alphabet length). It is however more sensitive to multipath interference. OFDM requires very accurate frequency synchronization between the receiver and the transmitter; with frequency deviation the sub-carriers will no longer be orthogonal, causing inter-carrier interference (ICI) (i.e., cross-talk between the sub-carriers). Frequency offsets are typically caused by mismatched transmitter and receiver oscillators, or by Doppler shift due to movement. While Doppler shift alone may be compensated for by the receiver, the situation is worsened when combined with multipath, as reflections will appear at various frequency offsets, which is much harder to correct. This effect typically worsens as speed increases, and is an important factor limiting the use of OFDM in high-speed vehicles. Several techniques for ICI suppression are suggested, but they may increase the receiver complexity.

2.2 Advantages

High spectral efficiency as compared to other double sideband modulation schemes, spread spectrum, etc.

Can easily adapt to severe channel conditions without complex time-domain equalization.

Robust against narrow-band co-channel interference. Robust against intersymbol interference (ISI) and fading caused by multipath propagation.

Efficient implementation using Fast Fourier Transform (FFT). Low sensitivity to time synchronization errors. Tuned sub-channel receiver filters are not required (unlike conventional FDM). Facilitates single frequency networks (SFNs); i.e., transmitter macrodiversity.

2.3Disadvantages

Sensitive to Doppler shift. Sensitive to frequency synchronization problems. High peak-to-average-power ratio (PAPR), requiring linear transmitter circuitry, which suffers from poor power efficiency.

Loss of efficiency caused by cyclic prefix/guard interval. The double sideband modulation of each sub-carrier causes lower spectral

efficiency and higher transmitter power requirements for equivalent coverage as compared to VSB modulation.

2.4 Implementation using the FFT algorithm


The orthogonality allows for efficient modulator and demodulator implementation using the FFT algorithm on the receiver side, and inverse FFT on the sender side. Although the principles and some of the benefits have been known since the 1960s, OFDM is popular for wideband communications today by way of low-cost digital signal processing components that can efficiently calculate the FFT. The time to compute the inverse-FFT or FFT transform has to take less than the time for each symbol. Which for example for DVB-T (FFT 8k) means the computation has to be done in 896 s or less. For an 8192-point FFT this may be approximated to:[5][clarification needed]

MIPS = Million instructions per second

2.5 Guard interval for elimination of intersymbol interference


One key principle of OFDM is that since low symbol rate modulation schemes (i.e., where the symbols are relatively long compared to the channel time characteristics) suffer less from intersymbol interference caused bymultipath propagation, it is advantageous to transmit a number of low-rate streams in parallel instead of a single high-rate stream. Since the duration of each symbol is long, it is feasible to insert a guard interval between the OFDM symbols, thus eliminating the intersymbol interference. The guard interval also eliminates the need for a pulse-shaping filter, and it reduces the sensitivity to time synchronization problems. A simple example: If one sends a million symbols per second using conventional singlecarrier modulation over a wireless channel, then the duration of each symbol would be one microsecond or less. This imposes severe constraints on synchronization and necessitates the removal of multipath interference. If the same million symbols per second are spread among one thousand sub-channels, the duration of each symbol can be longer by a factor of a thousand (i.e., one millisecond) for orthogonality with approximately the same bandwidth. Assume that a guard interval of 1/8 of the symbol length is inserted between each symbol. Intersymbol interference can be avoided if the multipath time-spreading (the time between the reception of the first and the last echo) is shorter than the guard interval (i.e., 125 microseconds). This corresponds to a maximum difference of 37.5 kilometers between the lengths of the paths. The cyclic prefix, which is transmitted during the guard interval, consists of the end of the OFDM symbol copied into the guard interval, and the guard interval is transmitted followed by the OFDM symbol. The reason that the guard interval consists of a copy of the end of the OFDM symbol is so that the receiver will integrate over an integer number of sinusoid cycles for each of the multipaths when it performs OFDM demodulation with the FFT. In some standards such as Ultrawideband, in the interest of transmitted power, cyclic prefix is skipped and nothing is sent during the guard interval. The receiver will then have to mimic the cyclic prefix functionality by copying the end part of the OFDM symbol and adding it to the beginning portion.

2.6 Idealized system model


This section describes a simple idealized OFDM system model suitable for a timeinvariant AWGN channel.

2.6.1 Transmitter
An OFDM carrier signal is the sum of a number of orthogonal sub-carriers, with baseband data on each sub-carrier being independently modulated commonly using some type of quadrature amplitude modulation (QAM) or phase-shift keying (PSK). This composite baseband signal is typically used to modulate a main RF carrier. is a serial stream of binary digits. By inverse multiplexing, these are first demultiplexed into parallel streams, and each one mapped to a (possibly complex) symbol stream using

some modulation constellation (QAM,PSK, etc.). Note that the constellations may be different, so some streams may carry a higher bit-rate than others. An inverse FFT is computed on each set of symbols, giving a set of complex time-domain samples. These samples are then quadrature-mixed to passband in the standard way. The real and imaginary components are first converted to the analogue domain using digital-toanalogue converters (DACs); the analogue signals are then used to

modulate cosine and sine waves at the carrier frequency, then summed to give the transmission signal,

, respectively. These signals are

as shown in figure 2.1

Fig 2.1 Transmitter model for ofdm

2.6.2 Receiver
The receiver picks up the signal , which is then quadrature-mixed down to baseband using , so

cosine and sine waves at the carrier frequency. This also creates signals centered on

low-pass filters are used to reject these. The baseband signals are then sampled and digitised using analog-to-digital converters (ADCs), and a forward FFT is used to convert back to the frequency domain. This returns parallel streams, each of which is converted to a binary stream using an ,

appropriate symbol detector. These streams are then re-combined into a serial stream, which is an estimate of the original binary stream at the transmitter as shown in figure 2.2

Fig 2.2 Receiver model for OFDM

2.7 Mathematical description


If sub-carriers are used, and each sub-carrier is modulated using combined symbols. alternative symbols,

the OFDM symbol alphabet consists of

The low-pass equivalent OFDM signal is expressed as:

where

are the data symbols,

is the number of sub-carriers, and

is the OFDM

symbol time. The sub-carrier spacing of this property is expressed as:

makes them orthogonal over each symbol period;

where

denotes the complex conjugate operator and

is the Kronecker delta.

To avoid intersymbol interference in multipath fading channels, a guard interval of length is inserted prior to the OFDM block. During this interval, a cyclic prefix is transmitted such that the signal in the interval OFDM signal with cyclic prefix is thus: equals the signal in the interval . The

The low-pass signal above can be either real or complex-valued. Real-valued low-pass equivalent signals are typically transmitted at basebandwireline applications such as DSL use this approach. For wireless applications, the low-pass signal is typically complex-valued; in which case, the transmitted signal is up-converted to a carrier frequency transmitted signal can be represented as: . In general, the

2.8 Usage
OFDM is used in Digital Audio Broadcasting (DAB), Digital television DVBLAN IEEE T/T2 (terrestrial), DVB-H (handheld), DMB-T/H, DVB-C2 (cable), 802.11a, ADSL (G.DMT/ITU G.992.1), Mobile phone 4G. Wireless

CHAPTER 3 Signal-to-noise ratio


Signal-to-noise ratio (often abbreviated SNR or S/N) is a measure used in science and engineering that compares the level of a desired signal to the level of background noise. It is defined as the ratio of signal power to the noise power. A ratio higher than 1:1 indicates more signal than noise. While SNR is commonly quoted for electrical signals, it can be applied to any form of signal (such as isotope levels in an ice core or biochemical signaling between cells). The signal-to-noise ratio, the bandwidth, and the channel capacity of a communication channel are connected by the ShannonHartley theorem. Signal-to-noise ratio is sometimes used informally to refer to the ratio of

useful information to false or irrelevant data in a conversation or exchange. For example, in online discussion forums and other online communities, off-topic posts and spam are regarded as "noise" that interferes with the "signal" of appropriate discussion.

3.1 Definition
Signal-to-noise ratio is defined as the power ratio between a signal (meaningful information) and the background noise (unwanted signal):

where P is average power. Both signal and noise power must be measured at the same or equivalent points in a system, and within the same system bandwidth. If the signal and the noise are measured across the sameimpedance, then the SNR can be obtained by calculating the square of the amplitude ratio:

where A is root mean square (RMS) amplitude (for example, RMS voltage). Because many signals have a very wide dynamic range, SNRs are often expressed using

the logarithmic decibel scale. In decibels, the SNR is defined as

which may equivalently be written using amplitude ratios as

The concepts of signal-to-noise ratio and dynamic range are closely related. Dynamic range measures the ratio between the strongest un-distorted signal on a channel and the minimum discernable signal, which for most purposes is the noise level. SNR measures the ratio between an arbitrary signal level (not necessarily the most powerful signal possible) and noise. Measuring signal-to-noise ratios requires the selection of a representative orreference signal. In audio engineering, the reference signal is usually a sine wave at a standardized nominal or alignment level, such as 1 kHz at +4 dBu (1.228 VRMS). SNR is usually taken to indicate an average signal-to-noise ratio, as it is possible that (near) instantaneous signal-to-noise ratios will be considerably different. The concept can be understood as normalizing the noise level to 1 (0 dB) and measuring how far the signal 'stands out'.

3.2 Difference from conventional power


In Physics power (physics) of an ac signal is defined as

But in Signal Processing and Communication we usually assume that

so that

usually we don't include that resistance term while measuring power or energy of a signal. This usually causes some confusions among readers but the resistance term is not significant for operations performed in signal processing. Most of cases the power of a signal would be

where 'A' is the amplitude of the ac signal. In some places people just use

as the constant term doesn't affect much during the calculations.

3.3 SNR for various modulation systems 3.3.1 Amplitude modulation


Channel signal-to-noise ratio is given by

where W is the bandwidth and ka is modulation index Output signal-to-noise ratio (of AM receiver) is given by

3.3.2 Frequency modulation


Channel signal-to-noise ratio is given by

Output signal-to-noise ratio is given by

3.4 Improving SNR

Fig 2.3 Recording of the noise of athermogravimetric analysis device All real measurements are disturbed by noise. This includes electronic noise, but can also include external events that affect the measured phenomenon wind, vibrations, gravitational attraction of the moon, variations of temperature, variations of humidity, etc., depending on what is measured and of the sensitivity of the device. It is often possible to reduce the noise by controlling the environment. Otherwise, when the characteristics of the noise are known and are different from the signals, it is possible to filter it or to process the signal. For example, it is sometimes possible to use a lock-in amplifier to modulate and confine the signal within a very narrow bandwidth and then filter the detected signal to the narrow band where it resides, thereby eliminating most of the broadband noise. When the signal is constant or periodic and the noise is random, it is possible to enhance the SNR by averaging the measurement. In this case the noise goes down as the square root of the number of averaged samples.

3.5 Digital signals


When a measurement is digitised, the number of bits used to represent the measurement determines the maximum possible signal-to-noise ratio. This is because the minimum possible noise level is the error caused by thequantization of the signal, sometimes called Quantization noise. This noise level is non-linear and signal-dependent; different calculations exist for different signal models. Quantization noise is modeled as an analog error signal summed with the signal before quantization ("additive noise"). This theoretical maximum SNR assumes a perfect input signal. If the input signal is already noisy (as is usually the case), the signal's noise may be larger than the quantization noise. Real analog-to-digital converters also have other sources of noise that further decrease the SNR compared to the theoretical maximum from the idealized quantization noise, including the intentional addition of dither. Although noise levels in a digital system can be expressed using SNR, it is more common to use Eb/No, the energy per bit per noise power spectral density. The modulation error ratio (MER) is a measure of the SNR in a digitally modulated signal.

CHAPTER 4 Bit error rate


In digital transmission, the number of bit errors is the number of received bits of a data stream over a communication channel that have been altered due

to noise, interference, distortion or bit synchronization errors. The bit error rate or bit error ratio (BER) is the number of bit errors divided by the total number of transferred bits during a studied time interval. BER is a unitless performance measure, often expressed as a percentage. The bit error probability pe is the expectation value of the BER. The BER can be considered as an approximate estimate of the bit error probability. This estimate is accurate for a long time interval and a high number of bit errors. Example: As an example, assume this transmitted bit sequence: 0 1 1 0 0 0 1 0 1 1, and the following received bit sequence: 0 0 1 0 1 0 1 0 0 1, The number of bit errors (the underlined bits) is in this case 3. The BER is 3 incorrect bits divided by 10 transferred bits, resulting in a BER of 0.3 or 30%.

4.1Factors affecting the BER


In a communication system, the receiver side BER may be affected by transmission channel noise, interference, distortion, bitsynchronization problems, attenuation,wireless mult ipath fading, etc. The BER may be improved by choosing a strong signal strength (unless this causes cross-talk and more bit errors), by choosing a slow and robust modulation scheme or line coding scheme, and by applying channel codingschemes such as redundant forward error correction codes.

The transmission BER is the number of detected bits that are incorrect before error correction, divided by the total number of transferred bits (including redundant error codes). The information BER, approximately equal to the decoding error probability, is the number of decoded bits that remain incorrect after the error correction, divided by the total number of decoded bits (the useful information). Normally the transmission BER is larger than the information BER. The information BER is affected by the strength of the forward error correction code.

4.2 Analysis of the BER


The BER may be analyzed using stochastic computer simulations. If a simple transmission channel model and data source model is assumed, the BER may also be calculated analytically. An example of such a data source model is the Bernoulli source. Examples of such simple channel models are:

Binary symmetric channel (used in analysis of decoding error probability in case of non-bursty bit errors on the transmission channel)

Additive white gaussian noise (AWGN) channel without fading.

A worst case scenario is a completely random channel, where noise totally dominates over the useful signal. This results in a transmission BER of 50% (provided that a Bernoulli binary data source and a binary symmetrical channel are assumed, see below).

Fig 2.3 Bit-error rate curves for BPSK, QPSK, 8-PSK and 16-PSK, AWGN channel.

In a noisy channel, the BER is often expressed as a function of the normalized carrier-tonoise ratio measure denoted Eb/N0, (energy per bit to noise power spectral density ratio), or Es/N0 (energy per modulation symbol to noise spectral density). For example, in the case of QPSK modulation and AWGN channel, the BER as function of the Eb/N0 is given by: .

People usually plot the BER curves to describe the functionality of a digital communication system. In optical communication, BER(dB) vs. Received Power(dBm) is usually used; while in wireless communication, BER(dB) vs. SNR(dB) is used. Measuring the bit error ratio helps people choose the appropriate forward error correction codes. Since most such codes correct only bit-flips, but not bit-insertions or bitdeletions, the Hamming distance metric is the appropriate way to measure the number of bit errors. Many FEC coders also continuously measure the current BER. A more general way of measuring the number of bit errors is the Levenshtein distance. The Levenshtein distance measurement is more appropriate for measuring raw channel performance before frame synchronization, and when using error correction codes designed to correct bit-insertions and bit-deletions, such as Marker Codes and Watermark Codes.

4.1.1 SIM300 key features at a glance

Table 4.1SIM300 key features


Coding scheme CS-1: CS-2: CS-3: CS-4: 1 Timeslot 9.05kbps 13.4kbps 15.6kbps 21.4kbps 2 Timeslot 18.1kbps 26.8kbps 31.2kbps 42.8kbps 4 Timeslot 36.2kbps 53.6kbps 62.4kbps 85.6kbps

Table 4.2 Coding schemes and maximum net data rates over air interface

4.2 APPLICATION INTERFACE


All hardware interfaces except RF interface that connects SIM300 to the customers cellular application platform is through a 60-pin 0.5mm pitch board-to-board connector. Subinterfaces included in this board-to-board connector are described in detail in following points. Power supply Dual serial interface Two analog audio interfaces SIM interface

4.3 SIM300 PIN DESCRIPTION


Table 4.3 Board-to-Board Connector pin description
Power Supply PIN NAME VBAT I/O DESCRIPTION DC CHARACTERISTICS Eight BAT pins of the Vmax= 4.5V board-to-board Vmin=3.4V connector are Vnorm=4.0V dedicated to connect the supply voltage. The power supply of SIM300 has to be a single voltage source of VBAT= 3.4V...4.5V. It must be able to provide sufficient current in a transmit burst which typically rises to 2A.mostly, these 8 pins are voltage input Current input for RTC Vmax=2.0V when the battery is not Vmin=1.2V supplied for the Vnorm=1.8V system. Inorm= 20uA Current output for backup battery when the main battery is present and the backup battery in low voltage state. Supply 3.0V voltage Vmax=3.15V for external circuit. By Vmin=2.85V measure this pin, user Vnorm=3.0V can judge the system is Imax=60mA on or off. When the voltage is low, the system is off. Otherwise, the system is on. Digital ground

VRTC

I/O

VDD_EXT

GND

4.4 OPERATING MODES


The following table summarizes the various operating modes, each operating modes is referred to in the following chapters. Table 4.4 Overview of operating modes Mode Normal operation Function GSM/GPRS SLEEP

Module will automatically go into SLEEP mode if DTR is set to high level and there is no on air or audio activity is required and no hardware interrupt (such as GPIO interrupt or data on serial port). In this case, the current consumption of module will reduce to the minimal level. During sleep mode, the module can still receive paging

message and SMS from the system normally.

4.5 POWER SUPPLY


The power supply of SIM300 is from a single voltage source of VBAT= 3.4V...4.5V. In some case, the ripple in a transmit burst may cause voltage drops when current consumption rises to typical peaks of 2A, So the power supply must be able to provide sufficient current up to 2A.

For the VBAT input, a local bypass capacitor is recommended. A capacitor (about 100F, low ESR) is recommended. Multi-layer ceramic chip (MLCC) capacitors can provide the best combination of low ESR and small size but may not be cost effective. A lower cost choice may be a 100 F tantalum capacitor (low ESR) with a small (1 F to 10F) ceramic in parallel, which is illustrated as following figure. And the capacitors should put as closer as possible to the SIM300 VBAT pins. The following figure is the recommended circuit.

Fig. 4.2 VBAT input The following figure is the VBAT voltage ripple wave at the maximum power transmit phase, the test condition is VBAT=4.0V, VBAT maximum output current =2A, CA=100 F tantalum capacitor (ESR=0.7) and CB=4.7F.

Fig. 4.3 VBAT ripple wave at the maximum power transmit phase

4.5.1 Power supply pins on the board-to-board connector


Eight VBAT pins of the board-to-board connector are dedicated to connect the supply voltage; four GND pins are recommended for grounding. BACKUP can be used to back up the RTC.

4.5.2 Minimizing power losses


Please pay special attention to the supply power when you are designing your applications. Please make sure that the input voltage will never drops below 3.4V even in a transmit burst during which the current consumption may rise up to 2A. If the power voltage drops below 3.4V, the module may be switched off. Using the board-to-board connector will be the best

way to reduce the voltage drops. You should also take the resistance of the power supply lines on the host board or of battery pack into account.

4.5.3 Monitoring power supply


To monitor the supply voltage, you can use the AT+CBC command which include three parameters: voltage percent and voltage value (in mV). It returns the battery voltage 1-100 percent of capacity and actual value measured at VBAT and GND. The voltage is continuously measured at intervals depending on the operating mode. The displayed voltage (in mV) is averaged over the last measuring period before the AT+CBC command was executed.

4.6 POWER UP AND POWER DOWN SCENARIOS 4.6.1 Turn on SIM300


SIM300 can be turned on by various ways, which are described in following chapters: Via PWRKEY pin: starts normal operating mode Via RTC interrupt: starts ALARM modes

Note: Only enter AT command through serial port after SIM300 is power on and Unsolicited Result Code RDY is received from serial port.

4.6.1.1 Turn on SIM300 using the PWRKEY pin (Power on)


You can turn on the SIM300 by driving the PWRKEY to a low level voltage for period time. The power on scenarios illustrate as following figure.

Figure4.4 Timing of turn on system

When power on procedure complete, SIM300 will send out following result code to indicate the module is ready to operate: RDY

4.6.1.2 Turn on SIM300 using the RTC (Alarm mode)


Alarm mode is a power-on approach by using the RTC. The alert function of RTC makes the SIM300 wake up while the module is power off. In alarm mode, SIM300 will not register to GSM network and the software protocol stack is close. Thus the parts of AT commands related with SIM card and Protocol stack will not accessible, and the others can be used as well as in normal mode. Use the AT+CALARM command to set the alarm time. The RTC remains the alarm time if SIM300 was power down by AT+CPOWD=1 or by PWRKEY pin. Once the alarm time expires and executed, SIM300 goes into the Alarm mode. In this case, SIM300 will send out an Unsolicited Result Code (URC): RDY ALARM MODE During Alarm mode, using AT+CFUN command to query the status of software protocol stack; it will return 0 which indicates that the protocol stack is closed. Then after 90S, SIM300 will power down automatically. However, during Alarm mode, if the software protocol is started by AT+CFUN=1, 1 command, the process of automatic power down will not available. In ALARM mode, driving the PWRKEY to a low level voltage for a period will cause SIM300 to power down (Please refer to the power down scenarios in 3.3.2.1). The table follow briefly summarizes the AT commands that are used usually during alarm mode, Table 4.5 AT commands used in Alarm mode
AT command AT+CALARM AT+CCLK AT+CPOWD AT+CFUN USE Set alarm time Set data and time of RTC Power down Start or close the protocol stack

4.6.2 Turn off SIM300


Following procedure can be used to turn off the SIM300: Normal power down procedure: Turn off SIM300 using the PWRKEY pin Normal power down procedure: Turn off SIM300 using AT command Under-voltage automatic shutdown: Takes effect if Under-voltage is detected Over-temperature automatic shutdown: Takes effect if Over-temperature is detected

4.6.2.1 Turn off SIM300 using the PWRKEY pin (Power down)
You can turn off the SIM300 by driving the PWRKEY to a low level voltage for period time. The power down scenarios illustrate as following Figure. This procedure will let the module to log off from the network and allow the software to enter into a secure state and save data before completely disconnect the power supply. Before the completion of the switching off procedure the module will send out result code: POWER DOWN After this moment, no any AT commands can be executed. Module enters the POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by VDD_EXT pin, which is a low level voltage in this mode.

Figure 4.5 Timing of turn off system

4.6.2.2 Turn off SIM300 using AT command


You can use an AT command AT+CPOWD=1 to turn off the module. This command will let the module to log off from the network and allow the software to enter into a secure state and safe data before completely disconnect the power supply. Before switching off the module will send out result code: POWER DOWN After this moment, no any AT commands can be executed. Module enters the POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by VDD_EXT pin, which is a low level voltage in this mode.

4.6.2.3 Under-voltage automatic shutdown


Software will constantly monitors the voltage applied on the VBAT, if the measured battery voltage is no more than 3.5V, the following URC will be presented: POWER LOW WARNNING If the measured battery voltage is no more than 3.4V, the following URC will be presented: POWER LOW DOWN After this moment, no further more AT commands can be executed. The module will log off from network and enters POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by VDD_EXT pin, which is a low level voltage in this mode.

4.6.2.4 Over-temperature automatic shutdown


Software will constantly monitors the temperature of the module, if the measured temperature is equal or higher than 85, the following URC will be presented: +CMTE:1 If the measured temperature is equal or lower than -35, the following URC will be presented: +CMTE:-1 The uncritical temperature range is -40 to 90. If the measured temperature is equal or beyond this range, the module will be automatic shutdown soon. If the measured temperature is equal or higher than 90, the following URC will be presented: +CMTE:2 If the measured temperature is equal or lower than -40, the following URC will be presented: +CMTE:-2 After this moment, no further more AT commands can be executed. The module will log off from network and enters POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by VDD_EXT pin, which is a low level voltage in this mode. To monitor the temperature, you can use the AT+CMTE command to measure the temperature when the module power on.

4.6.3 Restart SIM300 using the PWRKEY pin


You can restart SIM300 by driving the PWRKEY to a low level voltage for period time, same as turn on SIM300 using the PWRKEY pin. Before restart the SIM300, you need delay at least 500mS from detecting the VDD_EXT low level on. The restart scenarios illustrate as the following figure.

Fig.4.6 Timing of restart system

4.7. POWER SAVING


There are two methods to achieve SIM300 module extreme low power. AT+CFUN is used to set module into minimum functionality mode and /DTR hardware interface signal can be used to set system to be SLEEP mode (or Slow clocking mode).

4.7.1 Minimum functionality mode


Minimum functionality mode reduces the functionality of the module to a minimum and, thus, minimizes the current consumption to the lowest level. This mode is set with the AT+CFUN command which provides the choice of the functionality levels <fun>=0,1,4 0: minimum functionality; 1: full functionality (Default); 4: disable phone both transmit and receive RF circuits;

If SIM300 has been set to minimum functionality by AT+CFUN=0, then the RF function and SIM card function will be closed, in this case, the serial ports is still accessible, but all AT commands need RF function or SIM card function will not accessible. If SIM300 has disable all RF function by AT+CFUN=4, then RF function will be closed, the serial ports is still active in this case but all AT commands need RF function will not accessible.

When SIM300 is in minimum functionality or has been disable all RF functionality by AT+CFUN=4, it can return to full functionality by AT+CFUN=1.

4.7.2 Sleep mode (Slow Clocking mode)


Through DTR signal control SIM300 module to enter or exit the SLEEP mode in customer applications. When DTR is in high level, at the same time there is no on air or audio activity is required and no hardware interrupt (such as GPIO interrupt or data on serial port), SIM300 will enter SLEEP mode automatically. In this mode, SIM300 can still receive paging or SMS from network. In SLEEP mode, the serial port is not accessible. Note: For SIM300, it requests to set AT command AT+CSCLK=1 to enable the sleep mode; the default value is 0, that cant make the module enter sleep mode, for more details please refer to our AT command list.

4.7.3 Wake up SIM300 from SLEEP mode


When SIM300 is SLEEP mode, the following method can wake up the module. Enable DTR pin to wake up SIM300;

If DTR Pin is pull down to a low level,this signal will wake up SIM300 from power saving mode. The serial port will be active after DTR change to low level about 20ms. Receive a voice or data call from network to wake up SIM300; Receive a SMS from network to wake up SIM300 RTC alarm expired to wake up SIM300;

CHAPTER 5 RELAYS AND DISPLAY UNIT


5.1. RELAYS
A relay is an electrically operated switch. Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and they are double throw (changeover) switches. Relays allow one circuit to switch a second circuit which can be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. There is no electrical connection inside the relay between the two circuits; the link is magnetic and mechanical.

Fig.5.1 Circuit symbol for a relay The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it can be as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips) cannot provide this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil. The maximum output current for the popular 555 timer IC is 200mA so these devices can supply relay coils directly without amplification. Relays are usually SPDT or DPDT but they can have many more sets of switch contacts, for example relays with 4 sets of changeover contacts are readily available. For further information about switch contacts and the terms used to describe them please see the page on switches. Most relays are designed for PCB mounting but you can solder wires directly to the pins providing you take care to avoid melting the plastic case of the relay. The supplier's catalogue should show you the relay's connections. The coil will be obvious and it may be connected either way round. Relay coils produce brief high voltage 'spikes' when they are switched off and this can destroy transistors and ICs in the circuit. To prevent damage you must connect a protection diode across the relay coil.

The animated picture shows a working relay with its coil and switch contacts. You can see a lever on the left being attracted by magnetism when the coil is switched on. This lever moves the switch contacts. There is one set of contacts (SPDT) in the foreground and another behind them, making the relay DPDT.

The relay's switch connections are usually labeled COM, NC and NO:

COM = Common, always connect to this; it is the moving part of the switch. NC = Normally Closed, COM is connected to this when the relay coil is off. NO = Normally Open, COM is connected to this when the relay coil is on. Connect to COM and NO if you want the switched circuit to be on when the relay coil is on. Connect to COM and NC if you want the switched circuit to be on when the relay coil is off.

5.1.1 Choosing a relay


You need to consider several features when choosing a relay:

5.1.1.1 Physicalsize and pin arrangement


If you are choosing a relay for an existing PCB you will need to ensure that its dimensions and pin arrangement are suitable. You should find this information in the supplier's catalogue.

5.1.1.2Coil voltage
The relay's coil voltage rating and resistance must suit the circuit powering the relay coil. Many relays have a coil rated for a 12V supply but 5V and 24V relays are also readily available. Some relays operate perfectly well with a supply voltage which is a little lower than their rated value.

5.1.1.3Coil resistance
The circuit must be able to supply the current required by the relay coil. You can use Ohm's law to calculate the current:

Fig. 5.2 Relay coil

5.1.1.4 Switch ratings (voltage and current)


The relay's switch contacts must be suitable for the circuit they are to control. You will need to check the voltage and current ratings. Note that the voltage rating is usually higher for AC, for example: "5A at 24V DC or 125V AC".

5.1.1.5 Switch contact arrangement (SPDT, DPDT etc)


Most relays are SPDT or DPDT which are often described as "single pole changeover" (SPCO) or "double pole changeover" (DPCO). For further information please see the page on switches.

5.2 LCD INTERFACING


LCDs can add a lot to your application in terms of providing an useful interface for the user, debugging an application or just giving it a "professional" look. The most common type of LCD controller is the Hitatchi 44780 which provides a relatively simple interface between a processor and an LCD. Using this interface is often not attempted by inexperienced designers and programmers because it is difficult to find good documentation on the interface, initializing the interface can be a problem and the displays themselves are expensive. I have worked with Hitatchi 44780 based LCDs for a while now and I have to say that I don't believe any of these perceptions. LCDs can be added quite easily to an application and use as few as three digital output pins for control. As for cost, LCDs can be often pulled out of old devices or found in surplus stores for less than a dollar.

The purpose of this page is to give a brief tutorial on how to interface with Hitatchi 44780 based LCDs. I have tried to provide the all the data necessary for successfully adding LCDs to your application. The most common connector used for the 44780 based LCDs is 14 pins in a row, with pin centers 0.100" apart. The pins are wired as: Table 5.1 Pin Description of LCD
Pins 1 2 3 4 5 6 7 - 14 Description Ground Vcc Contrast Voltage "R/S" _Instruction/Register Select "R/W" _Read/Write LCD Registers "E" Clock Data I/O Pins

As you would probably guess from this description, the interface is a parallel bus, allowing simple and fast reading/writing of data to and from the LCD. This waveform will write an ASCII Byte out to the LCD's screen. The ASCII code to be displayed is eight bits long and is sent to the LCD either four or eight bits at a time. If four bit mode is used, two "nibbles" of data (Sent high four bits and then low four bits with an "E" Clock pulse with each nibble) are sent to make up a full eight bit transfer. The "E" Clock is used to initiate the data transfer within the LCD. Sending parallel data as either four or eight bits are the two primary modes of operation. While there are secondary considerations and modes, deciding how to send the data to the LCD is most critical decision to be made for an LCD interface application.

Eight bit mode is best used when speed is required in an application and at least ten I/O pins are available. Four bit mode requires a minimum of six bits. To wire a microcontroller to an LCD in four bit mode, just the top four bits (DB4-7) are written to. The "R/S" bit is used to select whether data or an instruction is being transferred between the microcontroller and the LCD. If the Bit is set, then the byte at the current LCD "Cursor" Position can be read or written. When the Bit is reset, either an instruction is being sent to the LCD or the execution status of the last instruction is read back. Table 5.2The different instructions available for use with the 44780
R/S R/W D7 D6 D5 D4 D3 D2 D1 D0 Instruction/Description 4 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 0 0 0 0 1 0 14 13 12 11 10 9 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 8 0 1 7 1 * Pins Clear Display Return Cursor and LCD to Home Position Set Cursor Move Direction

ID S

D C B Enable Display/Cursor * * Move Cursor/Shift Display Set Interface Length

SC RL * *

DL N F

A A

A A A A Move Cursor into CGRAM A A A A Move Cursor to Display * * * * Poll the "Busy Flag" Write a Character to the Display at the Current Cursor Position Read the Character on the Display at the Current Cursor Position

A A A * *

BF *

D D D D

D D D D

D D D D

D D D D

5.2.1The bit descriptions for the different commands are:


"*" - Not Used/Ignored. This bit can be either "1" or "0" Set Cursor Move Direction: ID - Increment the Cursor After Each Byte Written to Display if Set S - Shift Display when Byte Written to Display

Enable Display/Cursor D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0) B - Cursor Blink On(1)/Off(0)

Move Cursor/Shift Display SC - Display Shift On(1)/Off(0) RL - Direction of Shift Right(1)/Left(0)

Set Interface Length DL - Set Data Interface Length 8(1)/4(0) N - Number of Display Lines 1(0)/2(1) F - Character Font 5x10(1)/5x7(0)

Poll the "Busy Flag" BF - This bit is set while the LCD is processing

Move Cursor to CGRAM/Display A - Address Read/Write ASCII to the Display D - Data Reading Data back is best used in applications which required data to be moved back and forth on the LCD (such as in applications which scroll data between lines). The "Busy Flag" can be polled to determine when the last instruction that has been sent has completed processing. In most applications, I just tie the "R/W" line to ground because I don't read anything back. This simplifies the application because when data is read back, the microcontroller I/O pins have to be alternated between input and output modes.

For most applications, there really is no reason to read from the LCD. I usually tie "R/W" to ground and just wait the maximum amount of time for each instruction (4.1 msecs for clearing the display or moving the cursor/display to the "home position", 160 secs for all other commands). As well as making my application software simpler, it also frees up a microcontroller pin for other uses. Different LCDs execute instructions at different rates and to avoid problems later on (such as if the LCD is changed to a slower unit), I recommend just using the maximum delays given above. In terms of options, I have never seen a 5x10 LCD display. This means that the "F" bit in the "Set Interface Instruction" should always be reset (equal to "0"). Before you can send commands or data to the LCD module, the Module must be initialized. For eight bit mode, this is done using the following series of operations:
1. Wait more than 15 msecs after power is applied. 2. Write 0x030 to LCD and wait 5 msecs for the instruction to complete 3. Write 0x030 to LCD and wait 160 secs for instruction to complete 4. Write 0x030 AGAIN to LCD and wait 160 secs or Poll the Busy Flag 5. Set the Operating Characteristics of the LCD
o o o o o

Write "Set Interface Length" Write 0x010 to turn off the Display Write 0x001 to Clear the Display Write "Set Cursor Move Direction" Setting Cursor Behavior Bits Write "Enable Display/Cursor" & enable Display and Optional Cursor

In describing how the LCD should be initialized in four bit mode, I will specify writing to the LCD in terms of nibbles. This is because initially, just single nibbles are sent (and not two, which make up a byte and a full instruction). As I mentioned above, when a byte is sent, the high nibble is sent before the low nibble and the "E" pin is toggled each time four bits is sent to the LCD. To initialize in four bit mode:
1. Wait more than 15 msecs after power is applied. 2. Write 0x03 to LCD and wait 5 msecs for the instruction to complete 3. Write 0x03 to LCD and wait 160 secs for instruction to complete 4. Write 0x03 AGAIN to LCD and wait 160 secs (or poll the Busy Flag) 5. Set the Operating Characteristics of the LCD

o o o o o o

Write 0x02 to the LCD to Enable Four Bit Mode Write "Set Interface Length" Write 0x01/0x00 to turn off the Display Write 0x00/0x01 to Clear the Display Write "Set Cursor Move Direction" Setting Cursor Behavior Bits Write "Enable Display/Cursor" & enable Display and Optional Cursor

Once the initialization is complete, the LCD can be written to with data or instructions as required. Each character to display is written like the control bytes, except that the "R/S" line is set. During initialization, by setting the "S/C" bit during the "Move Cursor/Shift Display" command, after each character is sent to the LCD, the cursor built into the LCD will increment to the next position (either right or left). Normally, the "S/C" bit is set (equal to "1") along with the "R/L" bit in the "Move Cursor/Shift Display" command for characters to be written from left to right (as with a "Teletype" video display). One area of confusion is how to move to different locations on the display and, as a follow on, how to move to different lines on an LCD display. The following table shows how different LCD displays that use a single 44780 can be set up with the addresses for specific character locations. The LCDs listed are the most popular arrangements available and the "Layout" is given as number of columns by number of lines: Table 5.3 Layout of LCDs
LCD Layout 8x1 Top Left Ninth Character Character 0 N/A Second Line N/A Third Line N/A Fourth Line N/A Comments Single 44780/No Support Chip Single 44780/No Support Chip 44780 with Support Chip. This is quite rare Single 44780/No Support Chip 44780 with Support Chip

16x1

0x040

N/A

N/A

N/A

16x1

N/A

N/A

N/A

8x2 10x2

0 0

N/A 8

0x040 0x040

N/A N/A

N/A N/A

16x2 20x2 24x2 30x2 32x2 40x2 16x4 20x4 40x4

0 0 0 0 0 0 0 0 U/N

8 8 8 8 8 8 8 8 U/N

0x040 0x040 0x040 0x040 0x040 0x040 0x040 0x040 U/N

N/A N/A N/A N/A N/A N/A 0x020 0x020 U/N

N/A N/A N/A N/A N/A N/A 0x060 0x060 U/N

44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip Two 44780 with Support Chips.

5.2.2 Moving LCD cursor


The "Ninth Character" is the position of the Ninth character on the first line. Most LCD displays have a 44780 and support chip to control the operation of the LCD. The 44780 is responsible for the external interface and provides sufficient control lines for sixteen characters on the LCD. The support chip enhances the I/O of the 44780 to support up to 128 characters on an LCD. From the table above, it should be noted that the first two entries ("8x1", "16x1") only have the 44780 and not the support chip. This is why the ninth character in the 16x1 does not "appear" at address 8 and shows up at the address that is common for a two line LCD.

Fig.5.3 Moving LCD cursor

Normally, the LCD is wired as two 40x2 displays. The actual connector is normally sixteen bits wide with all the fourteen connections of the 44780 in common, except for the "E" (Strobe) pins. The "E" strobes are used to address between the areas of the display used by the two devices. The actual pin outs and character addresses for this type of display can vary between manufacturers and display part numbers. Note that when using any kind of multiple 44780 LCD display, you should probably only display one 44780's Cursor at a time. Cursors for the 44780 can be turned on as a simple underscore at any time using the "Enable Display/Cursor" LCD instruction and setting the "C" bit. I don't recommend using the "B" ("Block Mode") bit as this causes a flashing full character square to be displayed and it really isn't that attractive. The LCD can be thought of as a "Teletype" display because in normal operation, after a character has been sent to the LCD, the internal "Cursor" is moved one character to the right. The "Clear Display" and "Return Cursor and LCD to Home Position" instructions are used to reset the Cursor's position to the top right character on the display. To move the Cursor, the "Move Cursor to Display" instruction is used. For this instruction, bit 7 of the instruction byte is set with the remaining seven bits used as the address of the character on the LCD the cursor is to move to. These seven bits provide 128 addresses, which matches the maximum number of LCD character addresses available. The table above should be used to determine the address of a character offset on a particular line of an LCD display. The Character Set available in the 44780 is basically ASCII. I say "basically" because some characters do not follow the ASCII convention fully (probably the most significant difference is 0x05B or "\" is not available). The ASCII Control Characters (0x008 to 0x01F) do not respond as control characters and may display funny (Japanese) characters.

CHAPTER 6 SOFTWARE AND PROGRAMMING


6.1 SOFTWARE
We have used KEIL software for compiling our embedded C code.

6.1.1. Keil
The Keil C51 C Compiler for the 8051 microcontroller is the most popular 8051 C compiler in the world. It provides more features than any other 8051 C compiler available today.The C51 Compiler allows you to write 8051 microcontroller applications in C that have the efficiency and speed of assembly language. Language extensions in the C51 Compiler give you full access to all resources of the 8051. C51 translates C source files into a relocatable object module. When the DEBUG control is used, the object file contains full symbolic information for debugging with the Vision3 Debugger or an in-circuit emulator. In addition to the object file, the C51 Compiler generates a listing file which optionally may include symbol table and cross-reference information.

6.1.1.1Features

Nine basic data types, including 32-bit IEEE floating-point Flexible variable allocation with bit, data, bdata, idata, xdata, and pdata memory types Interrupt functions may be written in C Full use of the 8051 register banks Complete symbol and type information for source-level debugging Use of AJMP and ACALL instructions Bit-addressable data objects Built-in interface for the RTX51 real-time operating system Support for dual data pointers on Atmel, AMD, Cypress, Dallas Semiconductor, Infineon, Philips, and Transcend microcontrollers

Support for the Philips 8xC750, 8xC751, and 8xC752 limited instruction sets Support for the Infineon 80C517 arithmetic unit

6.2. PROGRAMMING
#include"reg51.h" #include"string.h" sbit sbit RS=P1^0; EN=P1^1;

#define LCDDATA P2 sbit key1 =P3^7; sbit key2 =P3^6; sbit key3 =P3^5; sbit key4 =P3^4; sbitmain_line =P1^2; sbitbackup_line =P1^3; voidsend_bits(int,unsigned char),display(int),lcdinit(); voiddisplayline(char*,int),delay(unsigned int t); unsigned char buffer[50],validkeyno=0,digit=0; unsigned char mode=0,phno[11]={0,0,0,0,0,0,0,0,0,0}; unsigned char phno1[11 ]={8,7,6,5,6,0,0,5,1,1}; unsigned char cursor_pos=0,set_phno=0,i; bit key1done=0,key2done=0,key3done=0; bit key4done=0,message_main=0; bitmessage_backup=0,message_main_line=0; voidkeysense(),keyserve(int),systeminit(); voidgsm_module_init(),putc(int i);

voidsend_ser_com(unsigned char *ptr ); void main() { systeminit(); while(1) { keysense(); if(main_line==0) { if(message_main==1) { message_main=0; message_main_line=1; } } if(message_main_line==1) { message_main_line=0; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13); strcpy(buffer, "MACHINE'S ARE NOW AGAIN WORKING ON MAIN'S "); send_ser_com(buffer); send_ser_com("at+cmgs="); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000);

putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48); putc('"');putc(13); strcpy(buffer, "YOUR UNIT IS NOW AGAIN WORKING ON MAIN'S "); send_ser_com(buffer);

} if(backup_line==0)message_backup=0; if(main_line==1 &&message_main==0 &&backup_line==0) { if(main_line==1 &&message_main==0 &&backup_line==0) { message_main=1; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "MACHINE'S ARE WORKING ON BACKUP POWER "); send_ser_com(buffer); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48);

putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "YOUR UNIT IS WORKING ON BACKUP POWER "); } } if(main_line==1 &&message_backup==0 &&backup_line==1) { if(main_line==1 &&message_backup==0 &&backup_line==1) { message_backup=1; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "WARNING! NO POWER BACKUP.SHUT DOWN "); send_ser_com(buffer); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "WARNING! YOUR UNIT IS NOT WORKING "); send_ser_com(buffer); send_ser_com(buffer);

} } } } voidsysteminit() { P0=0XFF;P1=0XFF;P2=0XFF;P3=0XFF; TMOD=0x20;TH1=0xfd;SCON=0x50; TR1=1;lcdinit();delay(60000); gsm_module_init(); } voidputc(int i) { } voidserialisr() interrupt 4 using 1 { if(TI) TI=0; if(RI) RI = 0; } voidsend_ser_com(unsigned char *ptr ) { while(*ptr) { } } SBUF=*ptr;ptr++;delay(10000); SBUF=i;delay(10000);

voidgsm_module_init() { displayline(" PLEASE WAIT ",1); displayline(" Initializing ",2); send_ser_com("at\r");delay(50000);delay(50000); send_ser_com("ate1\r");delay(5000);delay(50000); send_ser_com("at+cmgf=1\r");delay(5000);delay(50000); for(i=0;i<10;i++) { send_ser_com("at+cmgd="); SBUF=i+48;delay(50000); } displayline("**** WELCOME ***",1); displayline(" V.I.E.T GP-14 ",2); } voidkeysense(void) { if(key1 == 0) { delay(1000); if(key1 == 0) keyserve(1); } else { if(key2 == 0) { delay(1000); if(key2 == 0)

keyserve(2); } else { if(key3 == 0) { delay(1000); if(key3 == 0) keyserve(3); } else { if(key4 == 0) { delay(1000);

if(key4 == 0) keyserve(4); } else { key1done=0;key2done=0; key3done=0;key4done=0; } } } } } voidkeyserve(int key)

switch(key) { case 1:if(key1done==0 && mode==1) { key1done=1;

if(++digit>9)digit=0; phno[cursor_pos]=digit; send_bits(1,phno[cursor_pos]); }break; case 2:if(key2done==0 && mode==1) { key2done=1;

if(++cursor_pos>=10)cursor_pos=0; send_bits(0,cursor_pos+192); }break; case 3:if(key3done==0 && mode==1)//phone no enterd { key3done=1; displayline("**** WELCOME ***",1); displayline(" V.I.E.T GP-14 ",2); }break; case 4:if(!key4done) { key4done=1;mode=1;cursor_pos=0; displayline("SET PHONE NO----",1); for(i=0;i<10;i++) send_bits(1,phno[i]+48); }break;

} } voiddisplayline(char* ptr,int line) { if(line==0); else if(line==1)send_bits(0,0x80); else if(line==2)send_bits(0,0xc0); elsesend_bits(0,line); send_bits(1,*ptr),ptr++; } voidsend_bits(inti,unsigned char com) { LCDDATA = com; RS=i;EN=1;delay(10);EN=0; delay(100); } void delay(unsigned int t) { } voidlcdinit() { send_bits(0,0x38);delay(400); send_bits(0,0x0c);delay(100); send_bits(0,0x01); } for(;t>0;t--);

CHAPTER 7 APPLICATIONS AND CONCLUSION

APPENDIX 1 ABBREVIATIONS
AbbreviationFull form
IR LCD Liquid crystal display AC Alternating current DC Direct current Infrared

IC Integrated circuit MHz VVolts INT Vss GND Integer Virtual ground Ground Mega hertz

VDD Positive power supply CLK Clock ACK Acknowledgement LED Light emitting diode RAM Random access memory I/O Input/output

COST ANALYSIS

REFERENCES
www.atmel.com/images/doc1919.pdf www.keil.com/dd/chip/3411.html www.keil.com/uvision/ en.wikipedia.org/wiki/Capacitor en.wikipedia.org/wiki/Resistor www.usbr.gov/pmts/client_service/recent/studytransformers.pdf www.autoshop101.com/forms/hweb2.pdf www.physics.unlv.edu/~bill/PHYS483/relay.pdf www.tentuts.com/2012/.../lcd-interfacing-with-8051-in-assembly.html probots.co.in/Manuals/SIM300.pdf en.wikipedia.org/wiki/Diode www.technologystudent.com/elec1/transis1.htm

Potrebbero piacerti anche