What is a micro controller
Today we will discuss about - what is a micro controller?
So first let me tell you what is the difference between an IC and a micro controller or what is the difference between normal IC controlled circuit and a micro controller controlled circuit.
A normal IC is or integrated circuit , sometimes called a chip or microchip, is a semiconductor wafer on which thousands or millions of tiny resistors, capacitors, and transistors are fabricated. An IC can function as an amplifier, oscillator, timer, counter, computer memory, or microprocessor. A particular IC is categorized as either linear (analog) or digital, depending on its intended application.
Such an IC is pre programmed or the purpose of its application is defined by the manufactures and those IC's can be used only for that purpose.
Now come to micro controller
A micro controller is a small, low-cost computer-on-a-chip which usually
So first let me tell you what is the difference between an IC and a micro controller or what is the difference between normal IC controlled circuit and a micro controller controlled circuit.
A normal IC is or integrated circuit , sometimes called a chip or microchip, is a semiconductor wafer on which thousands or millions of tiny resistors, capacitors, and transistors are fabricated. An IC can function as an amplifier, oscillator, timer, counter, computer memory, or microprocessor. A particular IC is categorized as either linear (analog) or digital, depending on its intended application.
Such an IC is pre programmed or the purpose of its application is defined by the manufactures and those IC's can be used only for that purpose.
Now come to micro controller
A micro controller is a small, low-cost computer-on-a-chip which usually
includes:–
·
An 8 or 16 bit microprocessor (CPU)
·
A small amount of RAM
·
Programmable ROM and/or flash memory
·
Parallel
and/or serial I/O
·
Timers and signal generators
·
Analog to Digital (A/D) and/or Digital to Analog (D/A)
conversion.
In a micro controller, the device is user programmable.
That is the user can write programs as per his needs and can be loaded into the
micro controller. So a single micro controller can be used for various purposes
by changing the program written into it.
It is also called embedded controllers, because the micro controller and support circuits are often built into, or embedded in, the devices they control.Embedded products are designed to allow the user to provide input and receive results.
It is also called embedded controllers, because the micro controller and support circuits are often built into, or embedded in, the devices they control.Embedded products are designed to allow the user to provide input and receive results.
Basic structure of a
micro controller
Block diagram
explanation:
Crystal oscillator:- It has the same function as that of a human
heart. It generates the clock pulses through which the entire functions of the
micro controller are carried out.
ADC/DAC:- Since the micro controller is a digital device, the
ADC/DAC port/pin is used for interfacing the external analog devices
Timers/Counters:- The timer TMR0/1 has a wide
range of applications in practice. Very few programs don't use it in some way.
It is very convenient and easy to use for writing programs or subroutines for
generating pulses of arbitrary duration, time measurement or counting external
pulses (events) with almost no limitations.
Parallel
I/O ports:- have a wide range of alternative functions:
•
UART
Universal asynchronous receiver/transmitter
•
SSI
Synchronous serial interface
•
I2C
Inter-integrated circuit
•
Timer
Periodic interrupts, input capture, and output compare
•
PWM
Pulse width modulation
•
ADC
Analog to digital converter, measure analog signals
•
Analog Comparator Compare two analog signals
•
QEI
Quadrature encoder interface
•
USB
Universal serial bus
•
Ethernet
High-speed network
•
CAN
Controller area network.
Parallel Ports Basics
Parallel ports are a set of pins used to interface external devices. The number of such ports are different for different micro controllers. Simply it can be defined as, we know that a micro controller is a programmed device which will perform as per the program. So in order to perform some actions the controller should be connected to some device/ circuit. As an example, in circuit we want to blink an LED for 5 seconds whens a key is pressed.Then we have to connect a switch and a LED to the controller. So we use the parallel ports to connect these components. The below picture shows the basic structure to connect an LED and switch to the controller.
We can choose any two pins(
depends on the type of controller) and assign one pin(say pin-1) for the switch
and the other(pin-2) for connecting the LED. And the a program is written in a
manner that when the switch is pressed blink the LED for next five seconds.
Program logic: when the switch is closed the pin is actually connected to ground. That means a 'zero' is given as input. Then as per the program when a 'zero' is detected in pin-1, a loop/timer starts counting till 5 seconds, and an output is given to the pin-2 till the loop/timer ends. Out put means a 'one' is given to the pin-2 which is +5 volts causes the LED to blink.
Uses of parallel ports:
Usually micro controllers are not used in simple circuits as stated above. They are always used in much bigger circuits and devices that have lots of functions depending on the situations. Situations simply mean the conditions that are given by the user.
As example suppose we want a device, when temperature in a room is becomes higher than a particular value, which will turn on the air conditioner and if the temperature falls beyond a value then turn offs the air conditioner. Then we have got two conditions that are, two temperatures. Using a digital thermometer we continuously check the temperature and the readings are given to the micro controller through any one pin of the micro controllers parallel port. Then we wright the program to detect the condition ( both the values of temperature) and also what to do for that conditions.
Program logic: when the switch is closed the pin is actually connected to ground. That means a 'zero' is given as input. Then as per the program when a 'zero' is detected in pin-1, a loop/timer starts counting till 5 seconds, and an output is given to the pin-2 till the loop/timer ends. Out put means a 'one' is given to the pin-2 which is +5 volts causes the LED to blink.
Uses of parallel ports:
Usually micro controllers are not used in simple circuits as stated above. They are always used in much bigger circuits and devices that have lots of functions depending on the situations. Situations simply mean the conditions that are given by the user.
As example suppose we want a device, when temperature in a room is becomes higher than a particular value, which will turn on the air conditioner and if the temperature falls beyond a value then turn offs the air conditioner. Then we have got two conditions that are, two temperatures. Using a digital thermometer we continuously check the temperature and the readings are given to the micro controller through any one pin of the micro controllers parallel port. Then we wright the program to detect the condition ( both the values of temperature) and also what to do for that conditions.
Or in some other devices we have to detect several conditions
and have to perform so many functions. Also these ports are used to interface
other chips and external memory.
The AT89C51 is a
low-power, high-performance C MOS 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 pin-out. The on-chip Flash allows the program memory to be
reprogrammed in-system or by a conventional 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.
First let's see the architecture of AT89c51
As you can see, the controller has 40 pins, of them 32
pins are the parallel ports that are used for interfacing. These 32 pins are
divided into 4 ports having 8pins for each. They are named as port 1, port 2,
port 3, port 4.
Port 1:- p0.0,p0.1,p0.2,p0.3,p0.4,p0.5,p0.6,p0.7 ( pin no:
39-32)
Port 2- p1.0,p1.1,p1.2,p1.3,p1.4,p1.5,p1.6,p1.7 ( pin no: 1-8)
Port 3:- p2.0,p2.1,p2.2,p2.3,p2.4,p2.5,p2.6,p2.7 ( pin
no: 28-21)
Port 4:- p3.0,p3.1,p3.2,p3.3,p3.4,p3.5,p3.6,p3.7 ( pin no:
10-17)
Pin 18 and 19 are for connecting crystal oscillator, pin 20 is
ground and 40 is vcc.
You can use any/all of the 4 ports to interface LED's. In this
experiment i had selected the Port 1:(p 0.0 - p0.7).
In this experiment we are
going to interface 8 LED's.
Components required:-
1. 8 LEDs.
2. Micro controller AT89c51.
3. 8 registers. (330 ohm)
4. 12MHz crystal oscillator.
5. 10 KΩ fixed register.
6. 10 μf (25v) capacitor.
2. Micro controller AT89c51.
3. 8 registers. (330 ohm)
4. 12MHz crystal oscillator.
5. 10 KΩ fixed register.
6. 10 μf (25v) capacitor.
Circuit
diagram
Connections are made as per the circuit
diagram. Here LED's are running of negative logic. That means normally every
pin of port 1 have +5v as output. Here cathode of every LED is connected
with Micro controller port pin and anode of all the LED's are connected to +5v
supply. Thus both the legs of LED are supplied with +5v. So we
required to give 0v at the output of micro controller in order to 'ON' the
LED's.
We are sending the sequence of 0x055 and 0x0AA alternatively with some delay.
Delay is in the range of few milliseconds.
Code :
#include<reg51.h>
void delay(int time)
//This function produces a delay in msec.
{
int
i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P1=0x00; // this code turns ON the LED's
delay(100);
P1=0xff; // this code turns OFF
the LED's
delay(100);
}
}
If port 2 is used then the code becomes :-
#include<reg51.h>
void delay(int time)
{
int
i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P2=0x00; // P1 changed to
P2. If p3 is used then write P3 here.
delay(100);
P2=0xff;
delay(100);
}
}
If more than one port is used then the
circuit diagram becomes:-
Here Port 1 and Port 3 are together used for interfacing
16 LED's.
Code (All 16 turned ON at a times)
#include<reg51.h>
void delay(int time)
{
int
i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P1=0x00; // this code turns ON the LED's in
Port 1
P3=0x00; // this code turns ON the LED's in Port 3
delay(100);
P1=0xff; // this code turns OFF
the LED's in Port 1
P3=0xff; // this code turns OFF the LED's in Port 3
delay(100);
}
}
Code (Only 8 LED's turned ON at a times)
#include<reg51.h>
void delay(int time)
{
int
i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P1=0x00; // this code turns ON the LED's in
Port 1
P3=0xff; //
this code turns OFF the LED's in Port 3
delay(100);
P1=0xff; // this code turns OFF
the LED's in Port 1
P3=0x00; // this code turns ON the LED's in Port 3
delay(100);
}
}
thank you.