Академический Документы
Профессиональный Документы
Культура Документы
Prepared by:
Eng. Ashraf Darwish
Ashraf.emad.darwish@gmail.com
Course Outline
Introduction to Microcontroller
AVR microcontroller Architecture.
Introduction to embedded C programming.
I/O Ports.
LCD & Keypad Interface.
Interrupts .
Timers/Counters
Stepper Motors .
Analog to digital converter ADC.
Serial Communication USART.
Introduction
Microcontroller
Faster
Slower
General purpose
More Expensive
Cheaper
Multi-operation
Single Operation
Introduction
Microprocessor
Introduction
Microcontroller
Memory Types
(ROM)
I. ROM(ROM)
II. PROM(Programmable ROM).
III. EPROM (Erasable PROM).
IV. EEPROM(Electrically Erasable PROM).
3. Flash memory
Microcontroller Types
ATMEL
Microchip
Motorola
(PIC)
Microcontroller series
AT tiny
AT mega
AT xmega
0.58kB program
memory
4256kB program
memory
16384kB program
memory
632-pin package
28100-pin package
4464100-pin
package
Limited features
Extended features
More extended
features
Why AVR ?
Cost Effective.
High capabilities
User friendly
Work cycle
1.
2.
3.
4.
5.
Use your Programmer kit to write your hex file on the chip.
6.
AT mega 16 Features
Pins Configuration
Pin Description
Pin
Description
4 I/O Ports
RESET
reset the IC
XTAL1 ,
XTAL2
AVCC
AREF
Embedded C programming
# Include Files: according to
Codevision
C header files :
Embedded C
programming
C functions
Main
Other functions
Function prototype before the main function
Embedded C
programming
Variable Declaration:
Type
Size (Bits) Range
bit
1
0,1
char
8
-128 to 127
unsigned char 8
0 to 255
signed char 8
-128 to 127
int
16
-32768 to 32767
short int 16
-32768 to 32767
unsigned int 16
0 to 65535
signed int 16
-32768 to 32767
Embedded C
programming
Variable Declaration:
Type
Size (Bits) Range
long int
32 -2147483648 to
2147483647
unsigned long int 32 0 to 4294967295
signed long int
32 -2147483648 to
2147483647
float
32 1.175e-38 to
3.402e38
double
32 1.175e-38 to
3.402e38
Embedded C
programming
Operators:
Assignment operator (x=y) (+=, -=, /=, *=)
Increment/decrement operator ++/- Equal operator (==)
Less than (<) less than or equal (<=)
Greater than (>) less than or equal (>=)
Not equal (!=)
Logical operators:
And (&&)
Bitwise AND (&)
Or (||)
Bitwise OR(|)
Not (!)
Bitwise XOR(^)
Complement (~)
Right shifted (>>)
Left shifted (<<)
Embedded C
programming
If Statement:
If(condition is true)
{
Write your code
}
Else if (another condition is true)
{
Write your code
}
:
.
Else
{
Write your code
}
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);
DDRA = 0xFF
output
DDRA = 0x00
input
output on
PORTx
PORTA = 0x55
port A
PORTA.3=1
PinA.3
PINx
Variable = PINA
Variable = PINA.1
out on
Embedded C
programming
Sample Code :
# include <ATmega16.h>
#include <delay.h>
void main (void)
{
DDRA=0x00
DDRB=0xFF
while (1)
{
if (PINA.0==1)
{
PORTB=0xFF
while (PINA.0=1)
{;}
}
if (PINA.0==0)
{
PORTB=0x00;
while (PINA.0=0)
{;}
}
}
}
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);
Embedded C
programming
While statement
While(condition)
{
Do whatever here
}
Do
{
}while(condition);