Showing posts with label keypad interfacing. Show all posts
Showing posts with label keypad interfacing. Show all posts

Thursday, June 16, 2011

The four dc motors used to build the structure are controlled by microcontroller Atmel 89C51.

1 AT89C51 from Atmel Corporation:

The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4K
bytes of Flash programmable and erasable read only memory (PEROM). The device
is manufactured using Atmel’s high-density nonvolatile memory technology and is
compatible with the industry-standard MCS-51 instruction set and pinout. The on-chip
Flash allows the program memory to be reprogrammed in-system or by a conven-
tional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash
on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides
a highly-flexible and cost-effective solution to many embedded control applications.
The AT89C51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Power-down Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset.


2 Pin configuration:





3 Block diagram


4 Pin Description

VCC
Supply voltage.

GND
Ground.

Port 0
Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs.
Port 0 may also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode P0 has internal pullups. Port 0 also receives the code bytes during Flash programming, and outputs the code bytes during program verification. External pullups are required during program verification.

Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2
Port 2 is an 8-bit bi-directional I/O port with internal pullups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled high by
the internal pullups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, it uses strong internal pullups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.
Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.

Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pullups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pullups.

RST
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.

XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.



XTAL2
Output from the inverting oscillator amplifier.

Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 2. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.
Idle Mode
In idle mode, the CPU puts itself to sleep while all the on-chip peripherals remain active. The mode is invoked by software. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset.
It should be noted that when idle is terminated by a hardware reset, the device normally resumes program execution, from where it left off, up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but access to the port pins is not inhibited. To eliminate the possibility of an unexpected write to a port pin when Idle is terminated by reset, the instruction following the one that invokes Idle should not be one that writes to a port pin or to external memory.



5 Design of dc drive

5.1 Block diagram:




5.2 Block diagram of dc drive

5.3 Description of components used

Uln2003

DESCRIPTION

The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. It consists of seven NPN darlington pairs that features high-voltage outputs with common cathode clamp diode for switching inductive loads. The collector-current rating of a single darlington pair is 500mA. The darlington pairs may be paralleled for higher current capability. Applications include relay drivers, hammer drivers, lamp drivers, display drivers (LED gas discharge), line drivers, and logic buffers.

FEATURES
• 500mA rated collector current(Single output)
• High-voltage outputs: 50V
• Inputs compatibale with various types of logic.
• Relay driver application


Logic Diagram

Friday, April 17, 2009

How to use a keypad ( keypad interfacing )


There are basically two methods commonly known for keypad interfacing in one
5 volts is supplied and the row and columns of the pressed key are made 0 in this way key is scanned.

But the method we used is that we made the all rows 1 (means supplied 5 (Volts) and then pressed the key and the pressed row and columns are scanned simultaneously but indirectly.


We used 4 * 3 keypad as 4 * 4 was not available in market. so we have 4 rows and 3 columns in our keypad which is actually a digital phone keypad we used a converter at the end to solder the wires with it and directly insert those in the bread board.

Row 1 to row 4 are attached to Pin 0 to pin3 of port 3 and similarly the pin 4 to pin 6 are used for columns last pin is not used of port 3.

Key scanning is quite simple the row and columns when made short through the keypad enables a single key and display it on the LCD.

LCD plus Keypad interfacing with 8051 Atmel

What is inside our code and how does this amazing code work??

Our code is quite simple we used simple commands to initialize the LCD all the data transported is in decimal. RS, RW and E pins of LCD are handled separately. We not used much function in our program as they usually make the program tricky. We tried to make the program as much simple as possible.
LCD:
We used blue LCD 16 * 2, JHD 1602 with 16 pins (actually 14 last two are for back light)
LCD interfacing is quite simple and easy to understand as each pin is handled and feeded with the data individually. This made the code quite easy.

PINs of LCD:

Data pins of LCD are connected to the port 1 of micro controller’s to the pin 1of port 2, RW pin 2 of port 2 and E to the pin 3 of port 2.
Pin 15 is directly given the 5 volts and pin 16 is grounded so that the back light can be utilized the basic function of the back light is to increase the visual ability of observer as we are using blue LCD and the text is written in grayish white which is not visible without the back light.

PIN 1, 2 & 3:
Pin 1 is grounded, pin 2 is connected to 5 volts & pin 3 of contrast is again grounded manually.

RS, RW & E PIN:
These are connected to port 2 and are feeded individually when ever and as needed. RS is 0 for command on LCD and 1 for data writing. RW is always 0 as we dont need it and E is changed from high to low pulse whenever the either command or data is sent to LCD.

EXPLAINATION:

FUNCTION SET:
1st of all function set command is feeded to the LCD data ports are feeded with 56 dec or 38 hex. That conveys that we are using 16 * 2 LCD. RS is zero. RW is zero. Enable pin is feeded with 1st high and then low signal.
P1 = 56, P2_1 = 0, P2_2 = 0,P2_3 = 1;
P2_3 = 0;

DISPLAY & Cursor ON OFF:
Secondly display on off and cursor on off (also blinking)command is sent to the LCD where data pins are feeded with 15 dec. RS is zero. RW is zero. Enable pin is feeded with 1st high and then low signal.
P1 = 15, P2_1 = 0, P2_2 = 0,P2_3 = 1;
P2_3 = 0;


CLEAR DISPLAY:
Data pins are feeded with 1. RS is zero. RW is zero. Enable pin is feeded with 1st high and then low signal to clear display.
P1 = 1, P2_1 = 0,P2_2 = 0,P2_3 = 1;
P2_3 = 0;


DISPLAY SHIFT:
To shift cursor right data pins are feeded with 28.RS is zero. RW is
zero. Enable pin is feeded with 1st high and then low signal.
P1 = 28, P2_1 = 0, P2_2 = 0, P2_3 = 1;
P2_3 = 0;


STARTING POSITION:
data pin is feeded with 81 hex or 129 decimal according to the Mazzidi`s book in assembly language. RS is zero. RW is zero. Enable pin is feeded with 1st high and then low signal.
P1 = 129, P2_1 = 0, P2_2 = 0, P2_3 = 1;
P2_3 = 0;

Now LCD`s initializing is complete....

KEYPAD INTERFACING:

Keypad interfacing involves a function call which also enables us to handle the debouncing problem delay is there but after the display of the key pressed. Proper use of delay by using for loop made it quite practical.

Whenever there is need to input data a function is called which calculate the key pressed from the keypad and display it or use the command as desired.

EXPLAINATION:

The data is saved in another variable 'g' at the same time transferred to variable 'f' and 'f' is multiplied with 10 and again if key is scanned the value of f changes by addition on new value of 'g' in 'f' i.e.- "f=f+g" again it is multiplied with 10 and procedure continues until enter or reset key is not pressed.

if(a!='*' && a!='#')
{
P1 = a, P2_1 = 1, P2_2 = 0, P2_3 = 1;
P2_3 = 0;
for(c=0;c<32000;c++);
f=f+g;
f=f*10;
}

ENTER:
Whenever enter key is pressed the value of 'f' is divided by 10 and the calculated no (which is actually the ASCII code) is sent to the LCD to display (this portion is in last of the code which can be operated by GOTO statement not else) its corresponding character. Again the value of 'f' and 'g' are made zero.
"f=0;
g=0;
"

if(a=='#')
{
f=f/10;
a=f;
P1 ='=', P2_1 = 1,P2_2 = 0,P2_3 = 1;
P2_3 = 0;
for(c=0;c<32000;c++);
f=0;
g=0;
goto label;
}
while(0)
{
label:
P1 = a, P2_1 = 1, P2_2 = 0, P2_3 = 1;
P2_3 = 0;
for(c=0;c<32000;c++);
P1 =' ', P2_1 = 1, P2_2 = 0, P2_3 = 1;
P2_3 = 0;
for(c=0;c<32000;c++);
}


RESET:
Whenever the reset key is pressed clear display command is executed and values of 'f' and 'g' are made zero.
"f=0;
g=0;
"
if(a=='*')
{
P1 = 1, P2_1 = 0,P2_2 = 0,P2_3 = 1;
P2_3 = 0;
f=0;
g=0;
for(c=0;c<32000;c++);
}


This all procedure is in wild loop. So in this way we have a numeric keyboard every character can be written on LCD with its corresponding ASCII code.