Thursday, 8 October 2015

EMBEDDED SYSTEM DEVELOPMENT

What is Embedded Systems?

Embedded system is defined as a way of working, performing or organizing one or many tasks according to a fixed set of rules (or) an arrangement in which all the units assemble and work together according to the program or plan


Embedded System


Embedded Systems Basics

Embedded System Block Diagram


Embedding a Micro controller:

The different streams of Micro controllers used in embedded systems are usually among the five streams of families  given in the table.
Embedding a Microcontroller

Embedded Systems Applications:

Embedded systems have different applications. A few select applications of embedded systems are smart cards, telecommunications, satellites, missiles, digital consumer electronics, computer networking, etc.
  • Motor Control System
  • Cruise Control System
  • Engine or Body Safety
  • Robotics in Assembly Line
  • Car Entertainment
  • Car multimedia
  • Mobile and E-Com Access
Embedded systems in Telecommunications
Embedded Systems in Smart Cards
Embedded Systems in Missiles and Satellites
  • Defense
  • Aerospace
  • Communication
Embedded Systems in Computer Networking & Peripherals
  • Networking Systems
  • Image Processing
  • Printers
  • Networks Cards
  • Monitors and Displays
Embedded Systems in Digital Consumer Electronics
  • DVDs
  • Set top Boxes
  • High Definition TVs
  • Digital Cameras
*8051 Micro Controller

  Pin Diagram:




Pin out Description:

Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the micro controller and clears the contents of most registers. In other words, the positive voltage on this pin resets the micro controller. By applying logic zero to this pin, the program starts execution from the beginning.
Pins 10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides, all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication clock output.
Pin 12: INT0 Interrupt 0 input.
Pin 13: INT1 Interrupt 1 input.
Pin 14: T0 Counter 0 clock input.
Pin 15: T1 Counter 1 clock input.
Pin 16: WR Write to external (additional) RAM.
Pin 17: RD Read from external RAM.
Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be used for frequency stability. Later versions of micro controllers operate at a frequency of 0 Hz up to over 50 Hz.
Pin 20: GND Ground.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every time the micro controller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the micro controller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register  memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. It means that even there is a program written to the micro controller, it will not be executed. Instead, the program written to external ROM will be executed. By applying logic one to the EA pin, the micro controller will use both memories, first internal then external (if exists).
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: VCC +5V power supply

More details about 8051
http://www.mikroe.com/chapters/view/65/chapter-2-8051-microcontroller-architecture/

Programming For 8051 using C

Using Keil uVision 4

1. Download and Install Keil uVision4
2. Open Keil uVision
untitled
3. Create a new Project : Project >> Create µVision Project
untitled
4. Browse for the location
5. Select the microcontroller Atmel>>AT89C51
6. Don’t Add The 8051 startup code
7. File>>New
8. Enter the  source code.
9. Save it
10.Add the source code.. Double click on source group1>>Select the file and Add and close it..
11. Then Compile it. Click Project>>Build Target or F7
12. Creat the Hex file to the output
13.Right click on Target1>>options for target “target 1”
     In the Output Tab check the “Create HEX file” box<
untitled
untitled

Saturday, 26 September 2015

HOW 16x2 ALPHANUMERIC LCD WORKS

HOW 16x2 ALPHANUMERIC LCD WORKS ?


          LCD (Liquid Crystal Display) is used in all the electronics projects to display the status of the process. A 16x2 alphanumeric LCD is most widely used module of LCD nowadays. There are several others type of  LCD available in market also.
The reason for choosing LCD over other display component or devices is that it is
  • Low cost
  • Easily programmable
  • Large number of display character etc.


Introduction  :
          16x2 LCD has 2 horizontal line which comprising a space of 16 displaying character. It has two type of register inbuilt that is

  • Command Register
  • Data Register.


    Command register is used to insert a special command into the LCD. While Data register is used to insert a data into the LCD. Command is a special set of  data which is used to give the internal command to LCD like Clear screen, move to line 1 character 1, setting up the cursor etc.


Pin Diagram of 16x2 LCD :


Sr. No
Pin No.
Pin Description
1
Pin 1 (GND)
This is a ground pin to apply a ground to LCD.
2
Pin 2 (VCC)
This is the supply voltage pin to apply voltage to LCD.
3
Pin 3 (VEE)
This is the pin for adjusting a contrast of  the LCD display by attaching a veriable resistor in between VCC and GND.
4
Pin 4 (RS)
RS stands for Register Select. This pin is used to select command/data register.
If RS=0 then command register is selected.
If RS=1 then data register is selected.
5
Pin 5 (R/W)
R/W stands for Read/Write. This pin is used to select the operation Read/Write.
If R/W=0 then Write operation is performed.
If R/W=1 then Read operation is performed.
6
Pin 6 (EN)
En stand for Enable signal. A positive going pulse on this pin will perform a read/write function to the LCD.
7
Pin 7-14 (DB0-DB7)
This 8 pin is used as a Data pin of  LCD.
8
Pin 15 (LED+)
This pin is used with pin 16(LED-) to setting up the illumination of back light of LCD. This pin is connected with VCC.
9
Pin 16 (LEC-)
This pin is used with pin 15(LED+) to setting up the illumination of back light of LCD. This pin is connected with GND.





Important commands codes for LCD :

Sr.No.
Hex Code
Command to LCD instruction Register
1
01
Clear display screen
2
02
Return home
3
04
Decrement cursor (shift cursor to left)
4
06
Increment cursor (shift cursor to right)
5
05
Shift display right
6
07
Shift display left
7
08
Display off, cursor off
8
0A
Display off, cursor on
9
0C
Display on, cursor off
10
0E
Display on, cursor blinking
11
0F
Display on, cursor blinking
12
10
Shift cursor position to left
13
14
Shift cursor position to right
14
18
Shift the entire display to the left
15
1C
Shift the entire display to the right
16
80
Force cursor to beginning to 1st line
17
C0
Force cursor to beginning to 2nd line
18
38
2 lines and 5x7 matrix

Friday, 25 September 2015

8051 Interfacing:LCD 16x2

Introduction:LCD

Liquid Crystal Display(LCDs) provide a cost effective way to put a text output unit for a microcontroller. As we have seen in the previous tutorial, LEDs or 7 Segments do no have the flexibility to display informative messages. This display has 2 lines and can display 16 characters on each line. Nonetheless, when it is interfaced with the micrcontroller, we can scroll the messages with software to display information which is more than 16 characters in length.

LCD Internal Controller


Fig 1: LCD Block diagram

The LCD is a simple device to use but the internal details are complex. Most of the 16x2 LCDs use a Hitachi HD44780 or a compatible controller. Yes, a micrcontroller is present inside a Liquid crystal display as shown in figure 1.
LCD Char 5x7 Matrix.jpg
The Display Controller takes commands and data from a external microcontroller and drivers the LCD panel(LCDP). It takes a ASCII value as input and generate a patter for the dot matrix. E.g., to display letter 'A', it takes its value 0X42(hex) or 66(dec) decodes it into a dot matrix of 5x7 as shown in figure 2.

Basic Commands

The LCD controller uses RS and RW lines along with E to operate the LCD.
  • Resister Select (RS): Determines weather a command(RS = 0) is sent (to set up the display) or actual data(RS=1) is sent.
  • Read/Write RW=0; writes to the LCD. RW=1;Reads from the LCD.
The commonly used instructions are shown in the instruction set below. Observe the Bit names: I/D, S, D, C etc at the bottom of instruction set to decode the instructions completely.
  • Clear Display
  • Cursor Home
  • Set Entry Mode
  • Display on/off control
  • Cursor/display shift
  • Function Set
  • Read Busy Flag
  • Data Read
  • Data Write

Instruction Set

HD44780U based instruction set
InstructionCodeDescription
RSR/WB7B6B5B4B3B2B1B0
Clear display0000000001Clears display and returns cursor to the home position (address 0).
Cursor home000000001*Returns cursor to home position. Also returns display being shifted to the original position. DDRAM content remains unchanged.

Entry mode set00000001I/DSSets cursor move direction (I/D); specifies to shift the display (S). These operations are performed during data read/write.

Display on/off control0000001DCBSets on/off of all display (D), cursor on/off (C), and blink of cursor position character (B).

Cursor/display shift000001S/CR/L**Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM content remains unchanged.

Function set00001DLNF**Sets interface data length (DL), number of display line (N), and character font (F).
Read busy flag &
address counter
01BFCGRAM/DDRAM addressReads busy flag (BF) indicating internal operation being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction).
Write CGRAM or
DDRAM
10Write DataWrite data to CGRAM or DDRAM.
Write CGRAM or
DDRAM
10Write DataWrite data to CGRAM or DDRAM.
Instruction bit names —
I/D - 0 = decrement cursor position, 1 = increment cursor position;
S - 0 = no display shift, 1 = display shift;
D - 0 = display off, 1 = display on;
C - 0 = cursor off, 1 = cursor on;
B - 0 = cursor blink off, 1 = cursor blink on ;
S/C - 0 = move cursor, 1 = shift display;
R/L - 0 = shift left, 1 = shift right;
DL - 0 = 4-bit interface, 1 = 8-bit interface;
N - 0 = 1/8 or 1/11 duty (1 line), 1 = 1/16 duty (2 lines);
F - 0 = 5×8 dots, 1 = 5×10 dots;
BF - 0 = can accept instruction, 1 = internal operation in progress.

LCD UNIT

Let us look at a pin diagram of a commercially available LCD like JHD162 which uses a HD44780 controller and then describe its operation.
PIN Diagram.PNG
All the pins are identically to the lcd internal controller discussed above
PIN NUMBERFUNCTION
1Ground
2VCC
3Contrast adjustment (VO)
4Register Select (RS). RS=0: Command, RS=1: Data
5Read/Write (R/W). R/W=0: Write, R/W=1: Read
6Clock (Enable). Falling edge triggered
7Bit 0 (Not used in 4-bit operation)
8Bit 1 (Not used in 4-bit operation)
9Bit 2 (Not used in 4-bit operation)
10Bit 3 (Not used in 4-bit operation)
11Bit 4
12Bit 5
13Bit 6
14Bit 7
15Back-light Anode(+)
16Back-Light Cathode(-)



Interfacing LCD with 8051

LCD can be interfaced with the 8051 micrcontroller in two modes, 8 bit and 4 bit. Let us Interface it in 8 bit mode first.

8 bit Mode


Objective


fig LCD display
There is lot of stuff that can be done with the LCDs, to start with we will simple display a couple of strings on the 2 lines of the LCD as shown in the image.

Schematic Discription

  • Data Lines: In this mode, all of the 8 datalines DB0 to DB7 are connected from the micrcontroller to a LCD module as shown the schematic.
  • Control Lines:' The RS, RW and E are control lines, as discussed earlier.
  • Power & contrast:Apart from that the LCD should be powered with 5V between PIN 2(VCC) and PIN 1(gnd)PIN 3 is the contrast pin and is output of center terminal of potentiometer(voltage divider) which varies voltage between 0 to 5v to vary the contrast.
  • Back-light: The PIN 15 and 16 are used as backlight. The led backlight can be powered through a simple current limiting resistor as we do with normal leds.

Schematic

Fig 3: Schematic LCD 8 bit mode


Code

As with all the interfaces to simplify thing we have separated code into two files, main.c and lcd_8_bit.c. You may go through the tools setup tutorial on configuring the code.
The main.c is very simple it includes the standard library files. Then it uses several functions from the lcd_8_bit.c file to set up and display messages. As you can see, it makes things very simple when the libraries are well written. We will discuss the implementation while discussing the lcd_8_bit.c file.

The main file main.c

/* Reg51.h contains the defnition of all ports and SFRs */
#include <reg51.h> 
 
#include "lcd.h" //Xplore labz LCD library 
#include "delay.h" //Xplore Labz Delay library
 
/* start the main program */
void main() 
{
 
  /* Initilize the lcd before displaying any thing on the lcd */
    LCD_Init();
 
  /* Display "hello, world" on first line*/
  LCD_DisplayString("hello, world");
 
  /*Go to second line and display "good morning" */
  LCD_GoToLineTwo();
  LCD_DisplayString("good morning");
 
    while(1);
}

lcd_8_bit.c: 8 bit lcd library file

The lcd_8_bit.c consists of various functions that are required to initialize and use the LCD. Let us look at few important lines and functions. Specifying the Connections: The connections described in the schematic are specified with following lines of code.
#define databus P2   // LCD databus connected to PORT2
sbit rs= P0^0;   // Register select pin connected to P0.0
sbit rw= P0^1;   // Read Write pin connected to P0.1
sbit en= P0^2;   // Enable pin connected to P0.2
Let us look at three important functons in lcd_8_bit.c
1. void LCD_CmdWrite( char cmd)
Commands are required to sent to lcd in order to set it up or initialize. The timing diagrams for command write are shown in the figure, figure: command write
  • step1: Send the I/P command to LCD.
  • step2: Select the Control Register by making RS low.
  • step3: Select Write operation making RW low.
  • step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
void LCD_CmdWrite( char cmd)
{
   databus=cmd;     // Send the command to LCD
     rs=0;          // Select the Command Register by pulling RS LOW
     rw=0;          // Select the Write Operation  by pulling RW LOW
     en=1;          // Send a High-to-Low Pusle at Enable Pin
     delay_us(10);
     en=0;
   delay_ms(1);
}
2. void LCD_DataWrite( char dat) This function sends a character to be displayed on LCD in the following steps.
  • step1: Send the character to LCD.
  • step2: Select the Data Register by making RS high.
  • step3: Select Write operation making RW low.
  • step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
The timings are similar as above only change is that RS is made high.
void LCD_DataWrite( char dat)
{
   databus=dat;    // Send the data to LCD
     rs=1;    // Select the Data Register by pulling RS HIGH
     rw=0;         // Select the Write Operation by pulling RW LOW
     en=1;    // Send a High-to-Low Pusle at Enable Pin
     delay_us(10);
     en=0;
   delay_ms(1);
}
3. void LCD_Init()
Looking at the instruction set of the LCD controller, we can initialize the LCD with following steps
  • Set the display mode as 2 lines, 5 x 7 matrix
  • Turn On the dislay, and cursor.
  • Clear the LCD
  • Get the cursor to first line first position.
The code is listed below.
void LCD_Init()
{
   delay_us(5000);
   LCD_CmdWrite(0x38);   // LCD 2lines, 5*7 matrix
   LCD_CmdWrite(0x0E); // Display ON cursor ON  Blinking off
   LCD_CmdWrite(0x01); // Clear the LCD
   LCD_CmdWrite(0x80); // Cursor to First line First Position
}




#include<reg51.h>
#include "delay.h"
#include "lcd.h"
 
#define databus P2   // LCD databus connected to PORT2
 
sbit rs= P0^0;   // Register select pin connected to P0.0
sbit rw= P0^1;   // Read Write pin connected to P0.1
sbit en= P0^2;   // Enable pin connected to P0.2
 
 
/* 16x2 LCD Specification */
#define LCDMaxLines 2
#define LCDMaxChars 16
#define LineOne 0x80
#define LineTwo 0xc0
 
#define BlankSpace ' '
 
 
void LCD_Init()
{
    delay_us(5000);
   LCD_CmdWrite(0x38);   // LCD 2lines, 5*7 matrix
   LCD_CmdWrite(0x0E); // Display ON cursor ON  Blinking off
   LCD_CmdWrite(0x01); // Clear the LCD
   LCD_CmdWrite(0x80); // Cursor to First line First Position
}
 
 
void LCD_CmdWrite( char cmd)
{
     databus=cmd;        // Send the command to LCD
     rs=0;             // Select Command Register by pulling RS LOW
     rw=0;             // Select Write Operation  by pulling RW LOW
     en=1;             // Send a High-to-Low Pusle at Enable Pin
     delay_us(10);
     en=0;
     delay_ms(1);
}
 
 
void LCD_DataWrite( char dat)
{
 
   databus=dat;    // Send the data to LCD
     rs=1;     // Select the Data Register by pulling RS HIGH
     rw=0;   // Select the Write Operation  by pulling RW LOW
     en=1; // Send a High-to-Low Pusle at Enable Pin
     delay_us(10);
     en=0;


Frequently used commands in lcd


No.InstructionHexDecimal
1Function Set: 8-bit, 1 Line, 5x7 Dots0x3048
2Function Set: 8-bit, 2 Line, 5x7 Dots0x3856
3Function Set: 4-bit, 1 Line, 5x7 Dots0x2032
4Function Set: 4-bit, 2 Line, 5x7 Dots0x2840
5Entry Mode0x066
6Display off Cursor off (clearing display without clearing DDRAM content)0x088
7Display on Cursor on0x0E14
8Display on Cursor off0x0C12
9Display on Cursor blinking0x0F15
10Shift entire display left0x1824
11Shift entire display right0x1C30
12Move cursor left by one character0x1016
13Move cursor right by one character0x1420
14Clear Display (also clear DDRAM content)0x011
15Set DDRAM address or coursor position on display0x80 + address*128 + address*
16Set CGRAM address or set pointer to CGRAM location0x40 + address**64 + address**
Table 4: Frequently used commands and instructions for LCD
* DDRAM address given in LCD basics section see Figure 2,3,4 ** CGRAM address from 0x00 to 0x3F, 0x00 to 0x07 for char1 and so on.. The table above will help you while writing programs for LCD. But after you are done testing with the table 4, i recommend you to use table 3 to get more grip on working with LCD and trying your own commands. In the next section of the tutorial we will see the initialization with some of the coding examples in C as well as assembly.