labreport 3

13
Abu Dhabi University College of Engineering and Computer Science Microprocessors and Firmware Programming Lab Report 3 Author: Asyya Bassam ID: 1011916 Instructor: Dr. Mohammed Ghazal Lab Instructor: Eng. Ahmed Sweleh May 25, 2012

Upload: asyya410

Post on 20-Apr-2015

44 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LabReport 3

Abu Dhabi University

College of Engineering and ComputerScience

Microprocessors and Firmware Programming

Lab Report 3

Author:Asyya BassamID:1011916

Instructor:Dr. Mohammed Ghazal

Lab Instructor:Eng. Ahmed Sweleh

May 25, 2012

Page 2: LabReport 3

Contents

1 Introduction 1

2 Experiment Setup 1

3 List of Equipment Used 2

4 Procedure 24.1 First Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.2 Second Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34.3 Third Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

5 Results and Discussion 75.1 First Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75.2 Second Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75.3 Third Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

6 Conclusion 7

Abstract

This lab, open the door to us to learn how to create any system byapplying main steps. This lab is talking about the connection of led suchas link them with push buttons, or make them working automaticallyas team work or one by one. We have the ability now to implementcodes using Atmel AVR programmer. The codes are variety of loops andfunctions. Also, how to simulate these codes using HAPSIM , which isreally exiting programmer, is know clear. All the steps in this lab isapproximately new to us in applying it.

1 Introduction

Lab 4 introduce us to meet different new programming. We have the pleasure todeal with AVR studio which is an Integrated Development Environment‘IDE‘for developing Atmel AVR applications in many windows. In other words, it’s asoftware application that provides overall facilities to users for software develop-ment. It’s comprehensive in code editor, build automation tools, and debugger.We use Helmi’s simulator “HAPSIM“ to apply our codes. It’s used to simulatethe codes by helping of AVR programmer. It’s exiting programmer and easy inusing. The idea of this assignment is to create a system that controls 8 led indifferent methods as automatically or by using push button. System’s details isreally interesting to be known.

2 Experiment Setup

The basic idea of this experiment is to make eight bulbs or reds light in differentways. There’re three cases that is discussion in this lab. First, we make for each

1

Page 3: LabReport 3

led its button when we press it, the led lights. Then, we try to make all ledlights in the same time. Also, the ability to make the led work individual ismore creativity. In other words, while the processor receives a signal, thenone of led lights for specific time then extinguishes and another bulb beginninglights. HAPSIM is one of the best program in simulate system. We use thisprogram to simulate each code of our lab. Every case has its own code and itshardware connection which represent below with more details.

3 List of Equipment Used

• Cables.

• AVR Dragon.

• Breadboard.

• HAPSIM Simulator.

• Training Board.

• Computer “ AVR programmer “.

• Microcontorller with Atmega16.

• Bulbs “ red , yellow , white “.

4 Procedure

As we mention above, there’re three cases that we discusses in our lab. Thesimilarity of these cases is that has eight led that light in different ways. Everyexercise has, also three, main steps which used in building any embedded system.First, the finite state machine which represents all inputs and outputs in system.Our software programming where we write the system’s code is AVR studio. It’sinteresting programmed to deal with it. When we open it, we’ve the choice toselect our project type which is AVR GCC. After choosing system’s place andnamed it, we start writing the code. Also, the connection of the combinationof the system which is the hardware or we can use the simulation method torepresent it.

4.1 First Exercise

The only exercise that every led has specific button. The bulb lights only if wepress its button. When this signal arrive the microcontroller, the processor makethat led works. This operation is used daily to light the rooms, laboratories,and also the streets at night. Because it keeps the electricity, it exists in allhouses, company’s building, and the universities.

2

Page 4: LabReport 3

Code This code mentions the input which is PORTA and the output whichis PORTB. By using while loop; we connect it to the push button.

#include <avr/io.h>

int main()

{

DDRB = 0xff;

while(1)

{

char x=PINA;

PORTB=x;

}

}

4.2 Second Exercise

This part is called repeating because the bulbs work periodical when the pro-grammer is running. In other words, all bulbs light automatically in the sametime and also dimming together. We use this situation in lights decoration.

FSM This graph shows the two state of this exercise which are LED OFFand LED ON that represents the light of led.

Code The code below apply the finite state machine as PORTB is theoutput with changing in value. When the bulb lights, the PORTB must equal0xFF “= 0b11111111“ which mean that all led are working. We use delayfunction which represent the time of staying in each state.

#include <avr/io.h>

int main()

{

DDRB = 0xff;

while(1)

{

PORTB = 0xFF;

_delay_ms(500);

PORTB = 0x00;

_delay_ms(500);

}

}

3

Page 5: LabReport 3

Figure 1: Finite state machine of repeating operation

4.3 Third Exercise

This case likes rotating. The led work automatically while the programmeris running. Each bulb lights and then dimes in specific order. This order isfrom bit 7 to bit 0. Also, it hasn’t any push button. In this part, we do thehardware connection by linking the led with the micocontroller and JTAGICEmkII. Then, we upload the code on this connection using AVR programmer.

FSM

Code The code show verity functions as switch case which has the abilityto move from case to other and also the delay.

#define S0 0

#define S1 1

#define S2 2

#define S3 3

#define S4 4

#define S5 5

#define S6 6

#define S7 7

4

Page 6: LabReport 3

Figure 2: Finite state machine of rotating operation

int current = S0;

#include <avr/io.h>

#include <util/delay.h>

void DoLED(char x, int nextState)

{

PORTA = x;

_delay_ms(500);

current = nextState;

}

int main()

{

DDRA=0xFF;

DDRB=0x00;

5

Page 7: LabReport 3

while(1)

{

switch(current)

{

case S0: DoLED(0b10000000,S1);break;

case S1: DoLED(0b01000000,S2);break;

case S2: DoLED(0b00100000,S3);break;

case S3: DoLED(0b00010000,S4);break;

case S4: DoLED(0b00001000,S5);break;

case S5: DoLED(0b00000100,S6);break;

case S6: DoLED(0b00000010,S7);break;

case S7: DoLED(0b00000001,S0);break;

}

}

}

-Ex3.jpg

Figure 3: The hardware connection of exersice 3

Hardware connection

6

Page 8: LabReport 3

5 Results and Discussion

For sure, these exercise are succsseful because of the matching in results withthe hypotheses. Figures below shows the results of each exersice.

5.1 First Exercise

In the first exercise, we learn how to deal with the led that have a push button.When any button is pressed, the variable ‘X‘ saves it and send it to PORTB.Then the output PORTB turn the LED depends in that number.

Simulation As shown in below figure, the simulation represents the 8push buttons in the right and the led in the left. As we can see, when we pressin button 6, the led 6 is light.

5.2 Second Exercise

In the second exercise, we connect the led in way that work together as lightingin same time and then dimming. To be fair, we mention the time of each stateby using delay.

Simulation As shown in this figure, when PORTB is equal to 0xFF, allled light. The other imge represent off led beacuse PORTB is 0x00.

5.3 Third Exercise

In the third exercise, we make a code that light the LEDs one by one where thebelow simulation abrove that. The led lights from the bottom to the top. Asshown in figure , when the processor start running, led seven begin lighting.

Simulation

6 Conclusion

To sum up, we learn many things from this lab. First, how to make a completesystem by dealing with specific steps. We learn how to connect the led in differ-ent way such as linking them with push buttons. This lab becomes interestingwhile we write the codes using many technique as while loops, switches, anddelay functions. It’s the first time that we deal with different programming.For example, we use Atmel AVR programmer to write our C code and uploadit in hardware or simulate it by using HAPSIM programmer. I hope, after allled that we used, that our life become lighting as it.

7

Page 9: LabReport 3

4 - new.jpg

Figure 4: When it’s pressing in the push button 6, the led 6 lights

8

Page 10: LabReport 3

2 - light.jpg

Figure 5: When the led lights

9

Page 11: LabReport 3

2 - UN.jpg

Figure 6: When the led is off = 0x00

10

Page 12: LabReport 3

3 - led 7.jpg

Figure 7: When the led seven is light which is the start of the this system

11

Page 13: LabReport 3

3 - led 2.jpg

Figure 8: When led 2 lights

12