AVR ATmega8 Bases Line Follower.
Easy to make PID LFR Robot.
A Typical MCU based solution. |
|
Block diagram |
|
The program it is executing is like this( In C language).The MCU contains a flash memory where it stores its program(its like a hard disk to it). The flash memory can be easily erased and a new program can burned. This makes them very flexible. MCUs can be programmed few thousand times before they die. | |
A Simple MCU Based System |
A Sample Program |
|
For example the image shows the PORTB and it bit numbering. Setting PORTB=0b00000001 will set PORTB's zeroth bit high that is 5V while remaining PINs will be low(GND).[NOTE:To write a binary number in c prefix it with 0b ex 0b00001000. It is decimal 8 not 1000 !!! ]The program above is not complete program it is just a pseudo-code.So it won't compile.Also you may be wondering where it will be entered, compiled and how the heck it will pushed into that chip?They are the subject of next tutorials and I will be covering them in detail. | |
MCU Ports |
A MCU has some ports.orts are PINs on the MCU that can be turned on and off by program.By on I mean 5V and off means 0V or GND.This behavior is for OUTPUT mode. They can also be put in INPUT mode. In INPUT mode they can read what is the signal level on them (only on and off).If voltage is more than a threshold voltage(usually half the supply) it is reported as ON(1) otherwise OFF(0).This is how MCU control everything .Majority of the PINs of a MCU are PORT so you can hookup lots of gizmos to it !!!They are named PORTA,PORTB,PORTC,PORTD etc.They are of one byte which means 8 Bitts all bits of them are connected to external pins and are available outside the chip.In smaller chips only some of the eight bits are available. For example the image shows the PORTB and it bit numbering. Setting PORTB=0b00000001 will set PORTB's zeroth bit high that is 5V while remaining PINs will be low(GND). [NOTE:To write a binary number in c prefix it with 0b ex 0b00001000. It is decimal 8 not 1000 !!! ] The program above is not complete program it is just a pseudo-code.So it won't compile.Also you may be wondering where it will be entered, compiled and how the heck it will pushed into that chip?They are the subject of next tutorials and I will be covering them in detail.
What the program does
STEP 1 SetPortDirection(); This Function Makes the PORTB as OUTPUT.Its implementation detail is not shown.
STEP 2 PORTB=0b00000001; makes the 0th bit high, switching off the L.E.D. because other end of LED is connected to VCC(i.e. Supply voltage 5V)
STEP 3 Delay(0.5); Halts the MCU for 0.5 Sec
STEP 4 PORTB=0b00000000; Switches on the LED
STEP 5 Delay(0.5); STEP 2 to 5 are within an infinite while loop so it runs till MCU is powered. The program is compiled, and burned into the chip and power is turned on and woillaaaa that LED is blinking once every second.You have just understood the "HELLO WORLD" program for MCU empire .Although the given program doesn't do something very important and can be done without a MCU and in a cheap manner, but it introduce you to microcontroller programming.Doing this with MCU has some advantages also.You can change the way LED blinks by simply writing a new program without touching the hardware part.You can also connect 8 LEDs to all 8 PINs of the PORTB, write a nice program them to light them in various pattern and you have a deluxe decorating lights !!! Which you can't make easily without MCUs.So you have seen that major functioning of a MCU project are made in software and hardware part is simple and small.
Return to Help Index.