//***************************************************************************** // File Name : datalogger.c // // Title : Windlogger // Revision : 0.3 22-10-2006 // Revision History: // When Who Description of change // ----------- ----------- ----------------------- // 20-Oct-2002 pstang Created the program // Oct - 2006 RifRaf changes stuff //***************************************************************************** //----- Include Files --------------------------------------------------------- #include // include I/O definitions (port names, pin names, etc) #include // include "signal" names (interrupt names) #include // include interrupt support #include "global.h" // include our global settings #include "uart.h" // include uart function library #include "rprintf.h" // include printf function library #include "timer.h" // include timer function library (timing, PWM, etc) #include "a2d.h" // include A/D converter function library #include "vt100.h" // include VT100 terminal support #include "extint.h" // include external interrupt library #define SetBit(BIT, PORT) PORT |= (1< 580) { mode = 1; SwitchToLoad(); } if (volts < 540) { mode = 0; SwitchToCharging(); } vt100SetCursorPos(1,1); rprintf("[%d%d%d%d%d%d]\r\n",volts,shuntvolts,rpm,windpulse,mode,direction); } } int windDirection() { PTRType test; int n; test.TPD7 = ISHIGH(7, PORTD); test.TPD6 = ISHIGH(6, PORTD); test.TPD5 = ISHIGH(5, PORTD); test.TPD4 = ISHIGH(4, PORTD); test.TPC2 = ISHIGH(2, PORTC); test.TPC3 = ISHIGH(3, PORTC); test.TPC4 = ISHIGH(4, PORTC); test.TPC5 = ISHIGH(5, PORTC); for (n = 0; n < 32; n++) { if( stateTable[n].state == test ) { return stateTable[n].next; } } return -1 // we dont know!? } typedef struct FSM_State_s { unsigned TPD7 : 1; unsigned TPD6 : 1; unsigned TPD5 : 1; unsigned TPD4 : 1; unsigned TPC2 : 1; unsigned TPC3 : 1; unsigned TPC4 : 1; unsigned TPC5 : 1; } FSM_State_t; typedef unsigned int PTRType; typedef struct stateEntry_s { PTRType next; FSM_State_t state; } stateEntry_t; #define on 0 #define off 1 //------------ // PC5 , PC4 , PC3 , PC2 , PD4 , PD5 , PD6 , PD7 , stateEntry_t stateTable[] = { { 0, { on , on , on , off , off , off , off , off , }}, /* index: 31 0 */ { 1, { on , on , off , off , off , off , off , on , }}, /* index: 62 1 */ { 2, { on , on , off , off , off , off , off , off , }}, /* index: 63 2 */ { 3, { on , off , on , off , off , off , off , off , }}, /* index: 95 3 */ { 4, { on , off , off , off , off , on , off , off , }}, /* index: 123 4 */ { 5, { on , off , off , off , off , off , on , on , }}, /* index: 124 5 */ { 6, { on , off , off , off , off , off , off , on , }}, /* index: 126 6 */ { 7, { on , off , off , off , off , off , off , off , }}, /* index: 127 7 */ { 8, { off , on , on , on , off , off , off , off , }}, /* index: 143 8 */ { 9, { off , on , on , off , off , off , off , off , }}, /* index: 159 9 */ { 10, { off , on , off , on , off , off , off , off , }}, /* index: 175 10 */ { 11, { off , on , off , off , off , off , off , on , }}, /* index: 190 11 */ { 12, { off , on , off , off , off , off , off , off , }}, /* index: 191 12 */ { 13, { off , off , on , on , on , off , off , off , }}, /* index: 199 13 */ { 14, { off , off , on , on , off , off , off , off , }}, /* index: 207 14 */ { 15, { off , off , on , off , on , off , off , off , }}, /* index: 215 15 */ { 16, { off , off , on , off , off , off , off , off , }}, /* index: 223 16 */ { 17, { off , off , off , on , on , on , off , off , }}, /* index: 227 17 */ { 18, { off , off , off , on , on , off , off , off , }}, /* index: 231 18 */ { 19, { off , off , off , on , off , on , off , off , }}, /* index: 235 19 */ { 20, { off , off , off , on , off , off , off , off , }}, /* index: 239 20 */ { 21, { off , off , off , off , on , on , on , on , }}, /* index: 240 21 */ { 22, { off , off , off , off , on , on , off , off , }}, /* index: 243 22 */ { 23, { off , off , off , off , on , off , on , off , }}, /* index: 245 23 */ { 24, { off , off , off , off , on , off , off , off , }}, /* index: 247 24 */ { 25, { off , off , off , off , off , on , on , on , }}, /* index: 248 25 */ { 26, { off , off , off , off , off , on , on , off , }}, /* index: 249 26 */ { 27, { off , off , off , off , off , on , off , on , }}, /* index: 250 27 */ { 28, { off , off , off , off , off , on , off , off , }}, /* index: 251 28 */ { 29, { off , off , off , off , off , off , on , on , }}, /* index: 252 29 */ { 30, { off , off , off , off , off , off , on , off , }}, /* index: 253 30 */ { 31, { off , off , off , off , off , off , off , on , }}, /* index: 254 31 */ }; void rpmSetup(void) { extintInit(); extintConfigure(EXTINT0, EXTINT_EDGE_RISING); extintConfigure(EXTINT1, EXTINT_EDGE_RISING); extintAttach(EXTINT0, myInt0Handler); extintAttach(EXTINT1, myInt1Handler); sbi(GIMSK, INT0); sbi(GIMSK, INT1); } void myInt0Handler(void) { Int0Count++; } void myInt1Handler(void) { Int1Count++; } void SwitchToCharging(void) { ClearBit(0, PORTB) ; return; } void SwitchToLoad(void) { SetBit(0, PORTB) ; return; }