程序代写代做代考 assembly 6/10/2013

6/10/2013
Embedded Systems Design ELEN90066
Lecture 18 Good Code and AVR Studio David Jahshan
Notes from last lecture
• Perfect code is linear with no branches or exceptions.
• Interrupts and how they operate and how to code in C
• Nested Interrupts
• How to add assembly to your code
• Self documenting code
AVR Studio
• Go through AVR studio
– Stepping through code
– Changing fuse settings
– Real time modifying registers – Viewing disassembly
Useful Macros
• #define ON 0xFF
• #define OFF 0x00
• #define SET(PORT,MASK,VALUE)
PORT = ((MASK & VALUE) | (PORT & ~MASK))
– PORT is the register (ie PORTA)
– MASK is a bit mask where there is a 1 at the
position you want to set a bit ie 0100 0000 – VALUE can be all 1 or all 0
• #define GET(PORT,MASK) (PORT & MASK)
SPI • Serial Peripheral Interface
Source: ATMEGA16 Datasheet Page 134
Using SPI
• Page138bottomhalf
• Learnhowtodothis,youwillbeexaminedonthis • Set up the clock
• Set up the operating mode
• Decide if you want to use interrupts
• Write interrupt service routine
1

6/10/2013
Next Lecture
• By Simone on Silicon Fabrication and design • Monday week
– Interfacing to the LCD – Timers
– PWM
2