74 lines
2.1 KiB
C
74 lines
2.1 KiB
C
/* ---------------------------------------------------------------------------
|
|
** This software is in the public domain, furnished "as is", without technical
|
|
** support, and with no warranty, express or implied, as to its usefulness for
|
|
** any purpose.
|
|
**
|
|
** ioisr.c
|
|
**
|
|
** Beschrijving: ISR on PORTD demonstrattion
|
|
** Target: AVR mcu
|
|
** Build: avr-gcc -std=c99 -Wall -O3 -mmcu=atmega128 -D F_CPU=8000000UL -c ioisr.c
|
|
** avr-gcc -g -mmcu=atmega128 -o ioisr.elf ioisr.o
|
|
** avr-objcopy -O ihex ioisr.elf ioisr.hex
|
|
** or type 'make'
|
|
** Author: dkroeske@gmail.com
|
|
** -------------------------------------------------------------------------*/
|
|
|
|
#define F_CPU 10e6
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
|
|
/******************************************************************
|
|
/*
|
|
short: Busy wait number of millisecs
|
|
inputs: int ms (Number of millisecs to busy wait)
|
|
outputs:
|
|
notes: Busy wait, not very accurate. Make sure (external)
|
|
clock value is set. This is used by _delay_ms inside
|
|
util/delay.h
|
|
Version : DMK, Initial code
|
|
*******************************************************************/
|
|
void wait( int ms ) {
|
|
for (int i=0; i<ms; i++) {
|
|
_delay_ms( 1 ); // library function (max 30 ms at 8MHz)
|
|
}
|
|
}
|
|
|
|
/*****************************************************************
|
|
short: ISR INT0
|
|
inputs:
|
|
outputs:
|
|
notes: Set PORTD.5
|
|
Version : DMK, Initial code
|
|
*******************************************************************/
|
|
ISR( INT0_vect ) {
|
|
PORTC
|
|
}
|
|
|
|
/******************************************************************
|
|
short: main() loop, entry point of executable
|
|
inputs:
|
|
outputs:
|
|
notes: Slow background task after init ISR
|
|
Version : DMK, Initial code
|
|
*******************************************************************/
|
|
int main( void ) {
|
|
// Init I/O
|
|
DDRD = 0xF0; // PORTD(7:4) output, PORTD(3:0) input
|
|
|
|
// Init Interrupt hardware
|
|
EICRA |= 0x00000010; // INT0 falling edge
|
|
EIMSK |= 0x03; // Enable INT1 & INT0
|
|
|
|
// Enable global interrupt system
|
|
//SREG = 0x80; // Of direct via SREG of via wrapper
|
|
sei();
|
|
|
|
while (1) {
|
|
|
|
}
|
|
|
|
return 1;
|
|
} |