/**************************************************************************/ /* blink.c Written by Matt Begg January '93 */ /**************************************************************************/ /* Sample program for the Analog Devices EZ-Lab board and C compiler 2.0 */ /* or later. */ /* Demonstrates use of interrupts and 21020 I/O flags without use of */ /* assmbly level programming. */ /* */ /* To compile: */ /* */ /* g21k blink.c -o blink -a ez.ach -Wall -O2 -save-temps -xref */ /* */ /* blink.c is the file to compile. If you don't specify ".c" as */ /* the extension, it will be assumed to be an object file */ /* and passed to the linker, which will probably complain. */ /* g21k will also assemble files with ".asm" extensions */ /* automatically. */ /* */ /* -o specifies the output file name (.exe automatically added */ /* if you don't specify otherwise) */ /* -a specifies the architecture file name. */ /* */ /* -Wall turns on the most useful warning messages. If you get a */ /* warning, there is usually something wrong. */ /* */ /* -O2 turns on the most optimimiations and will produce the most */ /* efficient code. -O runs only the faster optimizations */ /* but still produces much better code than unoptimized, which */ /* is the only code the debugger can handle. */ /* */ /* -save-temps tells the compiler to keep its temporary files */ /* they are: */ /* blink.i Preprocessed file. Comments are removed, macros */ /* are expanded into C code or asm statements */ /* */ /* blink.s assembly language file. Look here to get an */ /* idea of how efficient the compiler is. */ /* */ /* blink.o object file. Ready to link. */ /* */ /* blink.ldr linker file. This can be treated like an exe. */ /* It is probably a bit bigger though. */ /* */ /* blink.exe executable file. Use this one with the */ /* EZ-Lab board or simulator. Arrays and other */ /* variables have been compressed for faster */ /* loading and smaller ROM requirements. */ /* */ /* -map tells linker to generate map file. Lists varibles and */ /* memory requirements. Does not account for any compression */ /* after linking. */ /* Note: Flag bits are restored by return from interrupt in rev. 0 21020 */ /* This means led 2 will appear to stay on constantly. To fix this, get */ /* a revision 1 part. */ #include <21020.h> #include void timer_isr(int interrupt_number); /* prototypes are very important */ void main(void) { timer_set(6250000, 6250000); /* period, current count (cycles) */ /* >6250000/25MHz=4 toggles per sec */ interrupt(SIG_TMZ0, timer_isr); /* set up timer interrupt routine */ timer_on(); /* start timer */ set_flag(SET_FLAG1, CLR_FLAG); /* turn off led 1 */ for(;;) /* infinite loop */ { poll_flag_in(READ_FLAG0, FLAG_IN_LO_TO_HI); /* wait for switch press */ set_flag(SET_FLAG1, SET_FLAG); /* turn on led 1 */ poll_flag_in(READ_FLAG0, FLAG_IN_HI_TO_LO); /* wait for release */ set_flag(SET_FLAG1, CLR_FLAG); /* turn off led 1 */ } } void timer_isr(int interrupt_number) /* The interrupt handler passes the */ { /* number of the interrupt to your */ /* isr so it can deal with */ /* multiple interrupts. You do not */ /* have to use this feature; take */ /* the parameter then ignore it. */ set_flag(SET_FLAG2, TGL_FLAG); /* toggle led 2 on or off */ }