Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


= 0;
/count to 1000 and trigger one second

the USART

Hertz\r");

parse_set(s);


unsigned char milliseconds
unsigned int second = 0;/
event
unsigned int speed = 0; // IR detector count per second
unsigned int lastspeed = 0; // IR detector count per second


void initializer()
{
// Calibrate the oscillator:
OSCCAL_calibration();


// Initialize
USARTinit();


// Init port pins
DDRB |= 0x08;
PORTB |= ((1<<PINB4));//|(1<<PINB6)|(1<<PINB7));


// Enable pin change interrupt on PORTB
PCMSK1 = ((1<<PINB4));//|(1<<PINB6)|(1<<PINB7));
EIFR = (1<<6)|(1<<7);
EIMSK = (1<<6)|(1<<7);


DDRD = 0xFF; // set PORTD for output
PORTD = 0XFF; // set LEDs off


milliSecInit(127); // 50% duty cycle 1kHz signal


// say hello
sendString("\rPC_Comm.c ready to communicate.\r");
// identify yourself specifically
sendString("You are talking to the Speedometer demo.\r");
sendString("'setxxx' to set speed\r'Hz' to get speed in


}


void parseInput(char s[])
{
// parse first character
switch (s[0])
{
case 's':
if( (s[1] == 'e') && (s[2] == 't'))

Free download pdf