flow chart programming

63
FLOW CHART PROGRAMMING FOR AVR MICROCONTROLLERS USING FLOWCODE PREPARED BY: TIRSO LLANTADA, ECE

Upload: tearsome-llantada

Post on 24-May-2015

3.295 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Flow chart programming

FLOW CHART PROGRAMMINGFOR AVR MICROCONTROLLERSUSING FLOWCODEPREPARED BY: TIRSO LLANTADA, ECE

Page 2: Flow chart programming

TOPIC TO BE DISCUSSED

• MICROCONTROLLERS

• AVR MICROCONTROLLERS

• FLOW CHART

• FLOWCODE

Page 3: Flow chart programming

MICROCONTROLLERS

Page 4: Flow chart programming

General Purpose

Microprocessor

RAM ROM TimerSerialCOMPort

IO Port

Data BUS

Address BUS

Control BUS

CPU RAM ROM

I/OTimerSerialPort

• General Purpose Microprocessors

• Microcontrollers

Page 5: Flow chart programming

EMBEDDED SYSTEMS

Page 6: Flow chart programming

EMBEDDED SYSTEMS

Page 7: Flow chart programming

COMMON MICROCONTROLLERS

Page 8: Flow chart programming

MICROCONTROLLER ARCHITECTURE

Page 9: Flow chart programming

TOPIC TO BE DISCUSSED

• MICROCONTROLLERS

• AVR MICROCONTROLLERS

• FLOW CHART

• FLOWCODE

Page 10: Flow chart programming

AVR MICROCONTROLLERS

• The acronym AVR has been reported to stand for: Advanced Virtual RISC and also for the chip's designers: Alf-Egil Bogen and Vegard Wollan who designed the basic architecture at the Norwegian Institute of Technology.

• RISC stands for reduced instruction set computer.

CPU design with a reduced instruction set as well as a simpler set of instructions (like for example PIC and AVR)

Page 11: Flow chart programming

A LITTLE HISTORY

• The PIC (Programmable Interrupt Controller) appeared around 1980.

→ 8 bit bus

→ executes 1 instruction in 4 clk cycles

→ Harvard architecture

• AVR (1994)

→ 8 bit bus

→ one instruction per cycle

→ Harvard architecture

Page 12: Flow chart programming

AVR INTERNAL ARCHITECTURE

PROGRAM ROM

PortsOSC

CPU

Timers

OtherPeripherals

ProgramBus Bus

RAM

I/O PINS

EEPROM

Interrupt Unit

Page 13: Flow chart programming

AVR DIFFERENT GROUPS

• Classic AVR

• e.g. AT90S2313, AT90S4433

• Mega

• e.g. ATmega8, ATmega32, ATmega128

• Tiny

• e.g. ATtiny13, ATtiny25

• Special Purpose AVR

• e.g. AT90PWM216,AT90USB1287

Page 14: Flow chart programming

LET’S GET FAMILIAR WITH THE AVR PART NUMBERS

ATmega128

ATtiny44

Atmel group Flash =128K

AtmelFlash =4K

AT90S4433

Atmel Classic group

Flash =4KTiny group

Page 15: Flow chart programming

AVR’S CPU

• AVR’s CPU

• ALU

• 32 General Purpose registers (R0 to R31)

• PC register

• Instruction decoder CPUPC

ALU

registers

R1

R0

R15

R2

R16

R17

R30

R31

Instruction Register

Instruction decoder

SREG: I T H S V N CZ

Page 16: Flow chart programming

TOPIC TO BE DISCUSSED

• MICROCONTROLLERS

• AVR MICROCONTROLLERS

• FLOW CHART

• FLOWCODE

Page 17: Flow chart programming

FLOWCHART

• A flowchart is a diagram that depicts the “flow” of a program.

START

Display message “How many hours did you work?”

Read Hours

Display message “How much do you get paid per hour?”

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

Page 18: Flow chart programming

ALGORITHMS AND FLOWCHARTS

• A typical programming task can be divided into two phases:

• Problem solving phase

• produce an ordered sequence of steps that describe solution of problem

• this sequence of steps is called an ALGORITHM

• Implementation phase

• implement the program in some programming language

Page 19: Flow chart programming

Rounded Rectangle

Parallelogram

Rectangle

Rounded Rectangle

START

Display message “How many hours did you work?”

Read Hours

Display message “How much do you get paid per hour?”

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross Pay.

Display Gross Pay

END

BASIC FLOWCHART SYMBOLS

Page 20: Flow chart programming

BASIC FLOWCHART SYMBOLS

• Terminals

• represented by rounded rectangles

• indicate a starting or ending point

Terminal

START

ENDTerminal

START

Display message “How many hours did you work?”

Read Hours

Display message “How much do you get paid per

hour?”

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross

Pay.

Display Gross Pay

END

Page 21: Flow chart programming

BASIC FLOWCHART SYMBOLS

• Input/Output Operations

• represented by parallelograms

• indicate an input or output operation

Display message “How many

hours did you work?”

Read Hours

Input/Output Operation

START

Display message “How many hours did you work?”

Read Hours

Display message “How much do you get paid per

hour?”

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross

Pay.

Display Gross Pay

END

Page 22: Flow chart programming

BASIC FLOWCHART SYMBOLS

• Processes

• represented by rectangles

• indicates a process such as a mathematical computation or variable assignment

Multiply Hours by Pay Rate. Store

result in Gross Pay.

Process

START

Display message “How many hours did you work?”

Read Hours

Display message “How much do you get paid per

hour?”

Read Pay Rate

Multiply Hours by Pay Rate. Store result in Gross

Pay.

Display Gross Pay

END

Page 23: Flow chart programming

FOUR FLOWCHART STRUCTURES

• Sequence

• Decision

• Repetition

• Case

Page 24: Flow chart programming

SEQUENCE STRUCTURE

• a series of actions are performed in sequence

• The pay-calculating example was a sequence flowchart.

Page 25: Flow chart programming

DECISION STRUCTURE

• One of two possible actions is taken, depending on a condition.

Page 26: Flow chart programming

DECISION STRUCTURE

• A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path

YESNO

Page 27: Flow chart programming

DECISION STRUCTURE

• In the flowchart segment below, the question “is x < y?” is asked. If the answer is no, then process A is performed. If the answer is yes, then process B is performed.

YESNOx < y?

Process BProcess A

Page 28: Flow chart programming

DECISION STRUCTURE

• The flowchart segment below shows how a decision structure is expressed in C++ as an if/else statement.

YESNOx < y?

Calculate a as x times 2.

Calculate a as x plus y.

if (x < y)

a = x * 2;

else

a = x + y;

Flowchart C++ Code

Page 29: Flow chart programming

DECISION STRUCTURE

• The flowchart segment below shows a decision structure with only one action to perform. It is expressed as an if statement in C++ code.

if (x < y)

a = x * 2;

Flowchart C++ Code

YESNOx < y?

Calculate a as x times 2.

Page 30: Flow chart programming

REPETITION STRUCTURE

• A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop.

Page 31: Flow chart programming

REPETITION STRUCTURE

• Notice the use of the diamond symbol. A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists.

Page 32: Flow chart programming

REPETITION STRUCTURE

• In the flowchart segment, the question “is x < y?” is asked. If the answer is yes, then Process A is performed. The question “is x < y?” is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited.

x < y?

Process A

YES

Page 33: Flow chart programming

REPETITION STRUCTURE

• The flowchart segment below shows a repetition structure expressed in C++ as a while loop.

while (x < y)

x++;

FlowchartC++ Code

x < y?

Add 1 to x

YES

Page 34: Flow chart programming

CONTROLLING A REPETITION STRUCTURE

• The action performed by a repetition structure must eventually cause the loop to terminate. Otherwise, an infinite loop is created.

• In this flowchart segment, x is never changed. Once the loop starts, it will never end.

• QUESTION: How can thisflowchart be modified soit is no longer an infiniteloop?

x < y? Display x

YES

Page 35: Flow chart programming

CONTROLLING A REPETITION STRUCTURE

• ANSWER: By adding an action within the repetition that changes the value of x.

x < y? Display x

Add 1 to x

YES

Page 36: Flow chart programming

A PRE-TEST REPETITION STRUCTURE

• This type of structure is known as a pre-test repetition structure. The condition is tested BEFORE any actions are performed.

x < y? Display x

Add 1 to x

YES

Page 37: Flow chart programming

A PRE-TEST REPETITION STRUCTURE

• In a pre-test repetition structure, if the condition does not exist, the loop will never begin.

x < y? Display x

Add 1 to x

YES

Page 38: Flow chart programming

A POST-TEST REPETITION STRUCTURE

• This flowchart segment shows a post-testrepetition structure.

• The condition is tested AFTER the actionsare performed.

• A post-test repetition structure alwaysperforms its actions at least once.

Display x

Add 1 to x

YESx < y?

Page 39: Flow chart programming

A POST-TEST REPETITION STRUCTURE

• The flowchart segment below shows a post-test repetition structure expressed in C++ as a do-while loop.

do{

cout << x << endl;x++;

} while (x < y);

Flowchart

C++ Code

Display x

Add 1 to x

YESx < y?

Page 40: Flow chart programming

CASE STRUCTURE

• One of several possible actions is taken, depending on the contents of a variable.

Page 41: Flow chart programming

CASE STRUCTURE

• The structure below indicates actions to perform depending on the value in years_employed.

CASEyears_employed

1 2 3 Other

bonus = 100

bonus = 200

bonus = 400

bonus = 800

Page 42: Flow chart programming

CASEyears_employed

1 2 3 Other

bonus = 100 bonus = 200 bonus = 400 bonus = 800

If years_employed = 1, bonus is set to 100

If years_employed = 2, bonus is set to 200

If years_employed = 3, bonus is set to 400

If years_employed is any other value, bonus is set to 800

CASE STRUCTURE

Page 43: Flow chart programming

CONNECTORS

• Sometimes a flowchart will not fit on one page.

• A connector (represented by a small circle) allows you to connect two flowchart segments.

A

Page 44: Flow chart programming

A

A

START

END

•The “A” connector indicates that the second flowchart segment begins where the first segment ends.

CONNECTORS

Page 45: Flow chart programming

MODULES

• A program module (such as a function in C++) is represented by a special symbol.

Page 46: Flow chart programming

•The position of the module symbol indicates the point the module is executed.

•A separate flowchart can be constructed for the module.

START

END

Read Input.

Call calc_pay function.

Display results.

MODULES

Page 47: Flow chart programming

COMBINING STRUCTURES

• Structures are commonly combined to create more complex algorithms.

• The flowchart segment below combines a decision structure with a sequence structure.

x < y? Display x

Add 1 to x

YES

Page 48: Flow chart programming

COMBINING STRUCTURES

• This flowchart segment shows two decision structures combined.

Display “x is within limits.”

Display “x is outside the

limits.”

YESNOx > min?

x < max?

YES NO

Display “x is outside the

limits.”

Page 49: Flow chart programming

EXAMPLE 1

• Draw flowchart to creates a table for the two-variable equation X =3Y by calculating and printing the value of X for each positive-integer value of Y.

Page 50: Flow chart programming

EXAMPLE 2

A program is required to read three numbers, add them together and print their total.

Input Processing Output

Number1Number2Number3

Read three numbersAdd number togetherPrint total number

total

Add numbers to total

ReadNumber1Number2number3

Print total

Start

Stop

Page 51: Flow chart programming

EXAMPLE 3

• A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, and calculate and display to the screen the average temperature, calculated by (maximum temperature + minimum temperature)/2.

Input Processing Output

Max_tempMin_temp

Prompt for temperaturesGet temperaturesCalculate average temperatureDisplay average temperature

Avg_temp

Page 52: Flow chart programming

EXAMPLE 4

• Design an algorithm that will prompt a terminal operator for three characters, accept those characters as input, sort them into ascending sequence and output them to the screen.

Input Processing Output

Char_1Char_2Char_3

Prompt for charactersAccept three charactersSort three charactersOutput three characters

Char_1Char_2Char_3

Page 53: Flow chart programming

EXAMPLE 5

• Design a program that will prompt for and receive 18 examination scores from a mathematics test, compute the class average, and display all the scores and the class average to the screen.

Input Processing Output

18 exam scores

Prompt the scoresGet scoresCompute class averageDisplay scoresDisplay class average

18 exam scoresClass_average

Page 54: Flow chart programming

Start

Total_score = zero

I = 1

Add scores(I) to

Total score

I = I + 1

Calculate average

I = I + 1

Prompt and get

Scores (I)

I = 1

I <= 18 ?

DisplayScores (I)

I <= 18 ?

Displayaverage

Stop

T

F

T

F

Page 55: Flow chart programming

FLOWCODE

• Flowcode is one of the World’s most advanced graphical programming languages for microcontrollers. The great advantage of Flowcode is that it allows those with little experience to create complex electronic systems. Flowcode is available in twenty languages and supports a wide range of devices. Separate versions are available for the PICmicro (8-bit), AVR/Arduino, dsPIC/PIC24 and ARM series of microcontrollers. Flowcode can be used with many microcontroller development hardware solutions including those from Matrix such as Formula Flowcode, E-blocks, MIAC and ECIO.

Page 56: Flow chart programming

ADVANTAGES

• Save time and money Flowcode facilitates the rapid design of electronic systems based of microcontrollers.

• Easy to use interface Simply drag and drop icons on-screen to create an electronic system without writing traditional code line

by line.

• Fast and flexible Flowcode has a host of high level component subroutines which means rapid system development. The

flowchart programming method allows to develop microcontroller programs.

• Error free results Flowcode works. What you design and simulate on-screen is the result you get when you download to your

microcontroller.

• Open architecture Flowcode allows you to view C and ASM code for all programs created and customise them. Access circuit

diagram equivalents to the system you design through our data sheets and support material.

• Fully supported Flowcode is supported by a wide range of materials and books for learning about, and developing, electronic

systems.

• Core-independent Flowcode programs developed for one microcontrollers easily transfer to another microcontroller.

Page 57: Flow chart programming

FEATURES

• Supported microcontrollers Microchip PIC 10, 12, 16, 18, dsPIC, PIC24, Atmel AVR/Arduino, Atmel ARM.

• Supported communication systems Bluetooth, CAN, FAT, GPS, GSM, I2C, IrDA, LIN, MIDI, One wire, RC5, RF, RFID, RS232, RS485, SPI, TCP/IP, USB, Wireless LAN, ZigBee

• Supported components ADC, LEDs, switches, keypads, LCDs, Graphical colour LCD, Graphical mono LCDs, Sensors, 7-segment displays, Internal EEPROM, comms systems, Touchscreen LCD, Webserver.

• Supported mechatronics Accelerometer, PWM, Servo, Stepper, Speech.

• Supported subsystems MIAC, MIAC expansion modules, Formula Flowcode.

• Panel designer Design a panel of your choice on-screen and simulate it.

• In-Circuit Debug (ICD) When used with EB006 PIC Multiprogrammer, EB064 dsPIC/PIC24 Multiprogrammer or FlowKit.

• Tight integration with E-blocks Each comms system is supported by E-blocks hardware.

• Virtual networks Co-simulation of many instances of Flowcode for multi-chip systems. Co-simulation of MIAC based systems with MIAC expansion modules.

Page 58: Flow chart programming

DESIGN PROCESS

DESIGN SIMULATE DOWNLOAD

Page 59: Flow chart programming

DESIGN

Page 60: Flow chart programming

SIMULATE

Page 61: Flow chart programming

DOWNLOAD

Page 62: Flow chart programming

DESIGN PROCESS

DESIGN SIMULATE DOWNLOAD

Page 63: Flow chart programming