You are on page 1of 41

POWER SUPPLY The power supply designed for catering a fixed demand connected in this project.

The basic requirement for designing a power supply is as follows, 1. The voltage levels required for operating the devices is +5volt. Here +5Volt required for operating microcontroller. And as well as required for drivers and amplifiers and ir transmitters and receivers. 2. The current requirement of each device or load must be added to estimate the final capacity of the power supply. The power supply always specified with one or multiple voltage outputs along with a current capacity. As it is estimate the requirement of power is approximately as follows, Out Put Voltage = +5Volt, Capacity = 1000mA The power supply is basically consisting of three sections as follows, 1. 2. 3. Step down section Rectifier Section Regulator section

Design principle: There are two methods for designing power supply, the average value method and peak value method. In case of small power supply peak value method is quit economical, for a particular value of DC output the in put AC requirement is appreciably less. In this method the DC out put is approximately equal to Vm. A full wave bridge rectifier is designed using two diodes and the output of the rectifier is filtered with a low pass filter. The capacitor value is decided so that it will back up for the voltage and current during the discharging period of

the DC output. In this case the out put with reference to the center tap of the transformer is taken in to consideration, though the rectifier designed is a full wave bridge rectifier but the voltage across the load is a half wave rectified out put. The Regulator section used here is configured with a series regulator LM78XX the XX represents the output voltage and 78 series indicates the positive voltage regulator 79 series indicates the negative regulator for power supply. The positive regulator works satisfactorily between the voltage XX+2 to 40 Volt DC. The output remains constant within this range of voltage. The output remains constant within this range of voltage.

Circuit connection: - In this we are using Transformer (12-0-12) v / 1mA, IC 7805 , diodes IN 4007,LED & resistors. Here 230V, 50 Hz ac signal is given as input to the primary of the transformer and the secondary of the transformer is given to the bridge rectification diode. The positive out put of the bridge rectifier is given as i/p to the IC regulator (7805) through capacitor

(1000uf/25v).

The o/p of the IC regulator is given to the LED

through resistors to act as indicator. Circuit Explanations: - When ac signal is given to the primary of the transformer, due to the magnetic effect of the coil magnetic flux is induced in the coil (primary) and transfer to the secondary coil of the transformer due to the transformer action. Transformer is an electromechanical static device which transformer electrical energy from one coil to another without changing its frequency. Here the diodes are connected to the two +12volt output of the transformer. The secondary coil of the transformer is given to the diode circuit for rectification purposes. During the +ve cycle of the ac signal the diodes D1 conduct due to the forward bias of the diodes and diodes D2 does not conduct due to the reversed bias of the diodes. Similarly during the ve cycle of the ac signal the diodes D2 conduct due to the forward bias of the diodes and the diodes D1 does not conduct due to reversed bias of the diodes. The output of the bridge rectifier is not a power dc along with rippled

ac is also present. To overcome this effect, a low pass filter is connected to the o/p of the diodes (D1 & D2). Which removes the unwanted ac signal and thus a pure dc is obtained. Here we need a fixed voltage, thats for we are using IC regulators (7805 ).Voltage regulation is a circuit that supplies a constant voltage regardless of changes in load current. This ICs are designed as fixed voltage regulators and with adequate heat sinking can deliver output current in excess of 1A. The o/p the full wave rectifier is given as input to the IC regulator through low pass filter with respect to GND and thus a fixed o/p is obtained. The o/p of the IC regulator (7805) is given to the LED for indication purpose through resistor. Due to the forward bias of the LED, the LED glows ON state, and the o/p are obtained from the pin no-3. MICROCONTROLLER BLOCK DIAGRAM

PB0-PB7

PD0-PD7

The microcontroller used here is atmega 16 which has inbuilt adc and counter along with microcontroller.the pin configuration and details are given below. The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega16 provides the following features: 16K bytes of InSystem Programmable Flash Program memory with Read-WhileWrite capabilities, 512 bytes EEPROM, 1K byte SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundary-scan, On-chip Debugging support and programming, three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, a

byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain (TQFP package only),a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low-power consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to run. The device is manufactured using Atmels high density nonvolatile memory technology. The On-chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the Application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega16 is a powerful microcontroller that

provides a highly-flexible and cost-effective solution to many embedded control applications. The ATmega16 AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits.

Pin Descriptions

VCC Digital supply voltage. GND Ground. Port A (PA7..PA0) Port A serves as the analog inputs to the A/D Converter.

Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.Port B also serves the functions of various special features of the ATmega16 . Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running. If the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs. Port C also serves the functions of the JTAG interface and other special features of the ATmega16 as listed on page 61. Port D (PD7..PD0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the

clock is not running. Port D also serves the functions of various special features of the ATmega16. RESET Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. The minimum pulse length is 0.1 vcc. Shorter pulses are not guaranteed to generate a reset. XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting Oscillator amplifier. AVCC AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. AREF AREF is the analog reference pin for the A/D Converter.

Adc 10-bit Resolution 0.5 LSB Integral Non-linearity 2 LSB Absolute Accuracy 13 - 260 s Conversion Time Up to 15 kSPS at Maximum Resolution 8 Multiplexed Single Ended Input Channels 7 Differential Input Channels 2 Differential Input Channels with Optional Gain of 10x and 200x(1) Optional Left adjustment for ADC Result Readout 0 - VCC ADC Input Voltage Range Selectable 2.56V ADC Reference Voltage Free Running or Single Conversion Mode ADC Start Conversion by Auto Triggering on Interrupt Sources Interrupt on ADC Conversion Complete Sleep Mode Noise Canceler

Motor In any electric motor, operation is based on simple electromagnetism. A current-carrying conductor generates a magnetic field; when this is then placed in an external magnetic field, it will experience a force proportional to the current in the conductor, and to the strength of the external magnetic field. As you are well aware of from playing with magnets as a kid, opposite (North and South) polarities attract, while like polarities (North and North, South and South) repel. The internal configuration of a DC motor is designed to harness the magnetic interaction between a current-carrying conductor and an external magnetic field to generate rotational motion. Let's start by looking at a simple 2-pole DC electric motor (here red represents a magnet or winding with a "North" polarization, while green represents a magnet or winding with a "South" polarization).

Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator, commutator, field magnet(s), and brushes. In most common DC motors (and all that BEAMers will see), the external magnetic field is produced by high-strength permanent magnets1. The stator is the stationary part of the motor -- this includes the motor casing, as well as two or more permanent magnet pole pieces. The rotor (together with the axle and attached commutator) rotate with respect to the stator. The rotor consists of windings (generally on a core), the windings being

electrically connected to the commutator. The above diagram shows a common motor layout -- with the rotor inside the stator (field) magnets. The geometry of the brushes, commutator contacts, and rotor windings are such that when power is applied, the polarities of the energized winding and the stator magnet(s) are misaligned, and the rotor will rotate until it is almost aligned with the stator's field magnets. As the rotor reaches alignment, the brushes move to the next commutator contacts, and energize the next winding. Given our example two-pole motor, the rotation reverses the direction of current through the rotor winding, leading to a "flip" of the rotor's magnetic field, driving it to continue rotating. In real life, though, DC motors will always have more than two poles (three is a very common number). In particular, this avoids "dead spots" in the commutator. You can imagine how with our example two-pole motor, if the rotor is exactly at the middle of its rotation (perfectly aligned with the field magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is a moment where the commutator shorts out the power supply (i.e., both brushes touch both commutator contacts simultaneously). This would be bad for the power supply, waste energy, and damage motor components as well. Yet another disadvantage of such a simple motor is that it would exhibit a high amount of torque "ripple" (the amount of torque it could produce is cyclic with the

position of the rotor). So since most small DC motors are of a three-pole design, let's tinker with the workings of one via an interactive animation (JavaScript required):

You'll notice a few things from this -- namely, one pole is fully energized at a time (but two others are "partially" energized). As each brush transitions from one commutator contact to the next, one coil's field will rapidly collapse, as the next coil's field will rapidly charge up (this occurs within a few microsecond). We'll see more about the effects of this later, but in the meantime you can see that this is a direct result of the coil windings' series wiring:

There's probably no better way to see how an average DC motor is put together, than by just opening one up. Unfortunately this is tedious work, as well as requiring the destruction of a perfectly good motor. Luckily for you, I've gone ahead and done this in your stead. The guts of a disassembled Mabuchi FF-030-PN motor (the same model that Solarbotics sells) are available for you to see here (on 10 lines / cm graph paper). This is a basic 3pole DC motor, with 2 brushes and three commutator contacts. The use of an iron core armature (as in the Mabuchi, above) is quite common, and has a number of advantages2. First off, the iron core provides a strong, rigid support for the windings -- a particularly important consideration for high-torque motors. The core also conducts heat away from the rotor windings, allowing the motor to be driven harder than might otherwise be the case. Iron core construction is also relatively inexpensive compared with other construction types. But iron core construction also has several disadvantages. The iron armature has a relatively high inertia which limits motor acceleration. This construction also results in high winding inductances which limit brush and commutator life. In small motors, an alternative design is often used which features a 'coreless' armature winding. This design depends upon the coil wire itself for structural integrity. As a result, the armature is hollow, and the permanent magnet can be mounted inside the rotor coil. Coreless DC motors have much lower armature inductance than iron-core motors of comparable size, extending brush and commutator life.

Motor driver
L293D has two channels. i.e, you can connect two motors to the same bridge. I have driven 4 motors of 250mA using L293D, with 2 motor in each channel. Now let's see the ratings of L293D Output Current 1 A Per Channel (600 mA for L293D)

Peak Output Current 2 A Per Channel (1.2 A for L293D) Maximum VC 4.5 to 36V (>VSS)( it should be greater than or equal the supply voltage,vss) input side(input to L293D from parallel port or microcontroller)
VIH High-level input voltage( a voltage which L293D takes input as HIGH(1)) VC 7 V (2.3 to VC) VC 7 V (2.3 to 7 V) VIL High-level input voltage( a voltage which L293D takes input as LOW(0))

remember that VIL should not be less than -.3V output side(output of L293D to motor)
(-.3 to 1.5V),

VOH High-level output voltage (VCC2 1.8, VCC2 1.4) VOL Low-level output voltage (1.2v , 1.8v) If you want to use PWM to control L293D then apply PWM output to the chip inhibit of the IC. Remember all these parameters when you connect L293D in circuits. L293B are available, if you use it use 4 external protection diodes. L293D costs around Rs.90 . I have seen too many post about the problems occurring L293D, so here i am explaining things in more detail, how to connect L293D in circuit so that it won't create any problems to you.

TROUBLESHOOTING L293D: 1. Insert IC into the breadboard. Make sure that IC is inserted properly into breadboard. You can verify it using continuity test in the multimeter. Test continuity between the pins of the IC and the holes of the breadboard. If you get a beep then you can sure that IC is fitted strongly into breadboard and the portion of breadboard you are using is good. 2. Test the continuity in the 16 pins of the IC and the breadboard holes, to make sure that nothing goes wrong. You should be thorough with the steps you are taking. 3. Apply Vss=5V(Pin 16) . The first thing to apply when you connect an IC is applying Vcc and ground. Remember Vss should be in the range of 4.5V to 7V 4. Now connect ground at Pins 4, 5,12,13. Remember if you use multiple supplies, you should short circuit all grounds and this ground is applied to the Pins. 5. Now Vss and Gnd applying is over. 6. Now apply +5V to chip enable pins . Chip enable pins are pin1,9 7. Here we are trying to use both channels, atleast test both channels of the IC so that we can test whether IC is good or not. 8. Apply Vc at Pin8. For testing the IC you can apply Vc=Vss=5V. When you connect the motor you should apply Vc>Vss or may it can be equal also. I have tested it. 9. The following test are done for each channels separatively. In the following explanation I refer '1' as +5V(Vss) and '0' as ground. 10.Apply Input 1 = Input 2 =0( ie,ground ) and connect multimeter to output 1 and ground of the circuit. Now test output1 and output2 voltages. Both should be zero at this condition. 11.Apply Input1=1 and Input2=0 and check voltages at output1 and output2. Remember your multimeter's one lead should be ground. Then you should get one output= Vc and other output = 0. Suppose if you got output1=Vc and output2=0. 12.Apply Input1=0 and Input2=1 and check voltages at output1 and output2. Then output1=0 and output2=Vc. That is this case is should be reverse of the previous case, motor will rotate in opposite direction. 13.Apply Input1=1 and Input2=1 and check voltages at output1 and output2. Then output1=output2=Vc. This is the braking case. 14.Test conditions 10-13 for both channels to test the IC is good. You should test it thoroughly so that a repetition is not needed. If your IC is not working, repeat steps 1-13 to make sure IC is bad. 15.The most problems occurring are breadboard problems,IC not inserted properly, applying Vss and Vc wrongly(this can sometimes

cause problems to IC), not disabling chip inhibit,absence of common ground. 16. If you are applying Vc=Vss = +5V, then you can use two LED's to see outputs. 17.When chip inhibit is enabled, ie chip is not working the outputs will be high impedance, you can test high impedance using an LED. First connect the cathode of LED to ground through a series resistor of 330ohm and test the output. LED will not glow. The apply 5V to the anode of the LED and apply output to the cathode through a series resistor of 330 ohm. Now also LED won't glow. Now you can assure that the output is high impedance. 18.Before connecting motor to the outputs of L293D, first test the motor is working with the desired VC by applying VC and ground directly to the two leads of the motor. Confirm this first, then connect the motor. 19.L293d has a thermal shutdown function. So see it is working in all conditions of the circuit and robot

RF TRANSMITTER
Introduction
Radio Frequency Technology Radio Frequency (RF) in the range of 3 Hz and 30 GHz. RF communications are typically support 1200 to 9600 baud. Recently developed modulation schemes and spread spectrum technologies are achieving up to 19,200 baud.

RF technology evolution challenges:


Higher frequency utilization Higher bit rates and thus larger BWs RF is affected by absorption, multi path interference, EMI etc. RF is affected by material like steel, wall, window glass etc.

Radio based on frequency convertible platforms. Flexible and scalable modular architecture. Increased integration to fit new standards and frequencies in the same cabinet Co-sitting capabilities with other standards requires high performance transmitters and receivers.

RF Network Configuration: System Identification Should be unique Channel / Frequency Should have minimal interference with other systems Data Rates.

TLP434A Ultra Small Transmitter Diagram

Frequency 315, 418 and 433.92 Mhz Modulation : ASK

Operation Voltage
Pin Specifications Pin 1: GND Pin 2: Data In

: 2 - 12 VDC

Pin 3: Vcc Pin 4: Antenna (RF output)

RF Transmitter Specifications

Application Circuit
Typical Key-chain Transmitter using HT12E-18DIP, a Binary 12 bit Encoder from Holtek Semiconductor Inc.

RF RECEIVER
Introduction

Radio Frequency Technology: Radio Frequency (RF) in the range of 3 Hz and 30 GHz. RF communications are typically support 1200 to 9600 baud. Recently developed modulation schemes and spread spectrum technologies are achieving up to 19,200 baud.

RF technology evolution challenges: Higher frequency utilization Higher bit rates and thus larger BWs RF is affected by absorption, multi path interference, EMI etc. RF is affected by material like steel, wall, window glass etc.

Radio based on frequency convertible platforms. Flexible and scalable modular architecture. Increased integration to fit new standards and frequencies in the same cabinet. Co-sitting capabilities with other standards requires high performance transmitters and receivers.

RF Network Configuration: System Identification Should be unique Channel / Frequency Should have minimal interference with other systems Data Rates

RLP434A SAW Based Receiver Diagram

Frequency 315, 418 and 433.92 MHz


Modulation Supply Voltage Output : ASK : 3.3 - 6.0 VDC : Digital & Linear

Pin Specifications Pin 1: Gnd Pin 2: Digital Data Output Pin 3: Linear Output /Test Pin 4: Vcc Pin 5: Vcc Pin 6: Gnd Pin 7: Gnd Pin 8: Antenna

RF Receiver Specifications

Application Circuit Typical RF Receiver using HT12D-18DIP, a Binary 12 bit Decoder with 8 bit uC HT48RXX from Holtek Semiconductor Inc.

DISPLAY DEVICES LCD(liquid crystal display) Introduction

Liquid Crystal Displays ( LCD ) are widely used as output in small systems especially robots . With there ability to display human readable text they are also a great add on to robots and can output great amount of information or be used as a system from which the user can interact . In this simple tutorial you will learn how to interface LCD's , what are the signal required on various pins and C code for using 16x1 and 16x2 LCD's.

LCD : Liquid crystal display ( because its has a crystalline structure and still it flows ) . To learn how it works you can read in scientific book . Now lets come to the point how to interfaceconnect a intelligent LCD (by intelligent i mean it has a controller built in ) Here is a step by step guide just follow the steps ...

STEP 1 : Identify : Determine what you want LCD are available in many flavors which are specified as follows 16x1 , 16x2 , 20x2 in the format AxB where A is the number of columns ( chatters ) and B is the number of Rows ( lines ) An LCD might also be Back lit . STEP 2 : Connect : most of the LCD's follow the standard Hitachi Pin out which is simply ... Pin No Name Function USE

1 2 3

Vss Vdd Vee

Ground +ve Supply Contrast 5v Volts Regulated DC This is used to set the contrast1 Register select signal 0:Instruction register (when writing) Busy flag & address counter (When reading) 1:Data register (when writing & reading) Read/write select signal 0 for writing , 1 for reading Operation (data read/write) enable signal

RS

Register Set

R/W

Read / Write

6 7 8 9 10 11

E D0 D1 D2 D3 D4

Enable Data Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit

4 12 13 14 D5 D6 D7 Data Bit 5 Data Bit 6 Data Bit 7 +4.2 for Back light Power supply Back light ( 0V) Positive supply for back light if available

15

16

THE ABOVE FIGURE SHOWS PIN CONFIGURATION OF LCD STEP 3 : Interface : Now connect pins RS ,RW ,E ,D0 - D7 to pins on the micro controller Lets suppose I connect Data bus on port A and

the RS , RW , E on port B . (you can save pins by using LCD in Nibble Mode (4 data pins ) and permanently grounding the RW line ( always in write mode ) . Now well see how to go from simple switching it on to graphics on the LCD .An Intelligent LCD Need Only a few Commands And data to function Command Set for the LCD

Para mete r

R D D R / B B S W 7 6

D B 5

D B 4

D B 3

D B 2

D B 1

D B 0

Note

Exe cuti ng tim e osc =25 0 khz 1.6 4ms 40u s1.6 4ms

Clea r Disp lay Retu rn Hom e

0 0

0 0

* DB1=1 :Increm ent DB1=0 :Decre ment DB0=1 :The

Entr y Mod e Set

0 0

1 / D

40u s1.6 4ms

display is shifted DB0=0 :The display is not shifted 40 s DB2=1 :Displa y on DB2=0 : Display off DB1=1 :Cursor on DB1=0 : Cursor off DB0=1 :Blinki ng on DB0=0 :Blinki ng off DB3=1 :Shifts display one

Disp lay ON OFF Cont rol

0 0

40u s

Curs or or Disp lay

0 0

S C

R L

40u s

Shift

charact er DB2=1 :Right shift DB2=0 :Left shift DB4=1 :8 bits DB4=0 :4 bits DB3=1 :2 lines display (1/16 duty) DB3=0 :1 line display DB2=1 :5 10 dots , 1/11 duty DB2=1 :5 7 dots , 1/8 duty CRA Addres s

Func tion Set

0 0

D L

40u s

Set CG RA

0 0

C R A

C R A

C R A

C R A

C R A

C R A

40u s

M Addr ess

Corresp onds to the cursor address D D A D D A D D A D D A D D A D D A D D A DB7=1 :Busy (instruc tion not accepte d) DB7=0 :Ready( for instruct ion)

Set DD RA M Addr ess

0 0

40u s

Read Busy Flag & Addr ess

D B C F A

D C A

D C A

D C A

D C A

D C A

D C A

1us

Writ e Data To CG or DD RA M

1 0

W W D D

W D

W D

W D

W D

W D

W D

Write Data

40u s

Read Data from CG or DD RA M

1 1

R R D D

R D

R D

R D

R D

R D

R D

Read Data

40u s

* : Does Not Matter DDRAM : Display Data RAM CGRAM : Character Generator RAM Address : These are where the characters are meant to be displayed before sending data into the LCD the address can be specified if you want the string to be printed somewhere in the middle after that the address simply increase each time a new character is passed . A simple 16x1 might be something like this 16x1 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7

16x2 0 0 4 0 0 1 4 1 0 2 4 2 0 3 4 3 0 4 4 4 0 5 4 5 0 6 4 6 0 7 4 7 0 8 4 8 0 9 4 9 0 A 4 A 0 B 4 B 0 C 4 C 0 D 4 D 0 F 4 F 0 E 4 E

After Connecting the LCD to the Micro controller And Apply Power The LCD will just show some squares on the screen which might not even cover the whole screen . Adjust the contrast till these squares are barely visible .

For saving Pins on the micro controller i have simply put the RW line connected to the ground (and used a small delay instead of checking the line for the busy flag for the writing )
Keypad Keypads are a part of HMI or Human Machine Interface and play really important role in a small embedded system where human interaction or human input is needed. Martix keypads are well known for their simple architecture and ease of interfacing with any microcontroller. In this part of tutorial we will learn how to interface a 4x4 matrix keypad with AVR microcontroller Constructing a Matrix Keypad Constuction of a keypad is really simple. As per the outline shown in the figure below we have four rows and four columns. In between each overlapping row and column line there is a key.

There are many methods depending on how you connect your keypad with your controller, but the basic logic is same. We make the coloums as i/p and we drive the

rows making them o/p, this whole procedure of reading the keyboard is called scanning. In order to detect which key is pressed from the matrix, we make row lines low one by one and read the coloums. Lets say we first make Row1 low, then read the columns. If any of the key in row1 is pressed will make the corrosponding column as low i.e if second key is pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done. So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of the button is pressed in a row, it will take the corrosponding column to a low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then column2 and so on...

Code #include <avr/io.h> #include<compat/deprecated.h> #include<avr/delay.h>

#define rs PD7 #define en PD6 #define dataport PORTB void LCD_init(void); void wrcomm (unsigned char CMD); void wrdata (unsigned char Data); void LCD_DisplayString(const unsigned char *string);

void LCD_init(void) { wrcomm(0x38); //initialize LCD 2 lines, 5x7 matrix

wrcomm(0x01);//Cursor at line 1, position 1 wrcomm(0x06);//Clear LCD wrcomm(0x0C); //Display on Cursor Blinking wrcomm(0x80); //Shift Entire Display To Right }

void wrcomm(unsigned char Command) { cbi(PORTD,rs) ; dataport = Command; sbi(PORTD,en); _delay_ms(1); cbi(PORTD,en); _delay_ms(10); } void wrdata(unsigned char Data) { sbi(PORTD,rs) ; dataport= Data; sbi(PORTD,en); _delay_ms(1); cbi(PORTD,en);

_delay_ms(10); } void LCD_DisplayString (const unsigned char *string)

{ //LCD_Cursor (row, column); while (*string) wrdata(*string++); }

void main() { DDRA=0X00; DDRD=0XFF; DDRB = 0xff; DDRC = 0xff;//0111,1011,1101,1110 unsigned char data[4]; unsigned char value[4]={0x07,0x0B,0X0D,0X0E}; unsigned char i,x,temp,y; LCD_init(); LCD_DisplayString("WELCOME //wrcomm(0xc0); while(1) { y=PINA&0b00010000; _delay_us(500); wrcomm(0x01); wrcomm(0xc0); for(i=0;i<4;i++) { x=PINA&0b00001111; _delay_us(500);

");

while(x==0x0f) x=PINA&0b00001111; _delay_us(500); data[i]=x; x=PINA&0b00001111; _delay_us(500); while(x!=0x0f) x=PINA&0b00001111; _delay_us(500); wrdata('*'); } for(i=0;i<4;i++) { if(data[i]==value[i]) temp=1; else { temp=2; break; } } if(temp==1) { wrcomm(0x01); wrcomm(0x80); LCD_DisplayString(" SUCCESS"); _delay_ms(1000); _delay_ms(1000); while(1) {

y=PINA&0b00010000;//mines x=PINA&0b00001111;//motor _delay_us(500); if(y==0b00010000) { wrcomm(0x01); wrcomm(0x80); LCD_DisplayString("mines found...."); } else { wrcomm(0x01); wrcomm(0x80); LCD_DisplayString(" searching...."); } if(x==0b00001110) PORTC=0b00001010; else if(x==0b00001101) PORTC=0b00000101; else if(x==0b00001011) PORTC=0b00000110; else if(x==0b00000111) PORTC=0b00001001; else PORTC=255; } } }

You might also like