Chapter 7: Microcontroller Interrupts and Timers
value
se Correct mode, CLK/8 prescaler
GM01)|(1<<WGM00)|(1<<CS01);
id s ount)
mpare value
ccurs twice per Millisec, timed for PWM
RTD &= 1) cbi(PORTD, 0);
else sbi(PORTD, 0);
once per second
1000)
d = speed; // store most recent speed in Hz
IGNAL(SIG_PIN_CHANGE1)
le changes. We reused the pin interrupt code from
he interrupt routine we increment a speed counter
opy the speed counter value to ‘lastspeed’ variable,
z when requested.
mbering to reset the AVRStudio programming tool to use
omm.hex, which I forgot AGAIN! Open HyperTerminal, toggle
// Sets the compare
setOCR0A(count);
// Set PWM Pha
TCCR0A = (0<<FOC0A)|(0<<W
}
vo etOCR0A(unsigned char c
{
// Sets the co
OCR0A = count;
}
// Interrupt o
SIGNAL(SIG_OUTPUT_COMPARE0)
{
// Toggle PORTD pin 0
if(PO
// get the speed count
if(second++ >=
{
second = 0;
lastspee
speed = 0;
}
}
S
{
speed++;
}
We’ve made a couple of simp
the joystick software and in t
variable. Once per second we c
which we report as the speed in H
Compile and load, reme
the correct PC_C