INTERFACING LCD TO 89C51

Posted: January 5, 2011 in Uncategorized

INTERFACING LCD TO 89C51

Liquid crystal display is very important device in embedded system. It offers high flexibility to user as he can display the required data on it. But due to lack of proper approach to LCD interfacing many of them fail. Many people consider LCD interfacing a complex job but according to me LCD interfacing is very easy task, you just need to have a logical approach. This page is to help the enthusiast who wants to interface LCD with through understanding. Copy and Paste technique may not work when an embedded system engineer wants to apply LCD interfacing in real world projects.You will be knowing about the booster rockets on space shuttle. Without these booster rockets the space shuttle would not launch in geosynchronous orbit.

Similarly to understand LCD interfacing you need to have booster rockets attached! To get it done right you must have general idea howto approach any given LCD.This page will help you develop logical approach towards LCD interfacing.

First thing to begin with is to know what LCD driver/controller is used in LCD.Yes, your LCD is dumb it does not know to talk with your microcontroller. LCD driver is a link between the microcontroller and LCD. You can refer the datasheet of LCD to know the LCD driver for e.g. JHD 162A is name of LCD having driver HD44780U.You have to interface the LCD according to the driver specification. To understand the algorithm of LCD interfacing user must have datasheet of both LCD and LCD driver. Many people ignore the datasheets and end up in troubles. If you want to interface LCD successfully you must have datasheets.
Why people ignore datasheets? Most of us do not like to read 100 pages of datasheet. But for a accurate technical specification datasheets are must. I will show you a technique to manipulate a datasheet within minutes.
First thing to find out in datasheet is the features viz. operating voltage, type of interface, maximum speed for interface in MHz, size of display data RAM, number of pixels, bits per pixel, number of row and columns. You must have the pin diagram of LCD.Pin diagram of LCD driver can be omitted.
Study the type of communication protocol whether it is parallel or serial interface. Check how LCD discriminates data bytes and command bytes, which pins on LCD are used for communication. Study Interface timing diagram given in the datasheet.
From datasheet of LCD driver find out whether hardware reset is required at startup, what is the time of reset pulse, is it active low and which pins of LCD are to be toggled.
Major task in LCD interfacing is the initialization sequence. In LCD initialization you have to send command bytes to LCD. Here you set the interface mode, display mode, address counter increment direction, set contrast of LCD, horizontal or vertical addressing mode, color format. This sequence is given in respective LCD driver datasheet. Studying the function set of LCD lets you know the definition of command bytes. It varies from one LCD to another. If you are able to initialize the LCD properly 90% of your job is done.
Next step after initialization is to send data bytes to required display data RAM memory location. Firstly set the address location using address set command byte and than send data bytes using the DDRAM write command. To address specific location in display data RAM one must have the knowledge of how the address counter is incremented.
Schematic

Algorithm to send data to LCD:

1.Make R/W low
2.Make RS=0 ;if data byte is command
RS=1 ;if data byte is data (ASCII value)
3.Place data byte on data register
4.Pulse E (HIGH to LOW)
5.Repeat the steps to send another data byte

LCD Initialization:

This is the pit fall for beginners.Proper working of LCD depend on the how the LCD is initialized. We have to send few command bytes to initialize the lcd. Simple steps to initialize the LCD
1.Specify function set:
Send 38H for 8-bit,double line and 5×7 dot character format.
2.Display On-Off control:
Send 0FH for display and blink cursor on.
3.Entry mode set:
Send 06H for cursor in increment position and shift is invisible.
4. Clear display:
Send 01H to clear display and return cursor to home position.

My 8051 Development cum

Programmer board

Addresses of cursor position for 16×2 HD44780 LCD

line1 80H 81H 82H 83H 84H 85H 86H 87H 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH
line2 C0H C1H C2H C3H C4H C5H C6H C7H C8H C9H CAH CBH CCH CDH CEH CFH

Assembly Language Code

; Interfacing LCD 16×2 in 4-bit mode.
; Port0 to higher nibble data pins of LCD
; Crystal 3.579545 MHz
; AT89C51
;P2.0 to RS pin
;P2.1 to Enable Pin

ORG 0000H
AJMP MAIN
ORG 0030H
MAIN:
MOV SP,#60H ;STACK POINTER
ACALL LCD_INIT ;Initialize lcd
MOV DPTR,#MESSAGE1
CALL LCD_STRING ;Display message on LCD
CALL NEXT_LINE ;Place cursor to;second Line
MOV DPTR,#MESSAGE2 
CALL LCD_STRING ;Display message on LCD
HERE: AJMP HERE

LCD_INIT: ;initialize LCD in 4-bit mode
ANL P0,#0F0H
CALL LOOP
MOV DPTR,#LCDCODE
MOV A,#0H
MOV R6,#0H
MOV R7,#0H
CLR P2.0 ;RS COMMAND
NEXT: ;8-bit code is split into two 4-bit nibbles.
INC R6
MOVC A,@A+DPTR
MOV R7,A
ANL A,#0F0H
SWAP A
ANL P0,#0F0H
ORL P0,A
ACALL ENABLE ;PULSE E sending first nibble
MOV A,R7
ANL A,#0FH
ANL P0,#0F0H
ORL P0,A
ACALL ENABLE ;PULSE E sending second nibble
MOV A,R6
CJNE R6,#09H,NEXT
RET

LCD_STRING:
MOV P0,#00H
SETB P2.0 ;RS DATA
MOV A,#00H
MOV R6,#00H
NC: ;checks the end of message string
MOVC A,@A+DPTR
CJNE A,#2FH,NC1
RET
NC1:
LCALL LCD_WRITE
INC R6
MOV A,R6
AJMP NC

LCD_WRITE:
SETB P2.0 ;RS DATA
CALL LO
RET

NEXT_LINE:
MOV P0,#00H
CLR P2.0 ;RS COMMAND
MOV A,#0C0H
CALL LO
RET

LCD_CLEAR: ;This Subroutine is used to clear LCD
CALL DELAYL
ANL P0,#00H
MOV A,#01H
CLR P2.0 ; RS command
LO: ;8-bit code is split into two 4-bit nibbles.
MOV R7,A
ANL A,#0F0H
SWAP A
ANL P0,#0F0H
ORL P0,A
CALL ENABLE
MOV A,R7
ANL A,#0FH
ANL P0,#0F0H
ORL P0,A
CALL ENABLE
RET

ENABLE: ;Give High-to-low pulse at enable pin
SETB P2.1
CALL DELAYL
CLR P2.1
CALL DELAYL
RET

;With respect to crystal frequency 3.579 MHz
DELAYL: ; 5ms DELAY
SETB PSW.4 ; SELECT BANK 2
MOV R7,#25
HDH:
MOV R6,#60
DJNZ R6,$
DJNZ R7,HDH
CLR PSW.4 ;DEFAULT BANK
RET

LOOP: ;1 SEC DELAY
MOV R7,#100
LOOP1:
CALL DELAYL
CALL DELAYL
DJNZ R7,LOOP1
RET

;LCD INITIALIZING CODE (DO NOT DISTURB THIS)
LCDCODE:
DB 02H
DB 02H
DB 02H
DB 28H
DB 28H
DB 28H
DB 0CH
DB 06H
DB 01H

;DATA TO BE DISPLAYED

;Maximum message length = 16 characters.
;To notify end of message place ‘/’ at the end.

MESSAGE1: DB “LCD INTERFACING /” ;Change Message1

MESSAGE2: DB ” BY JAYANTH /” ;Change Message2

END

 

Advertisements

ULTRA SONIC MOTION DETECTOR

Posted: January 5, 2011 in Uncategorized

ULTRA SONIC MOTION DETECTOR

This Ultrasonic Sensor Circuit consists of a set of ultrasonic receiver and transmitter which operate at the same frequency. When something moves in the area covered the circuit’s fine balance is disturbed and the alarm is triggered. The ultrasonic circuit is very sensitive and can be adjusted to reset itself automatically or to stay triggered till it is reset manually after an alarm.

The ultra sonic transmitter is built around two NAND gates wired as inverters and they form a multivibrator the output of which drives the transducer. The trimmer P2 adjusts the output frequency of the transmitter and for greater efficiency it should be made the same as the frequency of resonance of the transducers in use. The ultrasonic receiver uses a transducer to receive the signals that are reflected back to it the output of which is amplified by the transistor TR3, and IC1 which is a 741 op-amp. The output of IC1 is taken to the non inverting input of IC2 the amplification factor of which is adjusted by means of P1.

How the ultrasonic sensor works?

The ultra sonic circuit is adjusted in such a way as to stay in balance as long the same as the output frequency of the transmitter. If there is some movement in the area covered by the ultrasonic emission the signal that is reflected back to the receiver becomes distorted and the circuit is thrown out of balance. The circuit works from 9-12 VDC and can be used with batteries or a power supply.

Ultra Sonic Detector Construction

The board is made of a thin insulating material clad with a thin layer of conductive copper that is shaped in such a way as to form the necessary conductors between the various components of the circuit. The use of a properly designed printed circuit board is very desirable as it speeds construction up considerably and reduces the possibility of making errors. In order to solder a component correctly you should do the following:

  • Clean the component leads with a small piece of emery paper.
  • Bend them at the correct distance from the component’s body and insert the component in its place on the board.
  • You may find sometimes a component with heavier gauge leads than usual, that are too thick to enter in the holes of the p.c. board.
  • In this case use a mini drill to enlarge the holes slightly. Do not make the holes too large as this is going to make soldering difficult afterwards.
  • Take the hot iron and place its tip on the component lead while holding the end of the solder wire at the point where the lead emerges from the board. The iron tip must touch the lead slightly above the p.c. board.
  • When the solder starts to melt and flow wait till it covers evenly the area around the hole and the flux boils and gets out from underneath the solder. The whole operation should not take more than 5 seconds. Remove the iron and allow the solder to cool naturally without blowing on it or moving the component. If everything was done properly the surface of the joint must have a bright metallic finish and its edges should be smoothly ended on the component lead and the board track. If the solder looks dull, cracked,or has the shape of a blob then you have made a dry joint and you should remove the solder (with a pump, or a solder wick) and redo it.
  • Take care not to overheat the tracks as it is very easy to lift them from the board and break them.
  • When you are soldering a sensitive component it is good practice to hold the lead from the component side of the board with a pair of long-nose pliers to divert any heat that could possibly damage the component.
  • Make sure that you do not use more solder than it is necessary as you are running the risk of short-circuiting adjacent tracks on the board, especially if they are very close together.
  • When you finish your work cut off the excess of the component leads and clean the board thoroughly with a suitable solvent to remove all flux residues that may still remain on it.
  • There are quite a few components in the circuit and you should be careful to avoid mistakes that will be difficult to trace and repair afterwards. Solder first the pins and the IC sockets and then following if that is possible the parts list the resistors the trimmers and the capacitors paying particular attention to the correct orientation of the electrolytic.
  • Solder then the transistors and the diodes taking care not to overheat them during soldering. The transducers should be positioned in such a way as they do not affect each other directly because this will reduce the efficiency of the circuit. When you finish soldering, check your work to make sure that you have done everything properly, and then insert the IC’s in their sockets paying attention to their correct orientation and handling IC3 with great care as it is of the CMOS type and can be damaged quite easily by static discharges. Do not take it out of its aluminium foil wrapper till it is time to insert it in its socket, ground the board and your body to discharge static electricity and then insert the IC carefully in its socket. In the kit you will find a LED and a resistor of 560 — which will help you to make the necessary adjustments to the circuit. Connect the resistor in series with the LED and then connect them between point 9 of the circuit and the positive supply rail (point 1).
COMPONENTS:

Connect the power supply across points 1 (+) and 2 (-) of the p.c. board and put P1 at roughly its middle position. Turn then P2 slowly till the LED lights when you move your fingers slightly in front of the transducers. If you have a frequency counter then you can make a much more accurate adjustment of the circuit. Connect the frequency counter across the transducer and adjust P2 till the frequency of the oscillator is exactly the same as the resonant frequency of the transducer. Adjust then P1 for maximum sensitivity. Connecting together pins 7 & 8 on the p.c. board will make the circuit to stay triggered till it is manually reset after an alarm. This can be very useful if you want to know that there was an attempt to enter in the place which are protected by the radar

 

MOBILE DETECTOR

Posted: January 5, 2011 in Uncategorized

MOBILE DETECTOR

The circuit can detect both the incoming and outgoing calls, SMS and video transmission even if the mobile phone is kept in the silent mode. The moment the bug detects RF transmission signal from an activated mobile phone, it starts sounding a beep alarm and the LED blinks. The alarm continues until the signal transmission ceases.

An ordinary RF detector using tuned LC circuits is not suitable for detecting signals in the GHz frequency band used in mobile phones. The transmission frequency of mobile phones ranges from 0.9 to 3 GHz with a wavelength of 3.3 to 10 cm. So a circuit detecting gigahertz signals is required for a mobile bug.
Here the circuit uses a 0.22μF disk capacitor (C3) to capture the RF signals from the mobile phone. The lead length of the capacitor is fixed as 18 mm with a spacing of 8 mm between the leads to get the desired frequency. The disk capacitor along with the leads acts as a small gigahertz loop antenna to collect the RF signals from the mobile phone.

Op-amp IC CA3130 (IC1) is used in the circuit as a current-to-voltage converter with capacitor C3 connected between its inverting and non-inverting inputs. It is a CMOS version using gate-protected p-channel MOSFET transistors in the input to provide very high input impedance, very low input current and very high speed of performance. The output CMOS transistor is capable of swinging the output voltage to within 10 mV of either supply voltage terminal.
Capacitor C3 in conjunction with the lead inductance acts as a transmission line that intercepts the signals from the mobile phone. This capacitor creates a field, stores energy and transfers the stored energy in the form of minute current to the inputs of IC1. This will upset the balanced input of IC1 and convert the current into the corresponding output voltage.
Capacitor C4 along with high-value resistor R1 keeps the non-inverting input stable for easy swing of the output to high state. Resistor R2 provides the discharge path for capacitor C4. Feedback resistor R3 makes the inverting input high when the output becomes high. Capacitor C5 (47pF) is connected across ‘strobe’ (pin 8) and ‘null’ inputs (pin 1) of IC1 for phase compensation and gain control to optimise the frequency response.
When the cell phone detector signal is detected by C3, the output of IC1 becomes high and low alternately according to the frequency of the signal as indicated by LED1. This triggers monostable timer IC2 through capacitor C7. Capacitor C6 maintains the base bias of transistor T1 for fast switching action. The low-value timing components R6 and C9 produce very short time delay to avoid audio nuisance.
Assemble the cell phone detector circuit on a general purpose PCB as compact as possible and enclose in a small box like junk mobile case. As mentioned earlier, capacitor C3 should have a lead length of 18 mm with lead spacing of 8 mm. Carefully solder the capacitor in standing position with equal spacing of the leads. The response can be optimised by trimming the lead length of C3 for the desired frequency. You may use a short telescopic type antenna.
Use the miniature 12V battery of a remote control and a small buzzer to make the gadget pocket-size. The unit will give the warning indication if someone uses mobile phone within a radius of 1.5 meters.
Check the related posts for more mobile phone detectors.

 

Constructing an FM Phone Transmitter

This project provides the schematic and the parts list needed to construct a FM Phone Transmitter. This device attaches in series to one of your phone lines. When there is a signal on the line (that is, when you pick up the handset) the circuit will transmit the conversation a short distance. In particular it will radiate from the phone line itself. It is a passive device – there is no battery. It uses the signal on the phone line for power. No aerial is needed – it feeds back the RF signal into the phone line which radiates it in the FM band. The frequency of transmission may be adjusted by the trimcap. Note that some countries may ban any electronic device which attaches to the telephone. It is the responsibility of the constructor to check the legal requirements for the operation of this FM Phone Transmitter and to obey them.


FM Phone Transmitter Circuit Description


The circuit is a radio frequency (RF) oscillator that operates around 93 MHz (93 million cycles per second).Power for the circuit is derived from the full wave diode bridge. C1, C8, L3 & T1 forms the FM oscillator.
Every Tx needs an oscillator to generate the Radio Frequency (RF) carrier waves. L1, C6, T2 forms the power amplifier. Audio from the telephone lines is coupled through R3 & C2 into the base of T1 to modulate the oscillator. This is done by varying the junction capacitance of the transistor. Junction capacitance is a function of the potential difference applied to the base of the transistor. R1 & C4 act as a low pass filter.
C3 is a high frequencyshunt. L2 is call a RFC (radio frequency shunt.) It decouples the power and audio from the transmitter amplifier circuit.This type of circuit usually should be calibrated. The resonant frequency of the L1-C6 amplifier circuit should beadjusted to match the resonent oscillator frequency of C1, C9-L3. However, in practice, we think you will find thatthe unit operates perfectly OK as it is constructed without the need to calibrate anything. If you want to try calibration you will need a frequency meter, a CRO or just trial and error.
Calibrate by moving the coils of L1 further apart. With C1 at 27p you will find that the it tunes into the FM band in the 86 – 95 MHz area. With C1 at 22p the band is raised to about 90-95mhz (depending in the coil spacing.) If you want to move this tunable area still higher to over 100MHz range then replace C1 by a 15pF or 10pF capacitor. This assumes that the on-hook voltage is about the standard 48V. If the on-hook voltage of an extension phone network is lower, say about 39V, C1 will have to be lower in the 15p to 10p range to be in the commercial FM band in this case.
Note that you should not hold the printed circuit board physically in your hands if you try to do any calibration. Your own body capicitance when you touch it is more than enough to change the oscillation frequency of the whole unit.
You can experiment the FM Phone Transmitter to get greater transmission range away from the phone line by adding an aerial (about 150 cm of 26 gauge wire) to the collector of T2.
FM Phone Transmitter Assembly Instructions
The ZTX320 has a flat and a curved side. Match these two sides with the flat and curved sides as shown on theoverlay for T2. Also note these points when assembling this project:
1) Two of the three coils have enamel insulation lacquer on them. This must be physically removed from bothends of the coil before it can be soldered. Now during the manufacture of these coils they have been solderdipped to remove this lacquer. But check each leg to see that this is the case.
2) Spread out the turns in the L3 coil about 1 mm apart. The coils should not touch.
3) A solder connection (or tap) is required from the top of the first turn in the L3 coil to the pad next to the coil. Solder a piece of wire to the top of the first turn as shown on the overlay. Then solder theother end to the pad immediately next to the L3 coil.
4) The cathodes of all diodes point to the top of the PCB.
5) Attach 3″ of wire with an alligator clip on the end to the pads between the diodes marked – ‘TO LINE’ No aerial is needed. The phone line itself acts as a sufficient aerial. To make the Kit small, resistors & diodesstand on their ends. The kit attaches to ONE of the two phone lines going to your phone. Either of the two lines will do. In most of the world this is the green or red wire. In the UK it is one of the wires attached to the terminals 2 or 5. Cut the phone line. Attach one alligator clip to one cut end and the other alligator clip tothe other cut end. Take your phone off the hook and turn on an FM radio at about 93 MHz. It should be very easyto tune into the transmission. Take a portable FM receiver outside and follow the phone line.
FM Phone Transmitter Parts List

 

Solar Charger Circuit Diagram

Posted: January 5, 2011 in Uncategorized

Solar Charger Circuit Diagram

The circuit uses a 12 volt solar panel and a variable voltage regulator IC LM 317. The solar panel consists of solar cells each rated at 1.2 volts. 12 volt DC is available from the panel to charge the battery. Charging current passes through D1 to the voltage regulator IC LM 317. By adjusting its Adjust pin, output voltage and current can be regulated. VR is placed between the adjust pin and ground to provide an output voltage of 9 volts to the battery. Resistor R3 Restrict the charging current and diode D2 prevents discharge of current from the battery. Transistor T1 and Zener diode ZD act as a cut off switch when the battery is full. Normally T1 is off and battery gets charging current. When the terminal voltage of the battery rises above 6.8 volts, Zener conducts and provides base current to T1. It then turns on grounding the output of LM 317 to stop charging.

MAKE A JOULE THIEF

Posted: January 5, 2011 in Uncategorized

MAKE A JOULE THIEF

Here is small,yet powerful circuit/project that can be used t light a LED from a single AA or AAA battery.you can light a LED with a dead cell.
Here’s the Joule thief. It’s like an open PCB torch that will take either an AA or AAA battery in the holder and use whatever power is left in the battery to light a white LED.
The amazing thing about this circuit is that it will run right down to about 0.35V if left running continuously, and will often provide a week of continuous low level light from a battery that would normally be considered dead.
The level of light is initially quite high but gradually reduces as the battery voltage goes lower. However, it can still be used for reading in a dark room, even when the battery is almost completely drained.
Take a metre of the 38swg (0.15mm) enamelled wire and fold it in half making sure that the point of the fold is nice and sharp since it will be used to thread the wire round the ferrite bead. It is important to lay the wire on evenly and pull it firmly round the form since you will need to make twenty turns of the doubled wire and it’s a tight fit.Don’t worry if you make a mess of it, since the ferrite bead can be re-used and you will have lots of spare wire to practice with.
The whole process of winding the bead is the most tricky part of the project and is made slightly more awkward by the fact you are winding two coils on simultaneously.When you pull the loop of wire through the bead be sure to carefully guide the loop through so that it doesn’t twist . When the bead is wound you should have a pair of wires sticking out each end. Crop them to about 2″ (50mm) and tin the ends, then meter them to find which wires are part of the same winding.
Now assemble the joule thief circuit with reference to the circuit diagram given above. And enjoy!!!

 

Hello world!

Posted: January 4, 2011 in Uncategorized

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!