?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik //*****************************************************************************
2 // File Name : extinttest.c
3 //
4 // Title : example usage of external interrupt library functions
5 // Revision : 1.0
6 // Notes :
7 // Target MCU : Atmel AVR series
8 // Editor Tabs : 4
9 //
10 // Revision History:
11 // When Who Description of change
12 // ----------- ----------- -----------------------
13 // 14-Dec-2004 pstang Created the program
14 //*****************************************************************************
15  
16  
17 //----- Include Files ---------------------------------------------------------
18 #include <avr/io.h> // include I/O definitions (port names, pin names, etc)
19 #include <avr/interrupt.h> // include interrupt support
20  
21 #include "global.h" // include our global settings
22 #include "uart.h" // include uart function library
23 #include "rprintf.h" // include printf function library
24 #include "timer.h" // include timer function library
25 #include "extint.h" // include external interrupt library
26  
27 // global variables
28 volatile u16 Int0Count;
29 volatile u16 Int1Count;
30  
31 // functions
32 void extintTest(void);
33 void myInt0Handler(void);
34 void myInt1Handler(void);
35  
36 //----- Begin Code ------------------------------------------------------------
37 int main(void)
38 {
39 // initialize our libraries
40 // initialize the UART (serial port)
41 uartInit();
42 // set the baud rate of the UART for our debug/reporting output
43 uartSetBaudRate(115200);
44 // initialize rprintf system
45 rprintfInit(uartSendByte);
46 // initialize timers
47 timerInit();
48  
49 // run the test
50 extintTest();
51  
52 return 0;
53 }
54  
55 void extintTest(void)
56 {
57 u16 temp0, temp1;
58  
59 // print a little intro message so we know things are working
60 rprintf("\r\n\n\nWelcome to the External Interrupt library test program!\r\n");
61  
62 // initialize the external interrupt library
63 rprintf("Initializing external interrupt library\r\n");
64 extintInit();
65  
66 // configure external interrupts for rising-edge triggering.
67 // when a rising-edge pulse arrives on INT0 or INT1,
68 // the interrupt will be triggered
69 rprintf("Configuring external interrupts\r\n");
70 extintConfigure(EXTINT0, EXTINT_EDGE_RISING);
71 extintConfigure(EXTINT1, EXTINT_EDGE_RISING);
72  
73 // attach user interrupt routines.
74 // when the interrupt is triggered, the user routines will be executed
75 rprintf("Attaching user interrupt routines\r\n");
76 extintAttach(EXTINT0, myInt0Handler);
77 extintAttach(EXTINT1, myInt1Handler);
78  
79 // enable the interrupts
80 rprintf("Enabling external interrupts\r\n");
81 // (support for this has not yet been added to the library)
82 sbi(GIMSK, INT0);
83 sbi(GIMSK, INT1);
84  
85 // In this loop we will count the number of external interrupts,
86 // and therefore the number of rising edges, that occur in one second.
87 // This is precisely the frequency, in cycles/second or Hz, of the signal
88 // that is triggering the interrupt.
89  
90 while(1)
91 {
92 // reset interrupt counters
93 Int0Count = 0;
94 Int1Count = 0;
95 // wait 1 second
96 timerPause(1000);
97 // get counter values
98 temp0 = Int0Count;
99 temp1 = Int1Count;
100 // print results
101 rprintf("Frequency on INT0 pin: %dHz -- On INT1 pin: %dHz\r\n", temp0, temp1);
102 }
103 }
104  
105 void myInt0Handler(void)
106 {
107 // count this interrupt event
108 Int0Count++;
109 }
110  
111 void myInt1Handler(void)
112 {
113 // count this interrupt event
114 Int1Count++;
115 }
116  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3