LPC 21xx Microcotroller Programming Starting

When getting started in embedded programming, GPIO (viz. General Purpose Input Output) pins are one of the first things played with. Its also quite evident that the most popular embedded systems Program is Blinking LED i.e a LED connected to pin on the Microcontroller that keeps blinking. The use of GPIO is not limited to driving LEDS but can be also used for reading digital signal , generating triggers for external components , controlling external devices and what not. In this tutorial we see how to use and program GPIO Pins for lpc214x ARM 7 microcontrollers from NXP/Philips.

In this tutorial we also learn to make a project in keil MDK with a blinking LED.

First of all make download Keil MDK from keil official Site ,install it and open it .

Go to the project menu and and make new project from their choose micro-controller from NXP family to LPC214x. and add Startup file to project. create new file name as extension of type .c. add file to the source project.

include hedder file as #include “lpc21xx.h” to the code.

First we start with GPIO (General purpose INPUT and OUTPUT) Pins. the LPC21xx controllers have two ports with 32 pins each as it is mirco-controller with 32 bit resistor.

there are four resister PIN , DIR , SET, CLR for each pin of 2 ports.

DIR - this resistor is used to set direction of pins.

Example of using this resistor is IO0DIR |= (1<<6); it will set pin 6 of port 0 as output.

void Direction_Set(unsigned int Port_No,unsigned int Pin_No,char Direction)
{
switch(Port_No)
{
case 0:
if(Direction)
{
IO0DIR |= (1<<Pin_No);
}
else
{
IO0DIR &= ~(1<<Pin_No);
}
break;
case 1:
if(Direction)
{
IO1DIR |= (1<<Pin_No);
}
else
{
IO1DIR &= ~(1<<Pin_No);
}
break;
}
}

SET  - this resistor is used to set pin/port of microcontroller. example of this resistor is IO1SET |= (1<<10); this will set Pin 10 of port 1.

void Set_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
IO1SET |= (1<<Pin_No);
}
else
{
IO0SET |= (1<<Pin_No);
}
}

Here is the function provided for Set pins of microcontroller.

 

CLR -  This resistor is used to clear Port/Pin of micro-controller. example of this resistor is as IO1CLR |= (1<<10);  .

void Clear_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
IO1CLR |= (1<<Pin_No);
}
else
{
IO0CLR |= (1<<Pin_No);
}
}

PIN - this resistor is used to take input from pins/port.
int Read_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
return (IO1PIN&(1<<Pin_No));
}
else
{
return (IO0PIN&(1<<Pin_No));
}
}

——————————————————————————————————————–

int Read_Port(unsigned int Port_No)
{
if(Port_No)
{
return (IO1PIN);
}
else
{
return (IO0PIN);
}
}

 

Memory Model of Arm Microcontroller

Hello guys today i am come up with an interesting and impotent topic for embedded system programming on micro-controller. As the Micro- controllers has small and limited memory described as

FLASH - A non-volatile memory that primarily stores the program’s instructions, and also any “constant” data values. In general, you only read from this memory, and it is only written when you download new code to the micro-controller.

RAM - It is a volatile memory that is the working data space for storing all variables whilst the program is running. In C, this is static variables, the heap, and the stack.

RAM is therefore much more scarce and valuable than FLASH, so it is worth understanding a little about the memory model to help make best use of the memory.

EEPROM - Some microcontrollers have special non-volatile memory that can be erased and written byte for byte rather than in blocks or sectors. This memory is typically used by the application to store special data or configuration. This memory requires special access by a peripheral and is not directly addressable.

C Memory Model

Heap Memory - This is used for dynamic memory allocation. When we create a new instance of an object using ‘new’, or if you allocate a block of memory using malloc and friends, you use memory in the heap.

Static/Global memory - Global and static memory are values that are allocated for the entire lifetime of the program.

If for some reason you have data that is fixed (such as a lookup table), you’d be much better off making sure the compiler can allocate it in FLASH to save valuable RAM space. In the previous example, we could use the C keyword “const” to tell the compiler the variable will never be changed.

Stack - The Stack is used to store types of variables that have a fixed lifetime based on how C programs run. It is a section of RAM that grows and shrinks as the program runs. When you call a function, its parameters and any variables you have defined in that function (which are not static) are stored on the stack.

 

Audio Amplifier

Now a days We all Are using Amplifier as part of TV , Home Theater and many more so i thought why we will not made an amplifier By Himself. this circuit can be used with a small 9 volt Battery Operated,Current use as little as 5 milliamps.And amplification up to 500 mW.

This circuit number LM386 IC is used as the IC, which is popular is that it has. It is a simple circuit. Less equipment items. Suitable for use or used in small trials.
The properties of the IC can be used from 4V-12V power supply for low current at 50 mA only. And the frequency response from 40Hz – 100 kHz rate of expansion of 46 dB and distortion. Less than 1%.

Requirements:

  • LM386
  • an Speaker
  • 10 UF ,220 UF and 0.1UF capasitor
  • 10 K ohm Resitance
  • Battery ( 9 volt)

Here The Circuit Diagram Is Provided

amplifier-audio-small-to-use-with-9V-battery-operated

Line Follower Robot Without Microcontroller

Line follower Robot is the  first Automatic Robot made by every engineer working on Robotics. as these days every robot functions with the help of Microcontroller and hence the circuit too complex to understand for start-up. due to this reason. i am presenting Line follower Robot with simple concept without Microcontroller. this robot is mobile automation robot which follow white/black line on black/white surface. using this concept you can make automatic loading goods system,

Here two sensor pairs LED-LDR are used. According to physics, if light falls on a white surface, it gets reflected but when it falls on black surface it will completely get absorbed by the surface. The LDR (Light Dependent Resistance) acts as a sensor which senses the reflected light i.e. “transmitted light by LED”.If the sensor is placed on a white surface, the D.C. motor is turned on and in black surface it will be turned off and robot
will move accordingly.

It is a simple circuit with a LM358 op-amp and is able to operate from 9v to 12V. The LM358 contains two op amps which are wired as comparators. Thus when the voltage at the non-inverting terminal (+) is higher than inverting terminal (-) its output will be high and when the voltage at the inverting terminal (-) is higher than non-inverting terminal (+) the output will be low. Outputs of the op-amp comparators are given to transistors which are wired as switch to drive the motors. Diodes D3 and D4 are provided to cancel the negative voltages produced due to the back emf of the motor.

The sensitivity of the LDR can be adjusted by using the 10K pot. For more accuracy, cover the sensor-LED pairs in a black wrapper through sides in such a way that only the reflected light falls on the LDR. The Line Follower can trace path drawn with black ink on a white chart and the width of the black track should be a litte less than the width between sensors.

Components Required

  •  LM358(2)
  •  D.C. MOTOR ( 2)
  • Variable 10K (2)
  •  Resistance 1K(4)
  • Wheel (4)
  •  Diode 4007
  •  LED ( 2)
  • LDR (2)
  • BC 547 ( 2)
  • Battery line-follower-robot-circuit-without-using-microcontroller-1005x1024

 

Can be Purchased from Here graphics-click-here-688974

Heart Rate Monitoring Sensor Circuit

Heart rate is a very vital health parameter that is directly related to the soundness of the human cardiovascular system. This project describes a technique of measuring the heart rate through a fingertip using a PIC microcontroller. While the heart is beating, it is actually pumping blood throughout the body, and that makes the blood volume inside the finger artery to change too. This fluctuation of blood can be detected through an optical sensing mechanism placed around the fingertip. The signal can be amplified further for the microcontroller to count the rate of fluctuation, which is actually the heart rate.

Reflective And Transmissive Pulse Oximetry

Pulse oximetry is a noninvasive photo-based technique that measures the light absorption and refection properties of deoxygenated and oxygenated hemoglobin. The amount of light absorbed in the hemoglobin is defined by the Lambert-Beer Law, which associates the degree of light absorption with the wavelength of the beam light, the path length, and the absorption coefficient of the blood constituents.

Heartbeat

 Requirements:

  • IC LM358
  • Potentiometer (2×100 K ohm).
  • Resistance (1×220 Ohm, 1×10 K,1×1 K, 1×47 K, 1×100 K.
  • Capacitor (1×100 nf , 1x 479 nf).
  • IR LED
  • IR Receiver.
  • Microcontroller board.
  • Display (LCD , LED Or Seven Segment).
  • Power Supply.

Sensor Assembly

The sensor unit consists of an infrared light-emitting-diode (IR LED) and a photo diode, placed side by side, and the fingertip is placed over the sensor assembly, as shown below. The IR LED transmits an infrared light into the fingertip, a part of which is reflected back from the blood inside the finger arteries. The photo diode senses the portion of the light that is reflected back. The intensity of reflected light depends upon the blood volume inside the fingertip. So, every time the heart beats the amount of reflected infrared light changes, which can be detected by the photo diode. With a high gain amplifier, this little alteration in the amplitude of the reflected light can be converted into a pulse.

HEART-BEAT-CIRCUIT
Finally

Automatic water tank Filling System

Automatic water level controller circuit is a simple project. It can automatically switch ON and OFF the domestic water pump set depending on the tank water level. You can implement this motor driver circuit at your home or college using less costly components.  The main advantage of this water level controller circuit is that it automatically controls the water pump without any user interaction.
The heart of this pump controller circuit is a NE 555 IC; Here we have manipulated the flip flop inside the 555 timer IC. Our project consists of two water level sensors, one fixed at the top and other at the bottom. Working of this circuit is almost similar to a bi stable mutlivibrator.

  • By Using This Project you are able to save water
  • By Using this you are able save time on monitoring to tank full and  to close Motor.
  • By using you are making you home to Smart Home category

Requirements

  1. Power supply (6v)
  2. NE 555 timer IC
  3. Resistors (100Ωx2, 10kΩ)
  4. Relay (6V, 30A)
  5. BC 548 transistor x2
  6. 1N4007 Diode

Automatic Water Tank Controller Engineering Project

About LCD and Its Interfacing

Electronic Display are important Devices used in the field of Robotics and Embedded System and its devices. the display Seven Segments, LCD (Liquid Crystal Display) can be used to display Data .  The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. They are of many types. The ones we commonly use for embedded systems, robotics, etc are of two types – character LCD and graphical LCD. lcd162b-yhy

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers.

  • Command/Instruction Register - stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc
  • Data Register - stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

 

lcd cammand

 

Now the Pin Map

rgblcd_pinout

Lcd_0

  •  Data pin8 (DB7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations. Therefore before passing any data to LCD, its command register should be read and busy flag should be checked.
  •  To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal.
  •   To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.

 

Arduino Liquid Crystal Library LCD Interface

Requirements :-

  • LCD 16×2
  • 1 Potentiometer
  • Jumperwire
  • Arduino Board
  • Bread board
  • Usb wire
  • Arduino IDE
  • Battery

 

All the product you can Buy From here

In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset, such as those available from Sparkfun.It currently implements 8-bit control and one line display of 5×7 characters. Functions are provided to initialize the screen, to print characters and strings, to clear the screen, and to send commands directly to the HD44780 chip. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions.

Install the Library
For a basic explanation of how libraries work in Arduino read the library page. Download the LiquidCrystal library here. Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under “Import Library”.

Connect Pin Out of arduino to LCD

The pinout is as follows:
Arduino                    LCD
2                             Enable
3                             Data Bit 0 (DB0)
4                             (DB1)
5                             (DB2)
6                             (DB3)
7                             (DB4)
8                             (DB5)
9                             (DB6)
10                           (DB7)
11                           Read/Write (RW)
12                           Register Select (RS)

Connect a potentiometer a a voltage divider between 5V, Ground, and the contrast adjustment pin on your LCD.

LCDAR

 

Program

 

#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
}
void loop(void){
lcd.clear(); //clear the display
delay(1000); //delay 1000 ms to view change
lcd.print(‘a’); //send individual letters to the LCD
lcd.print(‘b’);
lcd.print(‘c’);
delay(1000);//delay 1000 ms to view change
}

 

This is all great fun, but who really wants to type out each letter of a message indivually? Enter the printIn() function. Simply initialize a string, pass it to printIn(), and now we have ourselves a proper hello world program.
#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
char string1[] = “Hello!”; //variable to store the string “Hello!”
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
}
void loop(void){
lcd.clear(); //clear the display
delay(1000); //delay 1000 ms to view change
lcd.printIn(string1); //send the string to the LCD
delay(1000); //delay 1000 ms to view change
} //repeat forever
Finally, you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function. For example, commandWrite(2) tells the board to move the cursor back to starting position. Here
is an example:
#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
char string1[] = “Hello!”; //variable to store the string “Hello!”
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
}
void loop(void){
lcd.commandWrite(2); //bring the cursor to the starting position
delay(1000); //delay 1000 ms to view change
lcd.printIn(string1); //send the string to the LCD
delay(1000); //delay 1000 ms to view change
} //repeat forever

Projects

C Programming Based Database management project

Here we had given a small c programming  based Project that having following features.

  •  this project uses File handling and taking input and wring to files.
  • This program is password protected with password 12345.
  • This program uses good knowledge of structure.
  • this program calculates employee salay , age and sort them according to different way.
  • this  program uses some system command of c programming.
  • You can download project from  MiniProject

Using DC Gear Motor

Whenever a robotics we talk about making a robot, the first thing comes to our mind is how Robot will move (How its motion part work).  there are always three options in front of the us, one is to  use a DC Gear motor , second is to use a stepper motor and third one is to use servo motors. When we think about  speed, weight, size, cost… DC motors are always preffered over stepper motors and servo motors. There are many things which we can do with  DC motor when we interfacing it with a microcontroller.

DC-Geared-Motor

 

  •  Control the speed of motor.
  •  Control the direction of rotation
  •  Using encoder, keeping track of how many turns are made by  motors.

Here we will work on interfacing a DC motor with a microcontroller. we will use H-bridge in interfacing a DC moto with microcontroller. Some Ic that are used to interface a DC motor with microcontroller are-

H-bridge can also be made with the help of trasistors and MOSFETs etc. rather of being cheap, they only increase the size of the design board, which is somtimes not required so using a small 16 pin IC is preffered for this purpose.

Why we are using Motor Driver for controlling motor. the perfect Ans of thing question is As microcontroller is running with small current and to run a motor need high current in compare to microcontroller  for that purpose we are using Motor Driver.

Most DC motors are normally very easy to reverse. By simply changing the polarity of the DC input, the direction of the drive shaft reverses. This property makes DC motors very popular among enthusiast people involved in robotics. In most cases, DC geared motors are used.

motor driver block

 

As in diagram shown we can run two motors with the help of 1 L293D Driver.

the following Features are available in a L293D

  •  two enable (EN) pins, pin 1 and pin 9. Pin 1 EN enables the motor Channel  M1 whereas pin 9 EN enables motor Channel M2.
  • Connect motor M1 across OUTPUT1 and OUTPUT2 i.e. across pins 3 and 6.
  • Connect motor M2 across OUTPUT3 and OUTPUT4 i.e. across pins 11 and 14.
  • The inputs for motor M1 is given across INPUT1 and INPUT2 i.e. across pins 2 and 7.
  • The inputs for motor M2 is given across INPUT3 and INPUT4 i.e. across pins 10 and 15.
  • Connect GROUND pins 4, 5, 12 and 13 to ground also work for heat sink.
  • Connect pin 16 to Vcc (=5V For Running Driver) and pin 8 to Vs (battery, 4.5V~36V)(Motor Operating voltage).

 

l293d pin diagram

 

  • If Input A1 = 0V and input A2 = 5V the motor1 will run Forward
  • If Input A1 = 5V and input A2 = 0V the motor1 will run Reverse
  • If Input A1 = 0V and input A2 = 0V Or  Input A1 = 5V and input A2 = 5V  the motor will Stop(0V) Or Breaking(5V).

motor clock

Same Situation will be occur for second channel

DC Gear Motor Using With Arduino

The Motor drive’s channel one is connected to pin 6 ,  9 to motor control and pin 8 for enable motor. and a potentiometer is connected to Analog 0 Pin for controlling the speed of motor.diy-servo-wiring

Program

int motor1Pin = 6;    // H-bridge leg 1 (pin 6, 1A)
int motor2Pin = 9;    // H-bridge leg 2 (pin 9, 2A)
int enablePin = 8;    // H-bridge enable pin
int switchPin = A0;
int Motor_speed = 0;

 void setup()                                                                    {   // set the switch as an input:

    pinMode(switchPin, INPUT);
    // set all the other pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
  }
void loop() {

    Motor_speed = analogRead(sensorPin);
       analogWrite(motor1Pin, Motor_speed );   // For motor run clockwise with speed //adjusted by potentiometer
        digitalWrite(motor2Pin,0);
       delay(10000);
     analogWrite(motor2Pin, Motor_speed );     // For motor run Anticlockwise with speed //adjusted by potentiometer
        digitalWrite(motor1Pin,0);
  }
DC Gear Motor Using With AVR Microcontroller
Generating Signals for controlling the direction of motor using Port A
Motot is connected to Port A at Pin PA0, PA1, PA2 and PA3.
                               Port A Avr

#include <avr/io.h>
#include <util/delay.h>          // for _delay_ms()

int main(void)
{
DDRA = 0x0F; // initialize port A
// motors connected across PA0…PA3
while(1)
{
// clockwise rotation
PORTA = 0b00000101; // PA0 = High = Vcc
// PA1 = Low = 0
// PA2 = High = Vcc
// PA3 = Low = 0

_delay_ms(500); // wait 0.5s

// counter-clockwise rotation
PORTA = 0b00001010; // PA0 = Low = 0
// PA1 = High = Vcc
// PA2 = Low = 0
// PA3 = High = Vcc

_delay_ms(500); // wait 0.5s
}
}

Here a Video of a Robot that is developed by using DC Gear Motor

[https://www.youtube.com/watch?v=lhk7XxzQQtY]