You are on page 1of 85

AVR Microcontroller

Embedded System Designing

Dr. Shirin Saleh Ahari

Department of Electrical and


computer Engineering
Grading

• Mid-term exam: 30%


• Final exam: 40%

• laboratory: 30%

References
• Muhammad Ali Mazidi, Sarmad Naimi, Sepehr Naimi, “the AVR
microcontroller and embedded system: using assembly and C”
SYLLABUS OF MICROCONTROLLER COURSE

 Introduction; application based introduction of microprocessors and


microcontrollers, microcontroller vs microprocessor
 The AVR microcontroller: history and features
 AVR microcontroller Architecture.
 C Review.
 AVR programming and applications( mega 32/16) “According to the
course flow”.
 I/O Ports.
 LCD
 Timers/Counters
 keypads
 Analog to digital converter “A/D”.
 Motor control with PWM
Introduction
A microcontroller is a single chip, self contained computer.
Introduction
Microprocessor vs. Microcontroller: the main difference is
related to their operation and their Peripherals

RAM ROM

Serial & Micro-


I/O Port
Parallel Ports Processor

Timer Interrupt
Introduction
Microprocessor vs. Microcontroller
Introduction
 Microprocessor:
 only processing of data
 Faster
 General purpose
 Expensive
 CPU is stand-alone, RAM, ROM, I/O, timer are
separate.
 Designer can control the amount of ROM, RAM and
I/O ports.
 It is cheaper compared to the microcontroller with
the same features.
Introduction

 Microcontroller:
 Slower.
 Stand alone operation.
 Cheaper.
 CPU, RAM, ROM, I/O and timer are all on a
single chip(but fixed amount).
 for applications in which cost, power and
space are critical.
 Single Operation.
history
AVR family
AVR family First AVR family

•AT90S series: These are the classic members of the AVR


family and have fewer features than the next two, and less
Word is used.

•ATtiny series: These microcontrollers are small in size 8 to 32


base and have better capabilities than the first category and
are mostly used in systems that do not require a high port.it is
8 bit.

•ATmega Series: This category has more features than the


previous two categories. These types of microcontrollers are
self-programmable and can be programmed using additional
circuits. It is 8 bit. It has 4–256 KB program memory .
ATMEGA8, ATMEGA48, ATMEGA16, ATMEGA32,…

•Atxmega series: these category is the largest and the


advanced one and has 16–384 KB program memory. It is 16 bit
microcontroller components

 CPU
 Memories
 Input/output
ports
 Timer/counter
 Parallel ports
 Interrupt sources
 PWM function
 (A/D , D/A)
converters
microcontroller components

 CPU: central proceeding unit


 CPU is the brain of a microcontroller. CPU is
responsible for fetching the instruction, decodes it,
then finally executed. CPU connects every part of a
microcontroller into a single system. The primary
function of CPU is fetching and decoding
instructions. The instruction fetched from program
memory must be decoded by the CPU.
 Flech
 Decode
 Execute
 CPU components
1. Register
2. ALU: arithmetic logic unit (ALU) is a combinational digital
circuit that performs arithmetic and bitwise operation
3. CU : control unit decodes the instructions, and controls all
the other internal components of the CPU to make it work.

An auxiliary register
1. Register: is a quickly accessible location available to a
processor and is one of a small set of data holding places that
may hold an instruction, a storage address, or any kind of data
 Accumulator register: the accumulator is a register in which
intermediate arithmetic and logic results are stored

 Flag register: it is the status register, the value of these bits


indicates some conditions that result after the execution of an
instruction
o Ex: ZF flag (zero falg): if the result of instruction will be zero then
ZF=1
o Ex: sign flag (negative –positive statues):if the sign of the
instruction will be negative then SF=1

 Program counter or instruction pointer register: indicates


where a CPU is in its program sequence and contains the
address of the next instruction meaning that along executing
the program a unity added to the line of number of the next
instruction
 Memory types:
 There are several types of memory which is divided
into RAM (random access memory) which is Volatile
memory, and ROM (read-only memory)and Flash
memory which are Non-Volatile
 RAM
 ROM
 Flash memory
 Memory types:

 RAM(Random Access Memory):


○ SRAM(Static RAM):
 Very expensive
 Very high performance
 Constructed of Flip-Flops
 RAM(Random Access Memory):
○ DRAM(Dynamic RAM):
 Cheap
 Constructed from Capacitors so it needs
to be refreshed periodically.
 It is divided into:
 SDRAM(Synchronous DRAM)
- SDR-SDRAM(Single Data Rate)
- DDR-SDRAM(Double Data Rate)
○ DDR-SDRAM has better performance and faster
than the SDR-SDRAM and it is commonly used now
in our computer
 ROM(Read Only Memory):

ROM(ROM)
PROM(Programmable ROM).
EPROM (Erasable PROM by UV
light).
EEPROM(Electrically Erasable
PROM).
 Flash Memory:
○ It is non-volatile computer memory that
can be electrically erased and
reprogrammed. It is a technology that is
primarily used in memory cards and USB
flash drives for general storage and
transfer of data between computers and
other digital products. It is a specific type
of EEPROM (Electrically Erasable
Programmable Read-Only Memory) that is
erased and programmed in large blocks (it
is faster than EEPROM)
 I/O: Input/output ports
 Parallel input/output ports are mainly used to
drive/interface various devices such as LCD’S,
LED’S, printers, memories, etc to a microcontroller
 T/C: Timers/counters
 The timers and counters provide all timing and counting
functions inside the microcontroller. The major operations
of this section are performed clock functions,
modulations, pulse generations, frequency measuring,
making oscillations, etc. This also can be used for
counting external pulses. A microcontroller may have
more than one timer and counters.
 Parallel ports
 provide various serial interfaces between a
microcontroller and other peripherals like
parallel ports

 interrupts sources
 Interrupts are the events that temporarily suspend
the main program and are provided by interrupts
sources
 PWM function block
 Is a built-in timer that can be used to generate
a PWM signal.

Pulse width modulation


 A/D: analog to digital converter
 are used for converting the analog signal to digital
form. The input signal in this converter should be in
analog form (e.g. sensor output) and the output from
this unit is in digital form. The digital output can be
used for various digital applications (e.g. measurement
devices)

 D/A: digital to analog converter


 perform reversal operation of ADC conversion
AVR Architecture
 RISC (reduced instruction set computer) modified Harvard architecture:
The purpose of this architecture is to shorten the runtime by reducing the
set of commands on the computer. The use of RISC architecture also made it
possible to program in high-level languages such as C and BASIC
• Scalable
Same powerful AVR core in all devices
• Single cycle execution
One instruction per external clock
• 32 Working Registers
All Directly connected to ALU!
• Very efficient core
Low power consumption
• High System Level Integration
Lowest total system cost
AVR
microcontroller
Architecture
AVR Harvard Architecture
 Buses: there are separate buses for the code and
control and data memory
 the address bus allows the CPU to send the address to
other components such as (RAM, I/P devices)
 The data bus carries the data between CPU and other
components. (unidirectional)
 the control bus is the communication between address
bus and data bus
ATmega16
 Pin description:
 4 ports A,B,C,D each has 8 pins.
 RESET input. A low level on this pin
for longer than the minimum pulse
length will generate a reset.
 XTAL1 Input to the inverting
Oscillator amplifier and input to the
internal clock operating circuit.
 XTAL2 Output from the inverting
Oscillator amplifier.
 AVCC is the supply voltage pin for
Port A and the A/D Converter. It
should be externally connected to
VCC.
 AREF is the analog reference pin for
the A/D Converter.
Atmega 32/16 features
 4 input/output ports
 T/C0 , T/C2 which are 8 bit and T/C1 is 16 bit
 Parallel ports or Serial interface (TXD, RXD)
 Interrupts T/C, A/D ;any function has its own interrupts
 2 PMM generators OC1a, OC1b
 8 A/D converter pins (bits) and AREF, AGND, AVCC

to omit the noise


Atmega 32/16 Clock sources
 AVR clock sources can be either:
 Internal Clock distribution

 External
A clock used by related fuse bits

 Internal clock sources


 Internal calibrated oscillator with the
frequency of 1, 2,4, 8 MHz which the
microcontroller as a default has the
frequency of 1MHz
Atmega 32/16 Clock sources

 external clock signal (22 MHz)

NC Extal 2

Extal1
Atmega 32/16 Clock sources

 external RC oscillator

min(C )  22 pF NC
Extal 2

1
f  Extal1
3RC
Atmega 32/16 Clock sources

 external crystal oscillator with frequency of which


is determined by quartz crystal (16 MHz)

30 pF
Extal 2

Extal1
30 pF

quartz crystal
 external crystal oscillator with frequency of
which is determined by quartz crystal (32.768
kHz)
ATmega16 Memories

 In-System Reprogrammable Flash


Program Memory

 The ATmega16 contains 16K bytes On-chip In-


System Reprogrammable Flash memory for
program storage.
 The Flash memory has an endurance of at least
10,000 write/erase cycles. The ATmega16
Program Counter (PC) is 13 bits wide.
ATmega16 Memories

 SRAM Data Memory

 Is divided to 3 section.1120 Data


Memory locations address the Register
File, the I/O Memory, and the internal
data SRAM. The first 96 locations
address the Register File (32) and I/O
Memory (64), and the next 1024
locations address the internal data
SRAM.
ATmega16 Memories

 EEPROM Data Memory


 The ATmega16 contains 512 bytes of data
EEPROM memory. It is organized as a separate
data space, in which single bytes can be read
and written. The EEPROM has an endurance of
at least 100,000 write/erase cycles.
ATmega16 reset sources
 Power-on Reset - The microcontroller is reset when the
supply voltage is less than the Power-on Reset threshold.

 External Reset - The microcontroller is reset when the


RESET pin (the pin number 9) is grounded

 Watchdog System Reset - The microcontroller is reset


when the Watchdog Timer period expires and the Watchdog
System Reset mode is enabled.
Watch dog timer are used to facilitate automatic correction of
hardware faults, and to prevent errant or malevolent software.
During normal operation, the computer regularly restarts the
watchdog timer to prevent it from elapsing, or "timing out“

 Brown-out Reset - The microcontroller is reset when the


supply voltage VCC is less than the Brown-out Reset.
C language review

 C is a middle- level programming language which can be used


for programming of AVR microcontrollers
Some of the advantages of c language to the assembly:
 C syntax is a lot easier to learn than Assembler syntax.
 C is easier to use for making more complex programs.
 C Is a lot more flexible and portable meaning that by small
changes in the program of particular AVR you can use that
program for another one, it means that the architecture of
the AVR don’t needed for programming while assembly
instruction depends on the processor architecture.
 Availability of library and functions
Advantage of assembly to c language is that, in using particular
instruction, assembly codes volume is lower than the c language
C language review

 Basic syntax of c language

 first rule involves the use of the semicolon ";". Every


command in C must end with a semi-colon except the
statements which starts with #.
a  a  b;
 Comments are like helping text in your C program and
they are ignored by the compiler. They start with /* and
terminate with the characters */ as shown below :
/* my first program in C */ or //
C language review

 It is possible to write more than one statement in one


line of a program, for Ex:

a  a  b; , a  a  b;

 The program which starts with curly braces ‘{‘ , it must


be enclosed with in that too, for Ex:

switch (var) {
case 1:
doThing1();
break; case 2:
doThing2();
break; }
C language review

 Each variable must be determined before using that


 For determining of the variables, letters, numbers and
also symbols like underline can be used.
 Numerical variables can be determined by these three
ways:
x  225; //Decimal

x  0b 11111111; //Binary

x  0 xFF ; //Hexadecimal
C language review
 C program basics
C language review
 A sample program
C Review:

 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
C Review:

 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
C Review:
 Global and Local variables
 Global variables:
 The variables declared outside any function are called global
variables. They are not limited to any function. Any function
can access and modify global variables. Global variables are
generally written before main() function.
 Local variables:
 The variables which are declared inside the function,
compound statement (or block) are called Local variables. is
one that occurs within a specific scope. They exist only in the
function where they are created.
 An example for local variables
C Review:
 Storage class variables

 Static variables can be global or local


e.g. static int n=1;
SRAM classes
 Extern variables are global
 e.g. extern int a;

 Const or flash variables: data will be constant and put in read only
memory like flash
e.g. const int var=1; or flash float pi=3.14

 this command is used for declaring the address of stored data in SRAM
e.g. int y@0x80; storing y in 80H address
C Review:
 Arrays:
 Char arreyName=[arreySize];
 Char arr1=[5];
 Char arreyName[arreySize]={arreyLegend};
 Char arr1[5]={1,2,3,4,5};
or char arr1[5];
arr1[0]=1; arr1[1]=2; arr1[2]=3; arr1[3]=4; arr1[4]=5;
 from arr1[0] to arr1[4]
 arr1[4]=5;
 Indexed by integer.
 Tow dimensional array x[3][4];
 Unsigned char highschool [2][3];
 Unsigned char highschool [2][3]={12,15,9}, {10,11,8};
C Review:

 Operators:
 Arithmetic operators
 ( x+y ,- , *, /, %)
 Increment/decrement operator ++ , --
 Increment operator: increases integer value by one
 decrement operator: decreases integer value by one

 Relation operators
 Equal operator (==)
 Less than (<) … less than or equal (<=)
 Greater than (>) … greater than or equal (>=)
 Not equal (!=)
C Review:
 Operators:
 Logical operators:
 And (&&)
 Or (||)
 Not (!)
 Bitwise operators
 Bitwise AND (&)
 Bitwise OR(|)
 Bitwise XOR(^)
 Complement (~)
 Right shifted (>>) a = 0001000 b = 2
 Left shifted (<<) a << b = 0100000
a >> b = 0000010
C Review:
 Assignment operator (= , +=, -=, /=, *=, %=)
C Review:
Preprocessors:
 #include: Inserts a particular header from another file.

 Include Files: “according to Codevision”

 AVR header files e.g. (mega8535.h, mega16.h,mega32.h tiny22.h,…etc.)


e.g. #include <mega16.h>
 C header files e.g. (math.h, string.h, stdlib.h, stdio.h,...etc.)
e.g.

 Other useful header files e.g. (delay.h, lcd.h, spi.h, I2C.h, gray.h,…etc.)

 other files that are added by programmer

e.g. #include "myheader.h"


C Review:

 #define: Substitutes a preprocessor macro.

e.g. #define data_port PORTA


 replaces instances of data_port with PORTA or the PORTA
renamed by data_port

 #undef: Undefines a preprocessor macro.

#define FILE_SIZE 42
e.g. #undef FILE_SIZE

 undefines existing FILE_SIZE and define it as 42.


C Review:

 C in functions
 Loops in c language
 for

 while

 Do while
 Conditional statements
 if

 Else if
 Switch case
C Review:
 The For statement
For(initial; condition ; increment) If there are no braces, the next
statement is the only statement
{
under the for statement
Do whatever here…
}

for (count = 0; count < 1000; count += 5)

count = 1;
for (x=5 ; count < 1000; count++)

for (count = 0; count < 100; )


{count++;}

for (i = 0, j = 999; i < 1000; i++, j--)


b[j] = a[i];
C Review: e.g.1
 While statement
While(condition) while(1){
PORTA=-PORTA;
{
delay_ms(400);
Do whatever here… }
}

e.g.2
Do
{ while(i<10){
PORTA=-PORTA;
}while(condition);
delay_ms(400);
i++
}

 If we write the number 1 inside (condition), we


have basically created an infinite unconditional
loop, and the only way out of it is to use the
break command
C Review:
 If Statement:
if(condition is true) If there are no braces the next
{ statement is the only statement
under the condition
Do whatever here…
}
Else if (another condition is true)
{
Do whatever here…
}
:
.
Else
{
Do a default operation
}
C Review:
 Switch case statement switch (expression)
​{
case constant1:
//statements
break;

case constant2:
// statements
break;
.
.
.

default:
// default statements
}
C Review:
 Goto statement
 goto is a jumping statement in c language, which
transfer the program’s control from one statement to
another statement (where label is defined)
: (colon) should be used after the label_name
 label_name:
 goto lable_name;

e.g.

label-name:
statement1;
statement2;
.
.
if(any-test-condition)
goto label-name;
C Review:

 C functions
 Function general form declaration.
Parameter list

Return-type function-name( type1 parameter 1, type2 parameter2)


{
Body of the function(arguments or the inputs)
}

 A function may return a value. The return_type is the data type of the value
the function returns.
 Some functions perform the desired operations without returning a value. In
this case, the return_type is the keyword void.
 An example for c function:
C Review:
 Delay function
 delay_ms(): this function is used to give a delay in the code and it is
in terms of its input argument
 fist the preprocessors must be included:
#include< delay.h>

 void delay_ms (unsigned int)


 Ex: delay_ms(1000) //td=1000 ms

 Delay_us(): the given delay is in terms of its input arguments  s


and
 void delay_us (unsigned int) s
 Ex: delay_us (1000) //td=1000
ATmega16 I/O Ports

 Each of I/O ports have capability of (read, write modify)


 Each of the ports can be used as input or output,
independently
 Each pin maximum current is 20 mA
ATmega16 I/O Ports
 There are Three memory address locations for each
port:
1. Port data Register (PORTX register)
2. Data Direction Register (DDRX register)
3. Port Input Pins register (PINX register)
 The Port Input Pins I/O register is read only, while the
Data Register and the Data Direction Register are
read/write.
0 input
 The DDxn bit in the DDRx Register selects the direction
of this pin. If DDxn is written logic one, Pxn is
configured as an output pin. If DDxn is written logic output
zero, Pxn is configured as an input pin.
1
ATmega16 I/O Ports
 If PORTxn is written a logic one when the pin is configured as
an input pin, the pull-up resistor is activated. To switch the
pull-up resistor off, PORTxn has to be written logic zero or
the pin has to be configured as an output pin.

 If PORTxn is written a logic one when the pin is configured as


an output pin, the port pin has initial state one or is driven
high. If PORTxn is written a logic zero when the pin is
configured as an output pin, the port pin has initial state
zero or is driven low.

 Reading the Pin Value: Independent of the setting of Data


Direction bit DDxn, the port pin can be read through the
PINxn Register bit.
ATmega16 I/O Ports
 Register Description for I/O-Ports:
 Port A Data Register – PORTA

 Port A Data Direction Register - DDRA

 Port A Input Pins Address – PINA


ATmega16 I/O Ports problems:

 I/O ports registers are bit-addressable registers. in


codevision you can use this feature…
 If you want to get the second bit in the register DDRA you simply
say DDRA.1 .

 Ex: Write a program to read the data of port D and put it in port B

#include<mega16.h>
void main (void) {
DDRD=0X00;
PORTD=0XFF;
while(1){
PORTB=PIND;
}
}
ATmega16 I/O Ports problems:

 EX: Program atmega16 to complement the contents of


port B every 0.5 seconds.

#include<mega16.h>
#include<delay.h>
void main (void) {
DDRB=0XFF;
PORTB=0X00;
while(1){
PORTB~= PORTB;
delay_ms(500)
}
}
ATmega16 I/O Ports problems:
 EX: Program atmega16 to read number on port A and save it to port B if the
number is 5.
#include<mega16.h>
#include<delay.h>
unsigned char a;
void main (void) {
DDRA=0X00;
PORTA=0XFF;
DDRB=0XFF;
while(1) {
a=PINA;
if (a==5) {
PORTB=PINA;
delay_ms(1000)
}
}
}
ATmega16 I/O Ports problems:
 EX: Write a function to read the first bit of port D and if it is one,
turn on the second bit of port D for 1s

#include<mega16.h>
#include<delay.h>
void Blink (void) {
if (PIND.0 ==1) {  Note: in if command, it is
PIND.1=1; possible to check one pin of
a port but reading the whole
delay_ms(1000);
port is impossible
PIND.1=0;
}
}
void main (void) {
DDRD.0=0;
DDRD.1=1;
while(1) {
Blink();
}
}
LCD
 LCDs are used for displaying status or parameters
in embedded systems meaning that they used to
show a program's printed output. LCDs using
related chips and codes interface microcontrollers
and converts the received data's to the characters
or letters that have in their memory
 LCD types:
1. alphanumeric LCD: they display numbers,
letters( A-Z and a-z ) and some other
characters that they have stored in their
memories
2. graphic LCD : they also display images.
The alphanumeric LCDs are divided in terms of row and
column as: 16  1 , 16  2 , 40  4 , for example 16  2
means that LCD has 16 column and 2 row
LCD
 LCD 16  2 is a 16 pin device which has 8 data pins (D0-D7) and
3 control pins (RS,RW,E). The remaining 5 pins are for supply
and backlight for the LCD

LCD

15 16
A K
LCD
 Vss: Ground pin
 Vdd: Supply pin
 Vee: Contrast regulation pin; contrast of data on LCD is done by
connecting the variable side of potentiometer to pin 3 of LCD and
connecting 2 other side of that to supply and ground, and
varying potentiometer
 RS: Register selection pin (either data or command)
RS=0:command register, RS=1:data register
 RW: Selects read or write operation. RW=0: for write, RW=1:for
read
 E: Enable pin: makes enable pin from high to low; by changing
the pulse level from one to zero, data and commands placed in
D0 -D7 enters to LCD
 D0-D7: when E=0, , data and commands are put in D0-D7
 A: anode: the light of background of LCD
 K: cathode: the light of background of LCD
LCD
 Interfacing modes of LCD with a micro controller
 16×2 LCD can be interfaced with a microcontroller in 8 Bit
or 4 Bit mode. In 8 Bit mode, character data and LCD
command are sent through the data lines D0 to D7. That is 8
bit data is send at a time and data strobe is given through E
of the LCD.
 But 4 Bit mode uses only 4 data lines D4 to D7. In this 8 bit
data is divided into two parts and are sent sequentially
through the data lines. The idea of 4 bit communication is
introduced to save pins of microcontroller. 4 bit
communication is bit slower than 8 bit but this speed
difference has no significance as LCDs are slow speed
devices. Thus 4 bit mode data transfer is most commonly
used.
LCD
 alphanumeric LCD and AVR interface
 4 Bit mode

 To interface LCD with microcontroller in codevision compiler in


codewizard setting some parameters like the port name and
LCD columns number can be selected

LCD port C Lines/Chars 16


LCD
 alphanumeric LCD and AVR interface: the pins of LCD must be
connected according following table which is defied in
codevision as a defult for one the microcontroller ports

LCD

15 16
A K

Port Bit 0 E LCD Pin 6


Port Bit 1 RS LCD Pin 4
Port Bit 2 RW LCD Pin 5
Port Bit 3 N.C
Port Bit 4 D4 LCD Pin 11
Port Bit 5 D5 LCD Pin 12
Port Bit 6 D6 LCD Pin 13
Port Bit 7 D7 LCD Pin 14
LCD
 Note that to interface LCD to microcontroller all 8 pins of a
microcontroller port (A /B/C/D) will be assigned to LCD pins. And
the connected port of microcontroller (if we don’t use codewizard
options for selecting the specification section for the port) will be
defined by the program in assembly language as follows:

connected port related progarm


LCD
 Also for to declare the number of the columns of LCD,
following code is used the number inside the () is determining
the column number of LCD, for example for LCD 2*16 the
number of columns is 16 then we will have:
lcd_init(16);

 LCD memories:
 ROM: include the ascci codes of characters, numbers, and
English letters that by declaring each of them to LCD, the
intended phrase will be displayed
 DROM: it is volatile memory for displaying the data
 RAM: it is 64 bit memory that can sore new characters
LCD
 LCD functions:
 LCD functions are in the library <lcd.h> that with wizard setting
they are added to the program #include <lcd.h>
1. LCD is waiting for the data
lcd_ready();
void lcd_ready(void)
2. To initialize the lcd

EX
lcd_init() lcd_init(16)
Void lcd_init(unsigned int)

3. To clear the LCD screen

lcd_clear()
void lcd_clear(void)
LCD
4. To Set the position of the cursor for subsequent text entry
Lcd_gotoxy(x,y)
void lcd_gotoxy(unsigned int x, unsigned int y) lcd_goto xy(5,0)
column row Sixth column and first row

5. To write a single character of data to the LCD display


lcd_putchar() EX lcd_putchar(‘A’)
6.To print string of data, stored SRAM memory, to the LCD display
lcd_puts()
7. To print string of data, stored in FLASH memory, to the LCD display
lcd_putsf() EX lcd_putsf(“Micro”)

 BY using the character “ ”, the equivalent ascci code is sent to LCD


LCD

 in C the character values are stored as ascii values. to convert int to ascii we
can add the ascii of character “ ” with the integer. In numeral variables ,
the value of variable must be converted to its ascci code. In following
example, to print the variable of value, in which the ambient temperature
has been saved, the convert commands to ascci must be used

 itoa to convert the int number to ascci code


This fuction is in
 ltoa to convert long int number to ascci code standard library
<stdlib.h>

Ex: itoa(value , value1)


lcd_putsf(value1) the content/amount of value is printed
lcd_putsf(“value”) the phrase –value- is printed
LCD
 Write a program to print ‘Micro’ every one second on LCD display

.equ_lcd_port=0x15; PORTC

void main(void)

lcd_ready();
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(“Micro”);
delay_ms(1000);
}
}

You might also like