Sunday, 7 December 2014

what is RAM, ROM, and EEPROM

 Read Only Memory (ROM)
Read Only Memory (ROM) is a type of memory used to permanently save the program being executed. The size of the program that can be written depends on the size of this memory. ROM can be built in the microcontroller or added as an external chip, which depends on the type of the microcontroller. Both options have some disadvantages. If ROM is added as an external chip, the microcontroller is cheaper and the program can be considerably longer. At the same time, a number of available pins is reduced as the microcontroller uses its own input/output ports for connection to the chip. The internal ROM is usually smaller and more expensive, but leaves more pins available for connecting to peripheral environment. The size of ROM ranges from 512B to 64KB.
 Random Access Memory (RAM)
Random Access Memory (RAM) is a type of memory used for temporary storing data and intermediate results created and used during the operation of the microcontrollers. The content of this memory is cleared once the power supply is off. For example, if the program performs an addition, it is necessary to have a register standing for what in everyday life is called the “sum” . For that purpose, one of the registers in RAM is called the "sum" and used for storing results of addition. The size of RAM goes up to a few KBs.
 Electrically Erasable Programmable ROM (EEPROM)
The EEPROM is a special type of memory not contained in all microcontrollers. Its contents may be changed during program execution (similar to RAM ), but remains permanently saved even after the loss of power (similar to ROM). It is often used to store values, created and used during operation (such as calibration values, codes, values to count up to etc.), which must be saved after turning the power supply off. A disadvantage of this memory is that the process of programming is relatively slow. It is measured in milliseconds.

Saturday, 6 December 2014

C code for interfacing LCD with 8051 and keil

Code for interfacing LCD with 8051 and keil
In this tutorial I will discuss about how to interface LCD with 8051 using C language. I am going to write a simple code to display ‘T’, ‘R’, ‘A’, ‘C’, ‘E’ to the LCD.
I am taking AT89s52 and connect all data pins of LCD with Port one (P1) and connect RS pin to pin 0 of port 2, RW pin to pin 1 of port 2, Enable (E) pin to pin 2 of port 2.
Here is the code……………
////////////////////////////////////////////////////////////////////////////////////////////////////

#include <reg51.h>
sfr ldata = 0x90;                                                // P1=LCD data pins
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
void main()
{
Lcdcmd(0x38);
Ms_delay(250);
Lcdcmd(0x0E);
Ms_delay(250);
Lcdcmd(0x01);
Ms_delay(250);
Lcdcmd(0x06);
Ms_delay(250);
Lcdcmd(0x86);                   // Line 1, position 6
Ms_delay(250);
Lcddata(‘T’);
Ms_delay(250);
Lcddata(‘R’);
Ms_delay(250);
Lcddata(‘A’);
Ms_delay(250);
Lcddata(‘C’);
Ms_delay(250);
Lcddata(‘E’);
Ms_delay(250);
}
Void Lcdcmd(unsigned char value)
{
Ldata = value;
rs = 0;
rw = 0;
en = 1;
Ms_delay(1);
en = 0;
return;
}
Void Lcddata (unsigned char value)
{
Ldata = value;
rs = 1;
rw = 0;
en = 1;
Ms_delay(1);
en = 0;
return;
}
Void Ms_delay(unsigned int time)
{
Unsigned int i,j;
For (i=0;i<time;i++)
For(j=0;j<1275;j++);
}






Friday, 5 December 2014

Theory for interfacing LCD

LCD interfacing theory
In this tutorial I will show you the operation modes of LCD then describe how to program and interface an LCD with 8051 using C language.
Operation of LCD
Now a day’s LCD is finding widespread use replacing LEDs (7 segment LEDs or other multi 7 segment LEDs). For the following reasons………
1.      The declining or lower price of LCDs.
2.      Wide range of use (ability to display numbers, characters, and graphics). This is in contrast to LEDs, which are limited to numbers and a few characters.
3.      Incorporation of refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU (or in some other way) to keep displaying the data.
4.      Ease of programming for characters and graphics.
LCD pin description

Pin
Symbol
I/O
Description
1
Vss
-
GND
2
Vcc
-
+5V power supply
3
Vee
-
Power supply to control contrast
4
RS
I
RS=0 to select command register
RS=1 to select data register
5
R/W
I
R/W=0 for write, R/W=1 for read
6
E
I/O
Enable
7
DB0
I/O
The 8-bit data bus
8
DB1
I/O
The 8-bit data bus
9
DB2
I/O
The 8-bit data bus
10
DB3
I/O
The 8-bit data bus
11
DB4
I/O
The 8-bit data bus
12
DB5
I/O
The 8-bit data bus
13
DB6
I/O
The 8-bit data bus
14
DB7
I/O
The 8-bit data bus


RS register select
There are two important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc. If RS=1 the data register is selected, allowing the user to send data to be displayed on the LCD.
RW, read write
R/W input allows the user to write information to the LCD or read information from it. R/W = 1 when reading; R/W = 0 when writing.
E enable
The enable pin is used by the LCD latch information presented to its data pins. When data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide.
LCD Command Codes
HEX Code

1
Clear display screen
2
Return Home
4
Shift cursor to left
5
Shift display right
6
Shift cursor to right
7
Shift display left
8
Display off, cursor off
A
Display off, cursor on
C
Display on, cursor off
E
Display on, cursor blinking
F
Display off, cursor off
10
Shift cursor position to left
14
Shift cursor position to right
18
Shift the entire display to the left
1C
Shift the entire display to the right
80
Cursor to beginning of 1st line
C0
Cursor to beginning of 2nd line
38
2 lines and 5x7 matrix






Thursday, 4 December 2014

C code for interfacing 7 segment display

Code for interfacing 7-Segment in 8051 and keil
In this lesson I will discuss about how to code to interface 7-segment in 8051 in c language.
Here I have used common anode 7-segment display.
The code is…………
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Seven segment display//
#include <REGX51.H>
#define seg P1
code char digit[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x90} ;

void delay_ms(int milisec)
{
   int i,j,k;
        for(j=0;j<milisec;j++)
        {
      for(k=0;k<20;k++)   
        {               
                  for(i=0;i<4898;i++);
                 }
        }
}
void main(void)
{
        int i;
        P1=0x00;
        while(1)
        {
                for(i=0;i<10;i++);
                {
                        P1=digit[i];
                        delay_ms(1000);
                }
        }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
By this code 7 segment will display 0 1 2 3 4 5 6 7 8 9 0 1…..for a continuas manner.

 Connect all pin of 7 segment to port one (P1).

Wednesday, 3 December 2014

Interfacing 7-Segment

Interfacing 7-Segment with 8051 using keil
7-Segment is the best display to message something spatially numbers by using low electrical power.
If we need to display some numerical data in a message board then we can choose 7-segment display because the 7-segment is a one type of LED display, it consume minimum electrical power to display. On the other hand LCD or other messaging display takes a huge amount of power to display something.
There are two types of 7-segment displays in our hand.
Common Anode 7-segment display.
              And
Common Cathode 7-segment display.

How to use Common-Cathode 7-segment display
   

Pin description for common cathode 7-segment display
Pin No.                         Used for
1                                                                    e
2                                                                    d
3                                                                    GND
4                                                                    C
5                                                                    Dp
6                                                                    b
7                                                                    a
8                                                                    GND
9                                                                    f
10                                                                g                                                                                                                     

In common anode display if we want to display a LED we have to make output low (0) to that LED pin.
Suppose if we want to display ‘1’ in the common cathode display, then we have to make b and c to output high (1) and remaining pin to output low (0).
Like that..
For common cathode display

Dp       g          f           e          d          c          b          a          Hex code         Display
0          0          1          1          1          1          1          1          0x3F                 0
0          0          0          0          0          1          1          0          0x06                1
0          1          0          1          1          0          1          1          0x5B                2
0          1          0          0          1          1          1          1          0x4F                 3
0          1          1          0          0          1          1          0          0x66                4
0          1          1          0          1          1          0          1          0x6D                5
0          1          1          1          1          1          0          1          0x7D                6
0          0          0          0          0          1          1          1          0x07                7
0          1          1          1          1          1          1          1          0x7F                 8
0          1          1          0          1          1          1          1          0x6f                 9














 


Tuesday, 2 December 2014

Interfacing 7-segment display for 8051 and keil

Interfacing 7-Segment with 8051 using keil
7-Segment is the best display to message something spatially numbers by using low electrical power.
If we need to display some numerical data in a message board then we can choose 7-segment display because the 7-segment is a one type of LED display, it consume minimum electrical power to display. On the other hand LCD or other messaging display takes a huge amount of power to display something.
There are two types of 7-segment displays in our hand.
Common Anode 7-segment display.
              And
Common Cathode 7-segment display.

How to use Common Anode 7-segment display
   

Pin description for common anode 7-segment display
Pin No.                         Used for
1                                                                    e
2                                                                    d
3                                                                    5v
4                                                                    C
5                                                                    Dp
6                                                                    b
7                                                                    a
8                                                                     5v
9                                                                    f
10                                                                g                                                                                                                     

In common anode display if we want to display a LED we have to make output low (0) to that LED pin.
Suppose if we want to display ‘1’ in the common anode display, then we have to make b and c to output low(0) and remaining pin to output high(1).
Like that..
For common anode display

Dp        g         f           e          d          c          b          a          Hex code         Display
1          1          0          0          0          0          0          0          C0                    0
1          1          1          1          1          0          0          1          F9                    1
1          0          1          0          0          1          0          0          A4                    2
1          0          1          1          0          0          0          0          B0                    3
1          0          0          1          1          0          0          1          99                    4
1          0          0          1          0          0          1          0          92                    5
1          0          0          0          0          0          1          0          82                    6
1          1          1          1          1          0          0          0          F8                    7
1          0          0          0          0          0          0          0          80                    8
1          0          0          1          0          0          0          0          90                    9