Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Advertisements

Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Introduction to Micro-controllers Anurag Dwivedi.
Lab7: Introduction to Arduino
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
CS 106 Introduction to Computer Science I 09 / 25 / 2006 Instructor: Michael Eckmann.
ECE 353 WinAVR and C Debugging Tutorial By Adam Bailin ECE 353 Fall ‘06.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
Railway Foundation Electronic, Electrical and Processor Engineering.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
LAUNCHXL2-RM57L – Project 0
ECE Department: University of Massachusetts, Amherst Lab 1: Introduction to NIOS II Hardware Development.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Railway Foundation Electronic, Electrical and Processor Engineering.
An Embedded C Program 1 Mainly from textbook: Embedded C Programming and the Atmel AVR 2 nd Edition Barnett, Cox and O’Cull.
Dr. Amr Talaat. #include ; /* this makes the header file for the PIC16f877 ready to be used in the C-class */ #define LED PORTC ; /* defines.
Introduction to Microcontrollers Shivendu Bhushan Summer Camp ‘13.
Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
I/O Ports CS-280 Dr. Mark L. Hornick 1. CS-280 Dr. Mark L. Hornick 2 Ports are channels from the CPU to external hardware and software Atmega32 has: 4.
Lab 1 - Microcontrollers Complete the program template below being sure to select the correct parameters to meet the requirements (see the Microcontroller.
RM2D Let’s write our FIRST basic SPIN program!. The Labs that follow in this Module are designed to teach the following; Turn an LED on – assigning I/O.
Installing TinyOS Developing Environment Test Program: Blink.
Chapter 2 A Loop in the Pattern Designing the Main Loop and Timing.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
FIRST GADGETEER PROJECT. Where are you? Making a VS project Parts of a C# program Basics of C# syntax Debugging in VS Questions? 2.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
® IBM Software Group © 2006 IBM Corporation EGL/Web Project QuickStart – 2 of 4 – Creating the Business Logic Layer These slides walk you through the process.
AVR Programming: Interrupts September 17, What are interrupts? An asynchronous signal indicating the need for an event to be handled A synchronous.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
11 EENG 1920 Introduction to VHDL. 22 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
Microcontrollers, Microcomputers, and Microprocessors
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
An Introduction to Programming with C++1 Void Functions Tutorial 5.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Atmega328p Introduction for Digital and PWM Output Brion L Fuller II Robotics Club.
Copyright © 2007 by Pearson Education 1 UNIT 6A COMBINATIONAL CIRCUIT DESIGN WITH VHDL by Gregory L. Moss Click hyperlink below to select: Tutorial for.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Sitarambhai Naranjibhai Patel Institute of Technology and Research Centre, Umrakh, Bardoli. A Presentation On “ 16x2 LCD Interfacing with AVR atmega32.
An Introduction to Programming with C++1 An Introduction to Control Structures Tutorial 1.
Assembly Language with GCC
Making a 24hr Timer.
Programming and Debugging with the Dragon and JTAG
Embedded Systems Programming Examples and Comparison
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Microprocessor Systems Design I
Microprocessor Systems Design I
I/O Ports in AVR Sepehr Naimi
Tim Sumner, Imperial College, Rm: 1009, x47552
Assembly Language Programming II: C Compiler Calling Sequences
AVR Programming in C Chapter 7
AVR Programming in C Chapter 7
I/O Ports in AVR Sepehr Naimi
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Software Setup & Validation
Running a Java Program using Blue Jay.
An Introduction to Designing and Executing Workflows with Taverna
ECE 3567 Microcontrollers Lab
Presentation transcript:

Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating

Assignment Write the “ Chasing Lights Program ” in C Use Codevision AVR to compile the program and remove all syntax errors Simulate the program in AVR Studio, identify all logic errors  If logic errors are found, go back to Codevision AVR and make the necessary changes 2

LED Sequence 3 The leftmost LED should light (all others are off)

4 Then turn off the leftmost LED and turn on the next one to its right LED Sequence

5 Then shift the on LED to the right again LED Sequence

6 And again LED Sequence

7 And again

LED Sequence 8 And again

LED Sequence 9 And again

LED Sequence 10 And again

LED Sequence 11 Then start over at the leftmost LED (and continue forever)

First Program 12 Many inexperienced C programmers will write a program as shown Assuming a 1 is on and a 0 is off void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; } void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; }

First Program 13 Many inexperienced C programmers will write a program as shown Assuming a 1 is on and a 0 is off void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; } void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; } While this will work, there are better solutions This is what I call a “brute force” program – it is inelegant.

First Program 14 Many inexperienced C programmers will write a program as shown Assuming a 1 is on and a 0 is off void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; } void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; PORTB = 0b ; } While this will work, there are better solutions This is what I call a “brute force” program – it is inelegant. Let’s enter it in Codevision

Open Codevision 15 Open Codevision. It will only look like this IF you were not working on a program the last time you used it

Open New Project 16 Click on File -> New

Open New Project 17 Click on Project and then OK

Use Code Wizard 18 It is easiest to use the Code Wizard, so click yes.

Code Wizard 19 Here you can change the chip and the clock speed

Ports 20 You can also initialize the ports

Serial Ports, Interrupts, Timers 21 The Code Wizard also helps you setup: External Memory Interrupts Timers Serial Ports LCDs

Done? 22 When done, click on File -> Generate, Save, and Exit

Save Files 23 When done, click on File -> Generate, Save, and Exit It will ask you to save 3 files it will prompt you

New File 24 Finally, the new file will open (It doesn’t take long)

Unnecessary Code 25 But, there is a lot of unnecessary code: it initializes all the ports, interrupts, timers,etc according to the default parameters – but that code is not needed for this program

Template 26 You’ll be left with a template Place global variables here Local variables here And the program statements here

Enter the Program 27 Place the program here

Build All 28 Save everything And the choose Build All from the Project Menu

No Errors 29 Hopefully we’ll have no errors or warnings

The Debugger 30 So, its time to simulate Click on the ladybug This will call up AVR Studio

Open Project 31 Choose Open

*.cof & *_cof.aps files 32 Choose Open and then the *.cof and the _cof.aps files then click next

Simulator and ATMega Choose AVR simulator and the ATmega128

The AVR Simulator 34 This setup opens because it is the way I left AVR simulator the last time I exited – yours may look different. I click on I/O ATmega128 so that I can see PortB

I/O 35 PortB still has to be opened so that we can see the rest of Portb

PortB.7 36 With PortB open, PORTB, DDRB, and PINB are all visible Note also that F11 has been pressed so that the instruction that sets b7 in PORTB has executed (PORTB.7 = 1)

PortB.6 37 Now PORTB.6 = 1

PortB.5 38 Now PORTB.5 = 1

PortB Now PORTB.4 = 1 Now PORTB.3 = 1 Now PORTB.2 = 1 PORTB.1 = 1

PortB.0…..Glitch 40 Now PORTB.0 = 1, then something happens – it executes the while, and during that time PORTB.0 stays 1.

Arrays 41 So a new program was tried using an array and a “for” loop. But there was still a delay while the “while” and “for” statements were executing. One more program was tried void main(void) { char LEDs[8] = { 0b , 0b , 0b , 0b , 0b , 0b , 0b , 0b }; char i PORTB=0x00; DDRB=0xFF; while (1) { for (i=0; i<8; ++i) PORTB = LEDs[i]; }; } void main(void) { char LEDs[8] = { 0b , 0b , 0b , 0b , 0b , 0b , 0b , 0b }; char i PORTB=0x00; DDRB=0xFF; while (1) { for (i=0; i<8; ++i) PORTB = LEDs[i]; }; }

Shift Operator 42 This program worked very well – there was no difference in timing between one PORTB bit and the next, and especially between PORTB.0 and PORTB.7 char leds = 0b ; void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = leds; leds >>= 1; if (leds == 0) leds = 128; } char leds = 0b ; void main(void) { DDRB = 0xFF; // PortB is all outputs PORTB = 0x00; // turn off all the lights while(1) // do forever.. { PORTB = leds; leds >>= 1; if (leds == 0) leds = 128; }

Summary The “ Chasing Lights Program ” was written in C several times  Brute Force  Arrays  Shift Operator The shift operator proved to be the best  Discovered while simulating 43