Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


e talking to the Joystick demo.

ove th you should receive:
The joys


ove t
he joys

u should receive:
he joys SH

ed

s loop runs in the CPU, which can do nothing else while it is
nning. You set the period of the delay by sending a parameter for the number of
ou want to waste. Knowing the time per cycle allows you to set the
me of the delay. Cycle wasting delays are a simple way to control some types of
periodi ost of totally occupying the CPU
hile w t need to do
unning, but it makes a lousy way to mark time if
ou have anything else going on. Timers are peripheral devices that run
independent of the CPU and only bother the CPU when set up to do so. The
othering can take the form of setting a flag that the CPU can poll, or throwing an
ions.


You ar


Type in:
joy


M e joystick to the left and
tick position is: LEFT


Move the joystick to the right and you should receive:
The joystick position is: RIGHT


Move the joystick up and you should receive:
The joystick position is: UP


M he joystick down and you should receive:
T tick position is: DOWN


Push the joystick while centered t and yo
T tick position is: PU


I’m tired and going to bed. Tomorrow we’ll look at timers. I may get so excit
that I won’t be able to sleeeeeppp ummm errr zzzzzz....


Timers/Counters


Good morning! In Blinky.c we set the timing of the blinks using the
_delay_loop_2(delaycount). The delay function uses a 16-bit count that takes 4
cycles/loop. Thi
ru
‘4 cycles’ y
ti
c events, but the simplicity comes at the c
w asting the specified time. That’s a good idea if you don’
anything else while the delay is r
y


b
interrupt to break into normal operat

Free download pdf