Professional Documents
Culture Documents
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Th
he AV
VR iB
Board Gu
uide
Table of Contentss
The AVR R iBoard: ............................................................................................................................ 3
n: ..................................................................................................................... 4
Parts identification
Board Connectionn Details: .......................................................................................................... 4
Programmming the AV VR ................................................................................................................... 5
1. Prog
gram to Blinnk and LED .................................................................................................. 13 1
2. Prog 1
gram Using Switches annd LEDs..................................................................................... 14
3. Prog 1
gram to Runn Motors ....................................................................................................... 15
1
gram to use LCD modulle ............................................................................................... 16
4. Prog
5. Prog
gram to com
mmunicate with the PC thhrough UAR 1
RT ...................................................... 17
6. Prog 1
gram to use the ADC in ATMega .................................................................................. 19
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
The AVR
R iBoard:
• In
ncludes ATMMEL ATMega 16 (Also sup pports ATMegga32) Microccontroller wiith 16kB flassh
m
memory work king at 16Mip ps
• In
n system proogrammable
• O
On board prog grammer
• O
On board regu ulated powerr supply
• O
On board mot tor drivers wwith current ccapacity of uppto 600mA pper channel
• Power indicattor LED
• 2 on board Du ual full H brid
dge motor drriver for 2 steepper or 4 DC motors
• Seeparate ON/OFF switch ffor power an nd motor driv vers
• 3 LEDs for staatus or debuggging purposses
• 3 ON/OFF switches for extternal inputss/interrupts
• O
On board LCD D connector(m multipurpose port,which h can be usedd for other ap
pplications
allso)
m Input voltaage
Maximum ‐ 16V
Minimum
m Input voltage ‐ 7V
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Parts ide
entification
n:
• Power On Swiitch: It’s a baasic push to o on ‐ push to ooff type switcch.
• ICC 7805: It’s aa three terminal linear 5 volt regulattor used to supply the m microcontrolleer
annd other perripherals.
• M
Motor Enable switch: Thiss switch is ussed to enablee/disable thee motor driveer chips hencce
in
n turn enabling/disablingg the motors..
• R
Reset Switch: This switch is used to reeset the micro ocontroller.
• M
MAX 232: Thi is chip takess care of the voltage conv versions neeeded to comm municate witth
thhe PC’s RS232 (Serial/ CO OM) port.
• L293D: It is a 4 channel m motor driver w with 600mA of current p per channel aand has inbuiilt
cllamp diodes.. The board ccontains two such chips.
• Potentiometer (Pot): The potentiometter is used to vary the con ntrast of the LCD.
• Seensor port: A At a time, 8 individual seensor modulles can be co onnected to this port. Th
he
port also prov vides a 5V suupply needed d drive the seensors.
• D
DB 9 connect tor: This is a 9 pin conneector used to o connect to the PC’s COM M port durin
ng
programmingg or for generral UART com mmunication ns.
• Swwitch array y: Four gen neral purpo ose switchess are connected in th he active‐low
coonfiguration.
• Crystal: A crysstal sets the microcontro oller’s clock frrequency to 11.0592 MH Hz.
• Beeper: Connected in the active low m mode, the beeeper can eassily be used to get audible
feeedbacks from m the contro oller.
• A
ADC Test: Shhort the tw
wo pins of tthe jumper next to thee potentiom meter and thhe
potentiometer gets connected to the P PortA 7.
Board Connection Details:
Port A
0…7 Seensor Conneector
Port B
0…3 M Motor Driverr
4 Sw
witch 1 (Actiive Low)
5,7 Programmer
6 LED D2 (Activve High)
Port C
0 LCD Control P
Pin
1 LED D1 (Activve High)
2 LCD Control P
Pin
3 Buzzer (Active High)
4…7 LCD Data Pinss
Port D
0 U
USART RXD
1 U
USART TXD + LED D3
2,3 Sw
witch 2,3
4…7 Motor Driver
M
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Program
mming the A
AVR
AVR micrrocontrollerss are fun, pow werful, featurre rich and aamong those microcontro ollers that can
be got upp and runningg quickly witthout much eeffort. Secondly a lot of reesources aree available onn
the net th
hanks to the eever widenin ng AVR comm munity. Free ware prograammers, com mpilers,
projects, name it and you get it.
For our uuse we will bee working with the follow wing softwarres
WinAVR ‐ http://winavr.sourcefo orge.net/
AVR Stud dio ‐ http://w
www.atmel.com
PonyProgg ‐ http://ww ww.lancos.co om/prog.htm ml
Download and install the followin ng softwares before we sttart of on ourr quest to usee to the AVR..
Checklistt:
1. AVR board
A
2. Power supply y
3. Seerial Cable
4. Computer witth the above softwares in nstalled
5. So ome patiencee :)
Step 1: Oppen AVR Studio, you will get the folloowing window w, click on N
New project
Step 2: Seelect AVR GC
CC and enter a name and d
destination ffor your project
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step3: Select AVR sim
mulator and the device to be used.
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step 4: Sttart writing y
your first pro
ogram.
#include< <avr/io.h>
#include< <avr/interru upt.h>
/*Macross definition*//
#define BBIT(x) (1 << (x))
#define CCHECKBIT(x,,b) x&b //Checkks bit status
#define SSETBIT(x,b) xx|=b; particular bit
//Sets the p
#define CCLEARBIT(x,b b) x&=~b; //Sets the p
particular bit
#define TTOGGLEBIT(xx,b) x^=b; //Toggles thhe particularr bit
int main((void)
{
SETBIT(D DDRB,BIT(6))) //Sets D
Direction of 66th pin of po
ort B as outpu
ut
while(1)
{
SEETBIT(PORT TB,BIT(6)) //Sets P
PORTB6 as h high i.e. LED oon AVR Boarrd Glows
}
}
Goto “Buiild” menu an nd click on Buuild.
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step 5: Op
pen PonyPro
og and go to ““Setup” interrface setup
Make the settiings as show
Step 6: M wn
Step 7: Cllick on “Setup
p” menu and d click on Calibration. A dialog box ask
king whetherr you want to
o
run calibrration now wwill appear. C
Click on “YESS”
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step8: Cliick on “Securrity and Conffiguration Bits” .Click on read first. Th
hen make thee settings as
shown. AAnd click on wwrite.
pen the hex ffile that AVR
Step 9: Op R studio generate. You willl find it insid
de a directory
y called
“Default” where the p
project was saaved. Then ggo to commaand menu and d click on wrrite
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step 10: C
Click on “Yess”
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Did you ssee the LED DD2 light up?? If yes, Congrratulations y
you have justt climbed thee first step.
d you get the following errror??
If not, did
Check thee following:
1. Is the ppower on?
2. Is the ‘PProg’ switch on the board d pressed?
3. Is the sserial cable connected?
If the ansswers to all thhis is ‘Yes’ ch
heck whetherr you have seelected the co
orrect devicee and the
fusebit seettings.
Happy Co oding!!!
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
1. Program to Blinkk and LED
This code blin nks the LED D2 on PORT TB PIN6 i.e P PB6 of the A AVR board. T The LED D2 is
connected to PB6 on tthe microcon ntroller, and is wired so tthat itt will be ON
O when th he
output iss high and OFF
O when thee output is llow. The "sp pecial functiion registerss" used in th
his
program are:
DDRB ‐‐ Port B Data D Direction Register
A high (1 1) value indicates outputt, low (0) is input.We sett the 6th bit in DDRB to configure th he
PB6 pin aas output pin n.
PORTB ‐‐ Port B Dataa Register
This is ussed to set thee output valu ue for each off the eight poort B pins.
WaitMs(() is used to p produce a delay.
#include< <avr/io.h>
#include< <avr/interru upt.h>
/*Macross definition*//
#define B BIT(x) (1 << (x)) //Set a partticular bit maask
#define C CHECKBIT(x,,b) x&b //Checks bit status
#define S SETBIT(x,b) xx|=b; particular bit
//Sets the p
#define C CLEARBIT(x,b b) x&=~b; //Sets the p
particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles th he particularr bit
void WaittMs(unsigned int ms);
int main((void)
{
SE ETBIT(DDRB B,BIT(6)) //SSets Direction of 6th pin o of port B as o
output
w
while(1)
{
SETBIIT(PORTB,BIT(6)) //Sets PORT TB6 as high ii.e. turn on leed
WaitM Ms(200); //delay for 200ms(0.2s))
CLEAR RBIT(PORTB B,BIT(6)) //Clears POORTB6(PB6 p pin goes low)) i.e
//turn off leed
WaitM Ms(200); //delay for 200ms(0.2s))
}
reeturn 0;
}
/* waits ((pauses) for ms milliseco onds (assumees clock at 16 6MHz) */
void WaittMs(unsigned int ms)
{
innt i;
w
while (ms‐‐ > 0)
{
/* 163 380 (16k) clo ock cycles forr 1ms; each ttime through h loop
is 5 ccycles (for lo
oop control ++ nop) */
for (i == 0; i < 3276;; ++i)
asm("nop"");
}
}
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
2. Program Using SSwitches an
nd LEDs
This code glo ows the LEDD D2 on POR RTB PIN6 i.ee PB6 of thee AVR board d, if switch1
1is
turned on n else it is offf. The LED DD2 is conneccted to PB6 o on the microccontroller, an nd is wired sso
that it wiill be ON whhen the output is high an
nd OFF when n the outputt is low. Thee Switch S1 is
connected to PB4. Th he "special fu
unction registters" used in n this program m are:
DDRB ‐‐ Port B Data D Direction Register
A high (1 1) value indiccates output,, low (0) is input. We seet the 6th bitt in DDRB to configure th he
PB6 pin aas output pin n. We clear th
he 4th bit in DDRB to con nfigure the PB4 pin as inp put pin.
PORTB ‐‐ Port B Dataa Register
This is ussed to set thee output valu ue for each off the eight po ort B pins.
PINB ‐‐‐ P PORTB inputt register, used to read in nputs in PORT TB pins
#include< <avr/io.h>
#include< <avr/interru upt.h>
/*Macross definition*//
#define B BIT(x) (1 << (x)) //Set a partticular bit maask
#define C CHECKBIT(x,,b) (x&b) //Checks bit status
#define S SETBIT(x,b) xx|=b; particular bit
//Sets the p
#define C CLEARBIT(x,b b) x&=~b; //Sets the p
particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles th he particularr bit
int main((void)
{
SE ETBIT(DDRB B,BIT(6)) //Sets tthe 6th pin in
n DDRB regisster to
//make PB6 6 a output pin n
CLEARBIT(DD DRB,BIT(4)) //Clears thee 4th pin in D DDRB registeer to
//make PB4 4 a input pin
w
while(1)
{
if(CHEECKBIT(PINB B,BIT(4))) //Chheck 4th bit iin PINB regisster
SETBIT(PO ORTB,BIT(6)) //Seets PORTB6 aas high i.e. LE ED on
//AV VR Board Glo ows
else
CLEARBIT(PORTB,BIT(6)) //Cllears PORTB6, PB6 goes llow i.e
//tu
urn led off
}
reeturn 0;
}
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
3. Program to Run Motors
Connect moto ors to the mootor connectoors. We will move them iin the either directions.
The moto ors are conneected to the PPortD 4‐7 an
nd PortB 0‐3
#include< <avr/io.h>
#include< <avr/interruupt.h>
/*Macross definition*//
#define B BIT(x) (1 << (x)) //Set a partticular bit maask
#define C CHECKBIT(x,,b) (x&b) //Checks bit status
#define S SETBIT(x,b) xx|=b; particular bit
//Sets the p
#define C CLEARBIT(x,b b) x&=~b; //Sets the p
particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles thhe particularr bit
void delaay(unsigned iint time)
{
unsignedd int i,j;
for(i=0;i<<1000;i++)
{
foor(j=0;j<timee;j++){}
}
}
int main((void)
{
D
DDRB=0x0F; //SSets lower niibble as outp
put
D
DDRD=0xF0; //SSets lower niibble as outp
put
w
while(1)
{
PORTB=0x05; //MMove motorss in one direcction
PORTD=0x50;
delay(1000);
PORTB=0x0A A; //Move mo otors in one direction
PORTD=0xA0 0;
delay(1000);
}
reeturn 0;
}
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
4. Program to use LLCD module
This head der files havee implementaation of some common finctions of th he LCD.
Include this
t header file in your C code. Calll the lcd_iniit() function before calliing any otheer
functionss to initialize the lcd.
lccd_init() ‐‐‐‐‐ Call the lcd__init() functio on before calling any otheer functions
to initializze the lcd.
lccd_cmd() ‐‐‐‐‐‐ This functiion is used to o give any co
ommand insttructions to tthe
LCD. For ee.g lcd_cmd(0x01) will giive the clear command.
lccd_char() ‐‐‐‐‐‐ This function will display a single ch haracter on tthe LCD display.
For example lcd_char((0x61) will d display A. Agaain lcd_char(('b')
will displaay b.
lccd_string()‐‐‐‐‐ This function will display a string. A An example o of this wouldd be
like lcd_sttring("This iss AVR")
lccd_showvalue()‐ This willl show a 3‐diigit decimal v value on the LCD. For
example if f we give lcd__showvalue(0 0xFF) then 2
255 will be diisplayed.
lccd_gotoxy1()‐‐‐ Will set th he cursor at a particular p position on L
LINE1 of the LCD.
So lcd_gottoxy1(3) will set the curssor at the 3+1 1=4th colummn in
the 1st lin
ne of the LCD D.
lccd_gotoxy2()‐‐‐ Will set th he cursor at a particular p LINE1 of the LCD.
position on L
So lcd_gottoxy2(0) will set the curssor at the 0+1 1=1st column in
the 2nd liine of the LCD D.
lccd_exit() ‐‐‐‐‐‐ You may calll this functio on after you are over with h your
LCD. Whilee calling the lcd functionss, there wou uld be some cchanges to th he
PORTC. Th his restores tthe original P PORTC configguration befo ore calling thhe
lcd_init() ffunction. Thiss is not absolutely necesssary. You may or may no ot
use this fun nction.
#include< <avr/io.h>
#include""LCD.h"
#define B BIT(x) (1 << (x))
#define C CHECKBIT(x,,b) (x&b) //Check ks bit status
#define S SETBIT(x,b) xx|=b; //Sets tthe particulaar bit
#define C CLEARBIT(x,b b) x&=~b; //Sets the p
particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles thhe particularr bit
int main((void)
{
lccd_init();
lccd_string("Th his is My Firsst LCD prograam");
w
while(1)
{}}
reeturn 0;
}
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
5. Program to communicate w
with the PC
C through U
UART
This code imp plements UART communication betw ween your PC C and AVR bo oard. This is a
simple EC CHO program m. So what y you send from m the Hyper terminal of the PC will b be received b by
the microo controller and resend back, i.e it w
will echo bacck the data. In this progrram USART is
configureed to 9600bps, 8‐bit chaaracter size and no parity. You neeed to configu ure the hypeer
terminal connection w with these seettings.
The "speecial function
n registers" used in thiss program are
a UBRR, UC CSRA, UCSRB B, UCSRC annd
UDR.
#include <avr/io.h>
#include< <avr/interruupt.h>
/*Macross definition*//
#define B BIT(x) (1 << (x)) //Set a particular biit mask
#define C CHECKBIT(x,,b) x&b //Checks bit status
#define S SETBIT(x,b) xx|=b; //Sets the p particular bit
#define C CLEARBIT(x,b b) x&=~b; //Sets the p particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles th he particularr bit
unsigned d char Recv;
int main (void)
{
///Initialize UAART with 8‐b bit character sizes,no parrity,1 stop bitt
U
UBRRL=0xA0 ; //WWrite UBRRL L register firsst
U
UBRRH=0x01 1; //then wriite the UBBR RH register
U
UCSRB=0x98; ; //Set RXCIIE, RXEN, TX XEN bits
U
UCSRC=0x86; //Set URSEEL,UCSZ0,UC CSZ1
seei(); //Enable G
Global Interrupt
w
while(1)
{
}
}
//RX com mplete Interrrup routine..put here alll the code th hat you wan nt to do withh the receiveed
data..
ISR(USAR RT_RXC_vectt)
{
R
Recv=UDR;
U
UDR=Recv;
}
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
Step 1: En
nter a name for the conneection
Step 2: Seelect the COM
M port and co
onfigure its p
properties
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
6. Program to use tthe ADC in ATMega
This code imp plements ADC C conversion n. The Test po ot at PA7 (AD DC7) is used to control th he
brightnesss of the led D2 (Make su ure the jump per is inserteed). The pot gives a variaable voltage aat
the ADC7 7 pin. This iss converted tto a digital vvalue. This diigital value is then used to control th he
brightnesss of the LEED. A simplee PWM with h delay routtines is used. The "special functio on
registers"" for ADC aree ADMUX, AD DCSRA, ADCH H, ADCL and SFIOR.
ADMUX iis used to seelect which cchannel to usse for ADC co onversion. W We used ADC7 here. It alsso
has an AD DLAR bit, by setting whicch the ADC daata value beccomes left ad djusted.
ADCSRA contain bits to enable AD DC,start ADC, select ADC prescale clocck,etc.
ADCH an nd ADCL con ntains the ADC data..Wee used ADCH H only coz w
we are satisfiied with 8‐b bit
resolution only.
SFIOR co ontains bits to
t configure different modes.
m Defau
ult value setss the ADC att free runnin
ng
mode.
The ADC ISR is executted when a A ADC conversiion completees. In the ISR R, you can do whatever yo ou
like with the ADC con nverted valuee stored in A ADCH:L At thee end of the IISR routine y you should set
the ADSCC (ADC start cconversion) b bit to again sstart the ADC C conversion.
#include <avr/io.h>
#include< <avr/interru upt.h>
/*Macross definition*//
#define B BIT(x) (1 << (x)) //Set a particular biit mask
#define C CHECKBIT(x,,b) x&b //Check ks bit status
#define S SETBIT(x,b) xx|=b; //Sets tthe particulaar bit
#define C CLEARBIT(x,b b) x&=~b; //Sets the p particular bit
#define T TOGGLEBIT(xx,b) x^=b; //Toggles th he particularr bit
unsignedd char digital= =100;
void Waitt(unsigned char delay);
int main((void)
{
///ADC Initialiization
A
ADMUX=0x27 7; //We set AADLAR=1(lefft adjusted) aand set the M MUX bits
//tto select ADCC7 input.
A
ADCSRA=0x8 E; //eenable ADC aand ADIE(En nable ADC intterrupt)
SE ETBIT(DDRB B,BIT(6)); //Set thhe DDRB bit 6 to configurre PB6 as outtput
SE ETBIT(PORT TB,BIT(6)); //Turn on the Led D D2
seei(); //EEnable Globaal Interrupt
SE ETBIT(ADCSSRA,BIT(6)); //Start ADC conversion
w
while(1)
{
//Herre we generate PWM usin ng a simple delay routine,,
TRI Technoso
T olutions Pvt
P Ltd
a SINE, IIT Bombay incu
ubatee
//ON time is proportional to th he digital vallue recieved
//fromm the ADC
//ON TIME
SETBIIT(PORTB,BIT(6)); //turn on leed
Wait(d digital);
//OFF F TIME
CLEAR RBIT(PORTB B,BIT(6)); //turn off leed
Wait(2 255‐digital);
}
reeturn 0;
}
//ADC coonversion com mplete ISR
ISR(ADC__vect)
{
digital=ADCH; //Get the A ADC converteed value..Sinnce we used L Left
//aadjusted, so w
we need to aaccess the AD DCH only
SEETBIT(ADCSSRA,BIT(6)); //Start the next ADC conversion n
}
//A delayy routine
void Waitt(unsigned char delay)
{
unsigned charr i;
w
while (delay‐‐ ‐ > 0)
{
for (i =
= 0; i < 65; ++
+i)
asm("nop"");
}
}