Академический Документы
Профессиональный Документы
Культура Документы
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 1
The AVR Assembler
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 2
The assembler’s text substitution allows one to use symbols rather than numbers
loop:
sbi PORTB,1
cbi PORTB,1
rjmp loop
loop:
000001 sbi 0x17,1
These are program addresses
000002 cbi 0x18,2
000003 cbi 0x18,1
000004 rjmp 0x01
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 3
The assembler’s text substitution allows one to use symbols rather than numbers
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 4
Assembler Directives
Instead, they are used to adjust the location of the program in memory, define
macros, initialize memory and so on.
loop:
sbi PORTB,1
cbi PORTB,1
rjmp loop
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 5
We have seen this directive
several times thus far
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 6
.INCLUDE – Include another file ASM Directive
The INCLUDE directive tells the Assembler to start reading from a specified file. The
Assembler then assembles the specified file until end of file (EOF) or an EXIT directive is
encountered. An included file may itself contain INCLUDE directives.
Contents of iodefs.asm
Include this in another AM program, and one can use symbols such as sreg
rather than 0x3f:
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 7
.EXIT - Exit this file ASM Directive
The EXIT directive tells the Assembler to stop assembling the file. Normally, the Assembler
runs until end of file (EOF). If an EXIT directive appears in an included file, the Assembler
continues from the line following the INCLUDE directive in the file containing the INCLUDE
directive.
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 8
Assembler Functions
ldi r19,low(0x07F3)
This returns the high byte
ldi r20,high(0x07F3)
ldi r19,0xF3
ldi r20,0x07
Generate opcodes
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 9
Assembler Functions
LOW and HIGH are often used, others less frequently, and we will not cover these
in this course
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 10
Assembler Preprocessor
The AVRASM2 preprocessor is modeled after the C preprocessor, with some exceptions
(see AVRASM2 documentation).
#error #message
.EQU c1 = 0b11011010
.equ c2 = 0b10101010
As with the C preprocessor, the AVRASM2
#define DEBUG preprocessor allows conditional processing.
#ifdef DEBUG For example, one can build a special debug version as
ldi r18,low(c1|c2) shown in the snippet.
rcall delay
#else
ldi r18,low(c1^c2)
#endif
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 11
Microcontroller Fuses
AVR ATtiny45 ® 8-Pin Microcontroller
• Except for GND and VCC all other pins can perform at least 4 functions
• PB5 can be hardware RESET or an ADC input
• PB3 & PB4 can be ADC inputs or where crystal for external oscillator
goes
• How does one configure controller for the external environment?
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 12
Microcontroller Configuration/Fuses
AVR ATtiny45 ® 8-Pin Microcontroller
• Except for GND and VCC all other pins can perform at least 4 functions
• PB5 can be hardware RESET or an ADC input
• PB3 & PB4 can be ADC inputs or where crystal for external oscillator
goes
• How does one configure controller for the external environment?
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 13
Microcontroller Configuration/Fuses
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 14
Enables use of WDT
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 15
Vcc
Vcc
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 16
Switch Bounce and Debouncing
Bounce
~ 5 ms
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 17
Switch Bounce and Debouncing
t
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 18
Software Debounce
One idea. Sample n times at regular intervals, say 10 ms apart. Count how many times the
switch is zero . In this is larger than the number of times the switch is high, consider the
switch pressed.
char isPressed(void)
{
char ones=0, zeroes=0, i;
for(i=0;i<=10-1;i++){
if(PINA&0x01){ // read pin == 1
ones++;
} else { // read pin == 0
zeroes++;
}
_delay_ms(10);
}
return (ones > zeroes);
}
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 19
Testing Status of an I/O PIN
...
cbi DDRB,0
cbi DDRB,1
...
SBIS PINB,0
...
...
cbi DDRB,0
cbi DDRB,1
...
SBIC PINB,0 Also, the is a companion instruction SBIC (Skip
... next instruction if bit in I/O is Clear)
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 20
Which PIN to Use?
There are 3 available PINs for use
as switch input: PINB0, PINB1,
PINB2.
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 21
Embedded Systems and Software, 55:036. The University of Iowa, 2013 Lab 2 Notes Slide 22