All pastes #214256 Raw Edit

Untitled

public c v1 · immutable
#214256 ·published 2006-10-21 22:53 UTC
rendered paste body
//*****************************************************************************// File Name    : a2dtest.c// // Title                : Windlogger// Revision          : 1.0// Notes                :       // Target MCU   : Atmel AVR series// Editor Tabs  : 4// // Revision History:// When   Who                  Description of change// -----------  -----------       -----------------------// 20-Oct-2002  pstang        Created the program// Oct - 2006 RifRaf changes stuff//***************************************************************************** //----- Include Files ---------------------------------------------------------#include <avr/io.h>            // include I/O definitions (port names, pin names, etc)#include <avr/signal.h>        // include "signal" names (interrupt names)#include <avr/interrupt.h>     // 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<<BIT)#define ClearBit(BIT, PORT)      PORT &= ~(1<<BIT)#define IsHigh(BIT, PORT)       (PORT & (1<<BIT)) != 0#define IsLow(BIT, PORT)        (PORT & (1<<BIT)) == 0 //global variablesunsigned int volts;       // Current value of Battery Voltsunsigned int shuntvolts;  // Current value of Shunt Voltsunsigned int acvolts;     // Current value of AC Voltsunsigned int mode;        // Dummy load on or offvolatile u16 Int1Count;u16 windpulse;             // Windspeed Pulses per 3 seconds// functions void SwitchToCharging(void);void SwitchToLoad(void);void rpmSetup(void);void myInt0Handler(void);void myInt1Handler(void); //----- Begin Code ------------------------------------------------------------ int main(void){        uartInit();        uartSetBaudRate(4800);    // set UART speed to 9600 baud        rprintfInit(uartSendByte);        timerInit();        a2dInit();         vt100ClearScreen();		//rprintf("hello");                    DDRC = 0x00;        PORTC = 0x00;         a2dSetPrescaler(ADC_PRESCALE_DIV64);        a2dSetReference(ADC_REFERENCE_AVCC);		rpmSetup();                // use a2dConvert8bit(channel#) to get an 8bit a2d reading        // use a2dConvert10bit(channel#) to get a 10bit a2d reading         while (1)                 // do this until finished or broken        {        volts      = a2dConvert10bit(0);    // Get ADC Value        shuntvolts = a2dConvert10bit(1);    // Get ADC Value		acvolts    = a2dConvert10bit(2);    // Get ADC Value		Int1Count = 0;          // reset interrupt counters		timerPause(3000);       // wait 3 seconds		windpulse = Int1Count;  // get counter values		if (volts > 580) { mode = 0; SwitchToLoad(); }        if (volts < 540) { mode = 1;  SwitchToCharging(); }            vt100SetCursorPos(1,1);            rprintf("[<V>%d</V><A>%d</A><R>%d</R><S>%d</S><M>%d<M>]\r\n",volts,shuntvolts,acvolts,windpulse,mode);        } } void rpmSetup(void){	extintInit();	extintConfigure(EXTINT1, EXTINT_EDGE_RISING);	extintAttach(EXTINT1, myInt1Handler);	sbi(GIMSK, INT1);}void myInt1Handler(void){	Int1Count++;}void SwitchToCharging(void) {   ClearBit(2, PORTC) ;   return;} void SwitchToLoad(void) {   SetBit(2, PORTC) ;  return;}