36
1 CHAPTER 1 EMBEDDED SYSTEM 1.1 INTRODUCTION TO EMBEDDED SYSTEM Embedded System is a special purpose computer. It helps in infusing artificial intelligence into an electronic system. DEFINITION: Embedded System is a combination of Hardware and Software to meet specific needs in a given time frame. E.g.: Daily life embedded systems are cell phones, printers, ATM etc. Fig. 1.1 An Embedded System Suppose you have a bare processor , its bare so you can not dare to ask it save any result anywhere , thus you “added” a memory , let’s say “added” in a better term that “you embedded a memory ” that is your RAM.

training report on embedded system and AVR

Embed Size (px)

Citation preview

Page 1: training report on embedded system and AVR

1

CHAPTER 1

EMBEDDED SYSTEM

1.1 INTRODUCTION TO EMBEDDED SYSTEM

Embedded System is a special purpose computer. It helps in infusing artificial

intelligence into an electronic system.

DEFINITION:

Embedded System is a combination of Hardware and Software to meet specific needs

in a given time frame.

E.g.: Daily life embedded systems are cell phones, printers, ATM etc.

Fig. 1.1 An Embedded System

Suppose you have a bare processor , its bare so you can not dare to ask it save any

result anywhere , thus you “added” a memory , let’s say “added” in a better term that

“you embedded a memory ” that is your RAM.

Page 2: training report on embedded system and AVR

2

Now you want to forward this logic to real world , before adding some output pins

you need a register to bridge between RAM and output pins , this register do a

special function of forwarding logic 1 and 0 in a term of 5 and 0 volts , so that’s a

special function. So there you SFR and output PIN.

An embedded system is a system that has a software embedded into hardware, which

makes a system dedicated for an application or specific part of an application or

product or part of a larger system. It processes a fixed set of pre-programmed

instructions to control electromechanical equipment which may be a part of even

larger system (not a computer wid keyboard, display, etc.).

A general purpose definition of embedded system is that they are devices used to

control monitor or assist the operation of equipment, machinery or plant.

“Embedded” reflects the fact that they are an integral part of the system.

1.2 CHARACTERISTICS OF EMBEDDED SYSTEM

Modern embedded systems are based on microcontrollers. A

microcontroller is a small, low-cost computer-on-a-chip which usually

includes:

1. A microprocessor (CPU).

2. A small amount of RAM.

3. Programmable ROM and/or flash memory.

4. Parallel and/or serial I/O.

5. Timers and signal generators.

6. Analog to Digital (A/D) and/or Digital to Analog (D/A) conversion.

1.3 Why embedded system?

Take it as granted, that everything which runs on electric and does not have

motor, shall be a part of embedded.

Robotics is a major part of embedded, which concern hoe to interface

machinery with our software to perform a certain task

Though , definition of an embedded system says ‘A circuit which has been

programmed to perform a particular task’ , but it’s a human need to utilize a

Page 3: training report on embedded system and AVR

3

gadget (electronics) as much as it could do, here we come with general

purpose system (a system which can perform many task).This part has

software and efficient coding in main concern.

Embedded has booming future, this is predecessor of robotics, Al and various

human-machine interface.

Page 4: training report on embedded system and AVR

4

CHAPTER 2

EMBEDDED C

2.1 INTRODUCTION

Embedded c is a subset of c language which is compatible with certain

microcontrollers.

Some features are added using header files like <avr/io.h>, <util/delay.h>.

Scanf and printf are removed as the inputs are sanned from the sensors and

outputs are given to the ports.

Control structures remain the same like if-statement, for loop, do while etc.

2.2 STRUCTURE OF A C PROGRAM FOR AN EMBEDDED

SYSTEM

//Headers

#include<avr/io.h>//header file for avr i/o

#include<util/delay.h>//header file for delay

//main program

{

Int main ()

While(1)

{

code….

}

Return (0);

}

Page 5: training report on embedded system and AVR

5

2.3 STATEMENTS USED IN EMBEDDED C

2.3.1 If – statement

Syntax:

If(condition)

{

Statement……

}

Else

{

Statement……

}

Program for if statement

Int a=4;

Int b=5;

If(a>b)

Printf(“a is largest”);

Else

Printf(“b is largest”);

2.3.2 Do while loop

Syntax:

Initial counter

Do

{

statement…..

update statement

}

While (condition);

Page 6: training report on embedded system and AVR

6

Program for do while

Int A=4;

Do

{

A++;

}

While(A>5);

2.3.3 For – statement

Syntax:

For(initial counter; test condition; update statement)

{

Statement….

Statement….

}

Program for for-statement

For(int i=0;i<5;i++)

Printf(“hello sir’14”);

Page 7: training report on embedded system and AVR

7

CHAPTER 3

BASIC ELECTRONICS COMPONENTS

3.1 RESISTOR

A resistor is a two-terminal passive electronic component. It is that limits or

regulates the flow of electrical current, voltage and power dissipation in an electronic

circuit. Resistors can also be used to provide a specific voltage for an active device

such as transistor. Mainly resistor are classified according to their resistance values

and there power ratings. Resistances range from 10ohm to 56mohm (or more) and

power ratings from 1/8w to20

Units

The ohm (symbol: Ω). Commonly used multiples and submultiples in electrical and

electronic usage are the milliohm (1x10-3), kilohm (1x103), and megaohm (1x106).

Color coding

We can measure the resistance of a resistor. This is done by color coding over the

resistor you can use multi-meter to measure resistance. As a beginner you should use

color coding. Usually we can see that 4-band code, 5-band code and 6-band code

registers are available but we mainly get resistors of 4- band code.

Fig. 3.1 Resistor color coding

Page 8: training report on embedded system and AVR

8

3.3 Capacitor

A capacitor is used to store charge. Like resistors there is fixed as well as variable

capacitor also. But we mostly use fixed capacitor in robotics; variable capacitors are

mainly used in analog communication. These are capacitors with no polarity.

Ceramic and mica capacitors available are of no polarity, but electrolytic capacitors

are of polarity.

We can identify negative lead of electrolytic capacitor by checking the length of the

lead, one with less length s –ve. On the body of electrolytic capacitor –ve symbol is

shown. Be careful about electrolytic capacitor because inverting polarity can make

‘explosion’.

Every electrolytic has two factors- value of its capacitance and other maximum

voltagerating.

There are mainly two types of capacitors.

1. Electrolytic capacitor- they are used for low frequency, high capacity

applications and they are “polar” meaning that one leg must be connected to

negative and the other must be connected to positive supply. One of their use

is as low frequency filter in power supplies.

2. Ceramic capacitors- they are used in high frequency, low capacity

applications. One of their use in computers is for filtering high frequency

noise from the system.

C = Q / V

Page 9: training report on embedded system and AVR

9

Fig. 3.2 Capacitors

3.4 POWER SUPPLY

Fig. 3.3 Power supply circuit diagram

Operating Voltages

● 2.7 - 5.5V (ATmega8L)

● 4.5 - 5.5V (ATmega8)

Page 10: training report on embedded system and AVR

10

Power Consumption at 4 Mhz, 3V, 25°C

● Active: 3.6 mA

● Idle Mode: 1.0 mA

● Power-down Mode: 0.5 μA

3.4.1 BRIDGE RECTIFIERS

Bridge rectifier circuit consists of four diodes arranged in the form of a bridge as

shown in figure.

Operation:

During the positive half cycle of the input supply, the upper end A of the transformer

secondary becomes positive with respect to its lower point B. This makes Point1 of

bridge positive with respect to point2. The diode D1 & D2 become forward biased &

D3 & D4 become reverse biased. As a result a current starts flowing from point1,

through D1 the load & D2 to the negative end.

During negative half cycle, the point2 becomes positive with respect to point1.

DiodeD1 & D2 now become reverse biased. Thus a current flow from point 2 to point

1.

Page 11: training report on embedded system and AVR

11

CHAPTER 4

MICROCONTROLLER

4.1 INTRODUCTION

The situation we find ourselves today in the field of microcontrollers has its beginnings

in the development of technology of integrated circuits. It enabled us to store hundreds

of thousands of transistors into one chip, which was a precondition for the manufacture

of microprocessors. The first computers were made by adding external peripherals,

such as memory, input/output lines, timers and other circuits, to it. Further increasing

of package density resulted in designing an integrated circuit which contained both

processor and peripherals. This is how the first chip containing a microcomputer later

known as the microcontroller was developed.

4.2 CHARACTERISTICS OF MICROCONTROLLERS

• Microcontrollers are important part of Embedded systems

• To understand Structure & working of Microcontrollers

• For designing good embedded system complete understanding of

microcontrollers required.

• Integrated chip that typically contains integrated CPU, programmable

memory (RAM ROM), parallel and/or I/O ports on a single Chip.

• System on a single Chip.

• Designed to execute a specific task to control a single system.

• Smaller & specified (design cost).

• Differs from Microprocessor.

• General -purpose chip.

• Used to design multipurpose computers or devices.

Page 12: training report on embedded system and AVR

12

• Require multiple chips to handle various tasks.

• Timers and signal generators

• Analog to Digital (A/D) and/or Digital to Analog (D/A) conversion

4.3 DIFFERENCE BETWEEN MICROPROCESSOR AND

MICROCONTROLLER

MICROPROCESSOR MICROCONTROLLER

Microprocessor assimilates the function of a

central processing unit (CPU) on to a single

integrated circuit (IC).

Microcontroller can be considered as a

small computer which has a processor and

some other components in order to make it

a computer.

Microprocessors are mainly used in designing

general purpose systems from small to large

and complex systems like super computers.

Microcontrollers are used in automatically

controlled devices.

Microprocessors are basic components of

personal computers.

Microcontrollers are generally used in

embedded systems

Computational capacity of microprocessor is

very high. Hence can perform complex tasks.

Less computational capacity when

compared to microprocessors. Usually

used for simpler tasks.

Page 13: training report on embedded system and AVR

13

A microprocessor based system can perform

numerous tasks.

A microcontroller based system can

perform single or very few tasks.

Microprocessors have integrated Math

Coprocessor. Complex mathematical

calculations which involve floating point can

be performed with great ease.

Microcontrollers do not have math

coprocessors. They use software to

perform floating point calculations which

slows down the device.

The main task of microprocessor is to perform

the instruction cycle repeatedly. This includes

fetch, decode and execute.

In addition to performing the tasks of

fetch, decode and execute, a

microcontroller also controls its

environment based on the output of the

instruction cycle.

In order to build or design a system

(computer), a microprocessor has to be

connected externally to some other

components like Memory (RAM and ROM)

and Input / Output ports.

The IC of a microcontroller has memory

(both RAM and ROM) integrated on it

along with some other components like I /

O devices and timers.

Page 14: training report on embedded system and AVR

14

The overall cost of a system built using a

microprocessor is high. This is because of the

requirement of external components.

Cost of a system built using a

microcontroller is less as all the

components are readily available.

Generally power consumption and dissipation

is high because of the external devices. Hence

it requires external cooling system.

Power consumption is less.

Instruction throughput is given higher priority

than interrupt latency.

In contrast, microcontrollers are designed

to optimize interrupt latency.

Page 15: training report on embedded system and AVR

15

CHAPTER 5

AVR MICROCONTROLLER

5.1 INTRODUCTION

Fig. 5.1 AVR

AVR stands for Advanced Virtual RISC. The AVR is a modified Harvard

architecture 8-bit RISC single chip microcontroller which was developed

by Atmel in 1996. The AVR was one of the first microcontroller families to use on-

chip flash memory for program storage, as opposed to one-time programmable

ROM, EPROM, or EEPROM used by other microcontrollers at the time.

5.2 CLASSIFICATION OF AVR

AVRs are generally classified into following:

Tiny AVR — the A tiny series

0.5–16 kB program memory

6–32-pin package

Limited peripheral set

Page 16: training report on embedded system and AVR

16

Mega AVR — the A mega series

4–512 KB program memory

28–100-pin package

Extended instruction set (multiply instructions and instructions for handling

larger program memories)

Extensive peripheral set

XMEGA — the A xmega series

16–384 KB program memory

44–64–100-pin package (A4, A3, A1)

Extended performance features, such as DMA, "Event System", and

cryptography support.

Extensive peripheral set with ADCs.

Mostly instruction Execute in Single clock cycle. Which makes it faster among 8 bit

microcontrollers.

AVR was designed for efficient execution of compiled C code.

5.3ARCHITECTURE OF AVR

The AVR is a Harvard architecture CPU.

Harvard Architecture

• Computer architectures that used physically separate storage and signal

pathways for their instructions and data.

• CPU can read both an instruction and data from memory at the same time

that makes it faster.

Von Neumann architecture

CPU can Read an instruction or data from/to the memory.

Read, Write can`t occur at the same time due to same memory and signal pathway

for data and instructions.

Page 17: training report on embedded system and AVR

17

Fig. 5.2 Architecture of AVR

Connection of components with CPU within a Microcontroller is called a

BUS. There are three types of bus:

1. Address Bus: It specifies the address.

2. Data Bus: It reads and writes on a specific address.

3. Control Bus: it controls the actions by sending and receiving messages, thus

it is bidirectional.

Key of microcontroller:

1. Register: it is a temporary storage and is a part of RAM. There are two types

of registers- General Purpose Registers (GPR) and Specific Function Registers

(SFR).

GENERAL purpose

32 general purpose registers having storage capacity of 8 bit

Named as R0,R1,R2 to R31.

Register 0 to 15 & 16 to 31 are different.

Can store both Data & Addresses.

Page 18: training report on embedded system and AVR

18

SPECIAL purpose: Three registers

Program counter

Stack Pointer

Status Register

2. Program Counter: it contains the address of next instruction to be executed

by the CPU. It is also a register.

3. Accumulator: it is an intermediate register on which all Arithmetic and

Logical operations are performed.

4. Clock Signals: these are digital signals which synchronize the action of a

microcontroller.

5. Flash ROM: it is where the program code is stored. It is a fast erasing

technology and erases all the contents at a time.

6. Interrupt: The interrupts refer to a notification, communicated to the

controller, by a hardware device or software, on receipt of which controller

momentarily stops and responds to the interrupt.

7. Stack: stack is used for the execution of the program. Whenever an interrupt

occurs or a subroutine is called, the previous section of program is pushed

onto the stack. After execution of the interrupt or the subroutine the execution

is resumed from that part which was getting executed previously.

5.4 ATMEGA8

Fig. 5.3 Atmega8

Page 19: training report on embedded system and AVR

19

5.4.1 ATmega8 - RISC Architecture

● 130 Instructions – Most Single-clock Cycle Execution

● 32 x 8 General Purpose Working Registers

● 64 x 8 Special Function Registers (I/O Registers)

● Up to 16 MIPS Throughput at 16 MHz

● On-chip 2-cycle Multiplier

Nonvolatile Program and Data Memories

● 8K Bytes of In-System Self-Programmable Flash

10,000 Write/Erase Cycles

● Optional Boot Code Section with Independent Lock Bits

● 512 Bytes EEPROM (100,000 Write/Erase Cycles)

● 1K Byte Internal SRAM

● Programming Lock for Software Security

Peripheral Features

● Two 8-bit Timer/Counters

● One 16-bit Timer/Counter with Capture Mode

● Real Time Counter with Separate Oscillator

● Three PWM Channels

● 6-channel ADC with 10 resp 8 Bit resolution (TQFP: 8 channels)

● Two-wire Serial Interface (TWI)

● Programmable Serial USART

● Master/Slave SPI Serial Interface

● Programmable Watchdog Timer with On-chip Oscillator

● On-chip Analog Comparator

Special Microcontroller Features

● Programmable Brown-out Detection

● Internal Calibrated RC Oscillator

● External and Internal Interrupt Sources

Page 20: training report on embedded system and AVR

20

● Five Sleep Modes

I/O and Packages

● 23 Programmable I/O Lines

● 28-lead PDIP, 32-lead TQFP, and 32-pad MLF

Operating Voltages

● 2.7 - 5.5V (ATmega8L)

● 4.5 - 5.5V (ATmega8)

Speed Grades

● 0 - 8 MHz (ATmega8L)

● 0 - 16 MHz (ATmega8)

Power Consumption at 4 Mhz, 3V, 25°C

● Active: 3.6 mA

● Idle Mode: 1.0 mA

● Power-down Mode: 0.5 μA

Page 21: training report on embedded system and AVR

21

5.4.2 Pin and Port Overview:

Fig. 5.4 PDIP view of atmega8

Page 22: training report on embedded system and AVR

22

Fig. 5.5 TQFP top view of atmega8

GND: Ground (0V)

VCC: Digital Supply Voltage (2,7 – 5,5V)

AVCC: Analog Supply Voltage

connect to low-pass filtered VCC

AREF: Analog Reference Voltage, usually AVCC

/Reset: Low level on this pin will generate a reset

Port B, Port C, Port D:

General Purpose 8 Bit bidirectional I/O - Ports,

Optional internal pull up-resistors when configured as input

Output source capability: 20mA

Page 23: training report on embedded system and AVR

23

Special Functions of the Ports available as configured using the SFRs:

Port D: Uart, external Interrupts, Analog Comparator

Port B: External Oscillator/Crystal, SPI

Port C: A/D converters, TWI

5.4.3 ATMEGA 8 CORE ARCHITECTURE

Fig. 5.6 Core Architecture of atmega8

● Seperate Instruction and

Data Memories (Harvard)

● all 32 General Purpose

Registers connected to

ALU

Page 24: training report on embedded system and AVR

24

● I/O Modules connected to

Data Bus and accessible via

Special Function Registers

Fig. 5.7 Harvard Architecture of atmega8

● Separate storage and signal pathways for

instructions and data.

● History: Harvard Mark I

relay-based computer

● word width, timing, and implementation

technology of instruction and data memories

can differ.

● Contrast: ‘Von Neumann’ - architecture:

Instructions and data use the same signal

pathways and memory.

Page 25: training report on embedded system and AVR

25

Ability to fetch the next instruction at the

same time it completes the current

instruction.

● Speed is gained at the expense of more

complex electrical circuitry.

5.4.4 Memory organization:

Fig. 5.8 Memory Organization of Atmega8

Page 26: training report on embedded system and AVR

26

● Program Flash Memor y:

On-chip, in system programmable

8 Kbytes, organized in 4K 16 bit words

Program Counter (PC) = 12 bits

Accessible via special instructions: LPM, SPM

Boot Loader support: Boot Flash Section,

SPM can be executed only from Boot Flash

● EEPROM - Memory:

512 Bytes, single Bytes can be read and written

Special EEPROM read and write procedure using SFRs:

EEPROM Address Register, EEPROM Data Register,

EEPROM Control Register

C – Library Functions available

Precautions to prevent EEPROM memory corruption:

● No flash memory or interrupt operations

● Stable power supply

Page 27: training report on embedded system and AVR

27

CHAPTER 6

PROGRAMS

6.1 7-segment display

Fig. 6.1 7-Segment Display

A seven-segment display (SSD), or seven-segment indicator, is a form of

electronic display device for displaying decimal numerals that is an

alternative to the more complex dot matrix displays.

Seven-segment displays are widely used in digital clocks, electronic meters,

basic calculators, and other electronic devices that display numerical

information.

6.1.1 Introduction

The 7 segment display can also be used for displaying numbers. Each of the segments

of the display is connected to a pin on the 8051. In order to light up a segment on the

pin must be set to 0V. To turn a segment off the corresponding pin must be set to 5V.

Page 28: training report on embedded system and AVR

28

This is simply done by setting the pins on the 8051 to '1' or '0'. LED displays are

Power-hungry (10mA per LED) and Pin-hungry (8 pins per 7-seg display). But they

are cheaper than LCD display.

7-SEG Display is available in two types -1. Common anode & 2. Common

cathode, but command anode display is most suitable for interfacing with 8051 since

8051 port pins can sink current better than sourcing it.

Fig. 6.2 Types of 7-Segment Display

6.1.2 Creating Digit Pattern

In Common Anode display, the common Anode pin is tied to 5v .The cathode pins are

connected to port 1 through 330 Ohm resistance (current limiting). For displaying

Digit say 7 we need to light segments -a ,b, c. in Common anode display , to do so we

have to provide Logic -0 (0 v) at cathode of these segments. So need to clear pins-

P1.0 ,P1.1,P1.2. That is 1 1 1 1 1 0 0 0 -->F8h.

Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. b Seg. a HEX

0 1 1 0 0 0 0 0 0 C0

1 1 1 1 1 1 0 0 1 F9

2 1 0 1 0 0 1 0 0 A4

3 1 0 1 1 0 0 0 0 B0

4 1 0 0 1 1 0 0 1 99

Table 6.1: Hex Code for Displaying Various Digits

Page 29: training report on embedded system and AVR

29

6.1.3 Multi 7 Segment interfacing

Fig. 6.3 Interfacing Multi 7-Segment Display

Since we can Enable only one 7-seg display at a time ,we need to scan these

display at fast rate .the data lines are common for all the 4 segments The

scanning frequency should be high enough to be flicker-free. At least 30HZ

.Therefore – time one digit is ON is 1/30 seconds

Page 30: training report on embedded system and AVR

30

6.1.4 PROGRAM FOR INTERFACING OF 7 SEGMENT

DIPLAY WITH AVR MICROCONTROLLER

#include <avr/io.h>

#include <util/delay.h>

int main(void)

{

DDRA = 0xFF; // Configure port B as output

while(1)

{

//TODO:: application code

PORTA = 0b00110000; // Display Number 1

_delay_ms(1000); // Wait for 1s

PORTA = 0b01011011; // Display Number 2

_delay_ms(1000); // Wait for 1s

PORTA = 0b01001111; // Display Number 3

_delay_ms(1000); // Wait for 1s

PORTA = 0b01100110; // Display Number 4

_delay_ms(1000); // Wait for 1s

PORTA = 0b01110111; // Display Letter A

_delay_ms(1000); // Wait for 1s

PORTA = 0b00111001; // Display Letter C

_delay_ms(1000); // Wait for 1s

PORTA = 0b01111001; // Display Letter E

_delay_ms(1000); // Wait for 1s

PORTA = 0b01110001; // Display Letter F

_delay_ms(1000); // Wait for 1s

}

return 0;}

Page 31: training report on embedded system and AVR

31

Fig. 6.4 Simulated Circuit

6.2LCD

6.2.1 Introduction

A liquid-crystal display (LCD) is a flat panel display, electronic visual display, or video

display that uses the light modulating properties of Liquid crystals. Liquid crystals do not

emit light directly

A liquid-crystal display (LCD) is a flat panel display, electronic visual display, or video

display that uses the light modulating properties of Liquid crystals. Liquid crystals do not

emit light directly

Page 32: training report on embedded system and AVR

32

Fig. 6.5 LCD

A liquid crystal display, is a thin, flat panel used for electronically displaying

information such as text, images, and moving pictures. Its uses include monitors for

computers, televisions, instrument panels, and other devices ranging from aircraft

cockpit displays, to every-day consumer devices such as video players, gaming

devices, clocks, watches, calculators, and telephones. Among its major features are

its lightweight construction, its portability, and its ability to be produced in much

larger screen sizes than are practical for the construction of cathode ray tube (CRT)

display technology. Its low electrical power consumption enables it to be used in

battery-powered electronic equipment. It is an electronically-modulated optical

device made up of any number of pixels filled with liquid crystals and arrayed in

front of a light source (backlight) or reflector to produce images in color or

monochrome.

Page 33: training report on embedded system and AVR

33

6.2.2 Program of 16x2 LCD interfacing with AVR

microcontroller atmega8

#include <avr/io.h> void delay(unsigned char);

//Main Code

int main()

{

DDRB=0xff; //set PORTB as out put

DDRD=0b01110000; //Set PD.4,5 and 6 as Output

/*

RS=PD5

R/W=PD6

E=PD4 */

//Give Inital Delay for LCD to startup as LCD is a slower Device

delay(2);

init_lcd();

while(1)

{

lcd_cmd(0x80); //Goto Line-1,first position

lcd_send_string("WELCOME TO! ");

lcd_cmd(0xC0); //Goto Line-2, first position

lcd_send_string("EGLOB :) ");

lcd_cmd(0x01); //Clear the lcd

delay(1);

Page 34: training report on embedded system and AVR

34

}

}

//LCD function

/*------------------------------------------------------------------------------------------------------------*/

//Function for sending commands to LCD

void lcd_cmd(unsigned char command)

{

//Put command on the Data Bus

PORTB = command;

//Enable LCD for command writing

PORTD = 0b00010000;

//Allow delay for LCD to read the databus

delay(1);

//Disable LCD again

PORTD = 0b00000000;

//Allow some more delay

delay(1);

}

//Function for sending Data to LCD

void lcd_data(unsigned char data)

{

//Put data on Data Bus

PORTB= data;

//Set R/S (Regiter Select) to High, and Enable to High

PORTD = 0b00110000;

//Allow for delay

Page 35: training report on embedded system and AVR

35

delay(1);

//Disable LCD again

PORTD = 0b00100000;

//Allow for some more delay

delay(1);

}

//Function to send String to LCD

void lcd_send_string(char* string)

{

while(*string)

{

//Send value of pointer as data to LCD

lcd_data(*string);

//Increment string pointer

string++;

}

}

//Function to Initilise LCD

void init_lcd()

{

//Setup both lines of LCD

lcd_cmd(0x38);

//Set Cursor off - Enable LCD

lcd_cmd(0x0E);

//Clear Screen

lcd_cmd(0x01);

//Goto first position

lcd_cmd(0x80);

} /*----------------------------------------------------------------------------------------------------------*/

//Delay function

Page 36: training report on embedded system and AVR

36

void delay(unsigned char dtime)

{

int i,j;

for(i=0;i<=dtime;i++)

{

for(j=0;j<5000;j++);

}}

//You can use your own delay functions and replace this delay function with your code

/*-----------------------------------------------------------------------------------------------------------*/

Fig. 6.6 Simulated Circuit