0% found this document useful (0 votes)
91 views7 pages

Compte Rendu TP N°1: Microcontroleur

Uploaded by

ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views7 pages

Compte Rendu TP N°1: Microcontroleur

Uploaded by

ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

comptE

rendu TP N°1
microcontroleur

 Réalisé par :
 Ali benchekroun

 Introduction:
 Atmel Studio is an Integrated Development Environment (IDE)
for writing and debugging AVR®/ARM® applications in
Windows® XP/Windows Vista®/Windows 7/8 environments.
Atmel Studio provides a project management tool, source file
editor, simulator, assembler, and front-end for C/C++,
programming, and on-chip debugging.

 Atmel Studio supports the complete range of Microchip AVR


tools. Each new release contains the latest updates for the tools
as well as support for new AVR/ARM devices

 Creating a New Project :

 1.Open Atmel Studio.

 2.In Atmel Studio, go to File → New → Project

3.The project generation wizard will appear. This dialog provides the option to
specify the programming language and project template to be used.
4.Next, it is necessary to specify which device the project will be developed for. A list of
devices will be presented in the Device Selection dialog, which can be scrolled through,
as depicted in Figure 3.
 Calcul de la temporisation :
Assuming that our Arduino AVR is running at 16 MHz (16 Million
clock cycles per second), how long does all this take?
T = 1/ F then T = 1 / 16E6
T = 0,0000000625 seconds, not precisely 0,06 us

if 1 cycle takes -----------0,0000000625 seconds


x cycles will take -----------0,5 seconds
this makes 0,5 / 0,0000000625 s = 8 000 0000 cycles

we will have to implement two loops: inner and outloop. See how:


Calculations - The inner loop is treated like one BIG instruction needing
262145 clock cycles. See: Inner loop first - as you know registers can be used
in pairs, allowing to work with values from 0 to 65 535. That’s a word.

The following piece of code clears registers 24 and 25 and


increments them in a loop until they overflow to zero again.
When that condition occurs, the loop doesn’t go around again. Let’s
go ahead!
clr r24 ; clr needs 1 cycle
clr r25 ; clr needs 1 cycleDELAY_05: ; we need .
5s delay
adiw r24, 1 ; adiw needs 2 cycles and
brne DELAY_05 ; brne needs 2 cycles if the branch is done
; and 1 otherwise
Every time the registers don’t overflow the loop takes adiw(2) +
brne(2) = 4 cycles.
This is done 0xFFFF (65 535) times before the overflow occurs. The
next time the loop only needs 3 cycles, because no branch is done.
This adds up to 4 * 65 535(looping) + 3(overflow) + 2(clr) = 262 145
cycles. This is still not enough: 8 000 000/262 145 ~ 30.51.
The “outer” loop will be down-counting from 31 to zero using R16.
ldi r16, 31OUTER_LOOP: ; outer loop label
ldi r24, 0 ; clear register 24
ldi r25, 0 ; clear register 25DELAY_05: ; the
loop label
adiw r24, 1 ; “add immediate to word”: r24:r25 are
; incremented
brne DELAY_05
dec r16 ; decrement r16
brne OUTER_LOOP ; load r16 with 8
The overall loop needs: 262 145 (inner loop) + 1 (dec) + 2 (brne) =
262 148 * 31 = 8 126 588 cycles.
This is more like what we want, but 126 588 cycles too long.
This is where the fine-tuning comes in — we need to change the
initial value of r24:r25.
The outer loop is executed 31 times and includes the “big-inner-
loop-instruction”.
We have to subtract some cycles from the inner loop: 126 588 /
31 = 4 083 cycles per inner loop.
This is what the inner loop has to be shorter. Every iteration of the
inner loop takes 4 cycles (the last one takes 3 but that’s not so
important), so let’s divide those 4 083 by 4.
That’s 1 020.8 or 1 021 fewer iterations.

 Lab2 :

this application is dedicated to have 4 leds that works teporarly one


after the other with a delay of 0,5s between the flash of every single
led with non stopped program till the user ends the simulation.
 Application 2:
 Before pushing the push button:
 After pushing the push button:

The goal of this application is to make a push button , when it got


pressed the led blinks and when the push button is released the led is
off again.

You might also like