Monday, 8 October 2012

TISHITU Basic Keypad Interface by 8051 microcontroller in Proteus...





                    Akhil Jain 


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 or 2x2  matrix keypad with AVR and 8051 microcontroller. Also we will see how to program then in Assembly and C.

Keyboards and LCDs are the most widely used input/output devices of the 8051, and a basic understanding of them is essential. In this section, we first discuss keyboard fundamentals, along with key press and key detection mechanisms. Then we show how a keyboard is interfaced to an 8051.Interfacing the keyboard to the 8051 At the lowest level, keyboards are organized in a matrix of rows and columns. The CPU accesses both rows and columns through ports; therefore, with two 8-bit ports, an 8 x 8 matrix of keys can be connected to a microprocessor. When a key is pressed, a row and a column make a contact; otherwise, there is no connection between rows and columns. In IBM PC keyboards, a single microcontroller (consisting of a microprocessor, RAM and EPROM, and several ports all on a single chip) takes care of hardware and software interfacing
of the keyboard. In such systems, it is the function of programs stored in the EPROM of the microcontroller to scan the keys continuously, identify which one has been activated, and present it to the motherboard. In this section we look at the mechanism by which the 8051 scans and identifies the key. Scanning and identifying the key Figure 12-6 shows a 4 x 4 matrix connected to two ports. The rows are connected to an output port and the columns are connected to an input port. If no key has been pressed, reading the input port will yield 1 s for all columns since they are all connected to high (Vcc). If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides the path to ground. It is the function of the microcontroller to scan the keyboard continuously to detect and identify the key pressed. How it is done is explained next.

To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch, then it reads the columns. If the data read from the columns is D1 -- DO = 11, no key has been pressed and the process continues until a key press is detected. However,
if one of the column bits has a zero, this means that a key press has occurred. For example, if D1 -- DO = 01, this means that a key in the Dl column has been pressed. After a key press is detected, the microcontroller will go through the process of identifying the
key. Starting with the top row, the microcontroller grounds it by providing a low to row DO only; then it reads the columns. If the data read is all Is, no key in that row is activated and the process is moved to the next row. It grounds the next row, reads the  columns, and checks for any zero. This process continues until the row is identified.To make sure that the preceding key has been released, Os are output to all rows at once, and the columns are read and checked repeatedly until all the columns are high. When all columns are found to be high, the program waits for a short amount of time before it goes to the next stage of waiting for a key to be pressed.To see if any key is pressed, the columns are scanned over and over in an infinite loop until one of them has a 0 on it. Remember that the output latches connected to rows still have their initial zeros (provided in stage 1), making themgrounded. After the key press detection, the microcontroller waits 20 ms for
the bounce and then scans the columns again. This serves two functions: (a) it ensures that the first key press detection was not an erroneous one due to a spike noise, and (b) the 20-ms delay prevents the same key press from being interpreted as a multiple key press. If after the 20Tins delay the key is still pressed, it goes to the next stage to detect which row it belongs to; otherwise, it goes back into the loop to detect a real key press.
To detect which row the key press belongs to, the microcontroller grounds one row at a time, reading the columns each time. If it finds that all columns are high, this means that the key press cannot belong to that row; therefore, it grounds the next row and continues until it finds the row the key press belongs to. Upon finding the row that the key press belongs to, it sets up the starting address for the look-up table holding the scan codes (or the ASCII value) for that row and goes to the next stage to identify the key.


**************************************** CODE 'C' ****************************]

#include<reg52.h>
sbit col1=P1^2;
sbit col2=P1^3;
sbit row1=P1^0;
sbit row2=P1^1; //define pins for easier reading
sbit out1=P2^0;
sbit out2=P2^1;
sbit out3=P2^2;
sbit out4=P2^3;

void main ()
{
unsigned char j;
col1=col2=1;  //Input Port
while(1)  //repeat forever
{
do
  {
row1=row2=0;  //Initialising Row With 0
}while(col1==0|col2==0); //check until all keys are released

while(1)
{
   row2=1;
row1=0; //grounding row1
if (col1==0|col2==0) //column detected 
{
j=0; //save row location 
break; //exit while loop
}
  row1=1;
row2=0; //grounding row2
if (col1==0|col2==0)
{
j=1;
break;
}
}
  
out1=out2=out3=out4=1;//To Switch off previous LED,When another is pressed

//check column and send result to output pins
if(col1==0&col2==1)
{
if(j==0)
out1=0; //if 1st key is pressed 
else
out3=0;
}
if(col1==1&col2==0)
{
if(j==0)
out2=0; //if 2nd key is pressed
else
out4=0;

} //// Time for Proteus Simulator :)
}
**********************************************************************************
**************************************** Hex file ***********************************


:030000000200A853
:0C00A800787FE4F6D8FD758107020003A4
:10000300D293D292C291C2902093047E0180027E49
:10001300002092047D0180027D00ED4E70E6D291B6
:10002300C2902093047E0180027E002092047D0111
:1000330080027D00ED4E6004E4FF801CD290C291EB
:100043002093047E0180027E002092047D018002C1
:100053007D00ED4E60C87F01D2A3D2A2D2A1D2A06F
:100063003093047E0180027E002092047D01800291
:100073007D00ED5E6009EF7004C2A08002C2A22081
:1000830093047E0180027E003092047D0180027D14
:1000930000ED5E7003020007EF7005C2A1020007C6
:0500A300C2A3020007EA
:00000001FF


**********************************************************************************



Sunday, 7 October 2012

TISHITU LM 35 temperature control via RS 232 Protocol By Visual Basic











By Umang Jain 
Team TISHITU 


In 1963, IBM produced computers which were specialized for data acquisition. These include the IBM 7700 Data Acquisition System and its

successor, the IBM 1800 Data Acquisition and Control System. These expensive specialized systems were surpassed in 1974 by general

purpose S-100 computers and data acquisitions cards produced by Tecmar/Scientific Solutions Inc. In 1981 IBM introduced the IBM

Personal Computer and Scientific Solutions introduced the first PC data acquisition products.
Data acquisition is the process of sampling signals that measure real world physical conditions and converting the resulting samples

into digital numeric values that can be manipulated by a computer. Data acquisition systems (abbreviated with the acronym DAS or DAQ)

typically convert analog waveforms into digital values for processing. The components of data acquisition systems include:
Sensors that convert physical parameters to electrical signals.
Signal conditioning circuitry to convert sensor signals into a form that can be converted to digital values.

Analog-to-digital converters, which convert conditioned sensor signals to digital values.
Data acquisition applications are controlled by software programs developed using various general purpose programming languages such as

BASIC, C, Fortran, Java, Lisp, Pascal.
Specialized software tools used for building large-scale data acquisition systems include EPICS. Graphical programming environments

include ladder logic, Visual C++, Visual Basic, and LabVIEW.
ISIS Schematic Capture - a tool for entering designs.
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5 simulator combined with a digital simulator.
ARES PCB Layout - PCB design system with automatic component placer, rip-up and retry auto-router and interactive design rule checking.
VSM - Virtual System Modelling lets cosimulate embedded software for popular micro-controllers alongside hardware design.
Data acquisition begins with the physical phenomenon or physical property to be measured. Examples of this include temperature, light

intensity, gas pressure, fluid flow, and force. Regardless of the type of physical property to be measured, the physical state that is

to be measured must first be transformed into a unified form that can be sampled by a data acquisition system. The task of performing

such transformations falls on devices called sensors.
A sensor, which is a type of transducer, is a device that converts a physical property into a corresponding electrical signal (e.g., a

acquisition system to measure differing properties depends on having sensors that are suited to detect the various properties to be

measured. Signal conditioning may be necessary if the signal from the transducer is not suitable for the DAQ hardware being used. The

signal may need to be filtered or amplified in most cases. Various other examples of signal conditioning might be bridge completion,

providing current or voltage excitation to the sensor, isolation, linearization. For transmission purposes, single ended analog

signals, which are more susceptible to noise can be converted to differential signals. Once digitized, the signal can be encoded to

reduce and correct transmission errors.
DAQ (Data acquisition )hardware is what usually interfaces between the signal and a PC[1]. It could be in the form of modules that can

be connected to the computer's ports (parallel, serial, USB, etc.) or cards connected to slots (S-100 bus, AppleBus, ISA, MCA, PCI,

PCI-E, etc.) in the motherboard. Usually the space on the back of a PCI card is too small for all the connections needed, so an

external breakout box is required. The cable between this box and the PC can be expensive due to the many wires, and the required

shielding.
DAQ cards often contain multiple components (multiplexer, ADC, DAC, TTL-IO, high speed timers, RAM). These are accessible via a bus by

a microcontroller, which can run small programs. A controller is more flexible than a hard wired logic, yet cheaper than a CPU so that

it is permissible to block it with simple polling loops. For example: Waiting for a trigger, starting the ADC, looking up the time,

waiting for the ADC to finish, move value to RAM, switch multiplexer, get TTL input, let DAC proceed with voltage ramp.

##############################################################################
CODE 'C"
###########################################################################
#include<reg52.h>
#define ldata P2
#define temp P1
sbit r= P3^3;  // Write pin. It is used to start the conversion. 
sbit d= P3^4;  // Read pin. It is used to extract the data from internal register to the output pins 
void senddata (unsigned char value);
void delay(unsigned int msec )  // The delay function provides delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0; j<1275; j++);
}

void main()
{  
signed int a,b,c; 
TMOD=0X20;
SCON=0X50;
TH1=0XFD;
TR1=1;    
while(1)
{

d=1;     
r=0;     
delay(1);
r=1;
delay(1);
d=0;
delay (1);
senddata(0x23);
delay (1);
c=temp/100;
senddata(c);
delay (1);
a=(temp/10)-(c*10);
senddata(a);
delay (1);
b=temp%10;
senddata(b);
delay (1);
}
}
void senddata (unsigned char value)
{
value=value+0x30;
SBUF=value;
TI=0;
while(TI==0);
}
###############################################################################

some screen Shots

###############################################################################
##############################################################################
Visual Studio Code
######################################################################
Dim a As Integer
Dim temp As Integer

Private Sub Command2_Click()
MSComm1.PortOpen = False
Command2.Visible = False
Command1.Visible = True
End Sub

Private Sub Form_Load()
a = 10
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = False
End Sub
Private Sub Command1_Click()
MSComm1.CommPort = Text2.Text
MSComm1.PortOpen = True
Command1.Visible = False
Command2.Visible = True

End Sub



Private Sub MSComm1_OnComm()
Dim Data As String
If MSComm1.CommEvent = comEvReceive Then
Data = MSComm1.Input
End If
If Data = Chr$(83) Then
a = 0
End If
Select Case a
Case "1"
 num1.Text = Data
Case "2"
 num2.Text = Data
Case "3"
 num3.Text = Data
 'thermo.Value = num1.Text + num2.Text + num3.Text         ########## You Can Collect all files and data from our Blogs and Sites www.tishitu.org Happy Programming
 pb.Value = num1.Text + num2.Text + num3.Text
End Select
 a = a + 1
'If a = 4 Then
'a = 1
'End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
#################################################################################

 Screen Shots
##############################################################################