Ad.c

Fra Hougaard

Skift til: Navigation, Søgning
// AkvarieComputer - ad.c
 
#include <pic18.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
#include "delay.h"
#include "akvarie.h"
#include "menu.h"
#include "xeeprom.h"
 
int ReadAD(unsigned char PortNo)
{
	char buffer[20];
	int  Value;
	ADCON1=0b0001011;
	/* update the channel to the A2D converter */
	CHS0=(PortNo&0b00000001);
	CHS1=((PortNo&0b00000010)>>1);
	CHS2=((PortNo&0b00000100)>>2);
 
	ADCON2=0b0011100;
	ADON =1;
 
	/* request the A2D conversion */
	GODONE=1;
	while(GODONE)continue;
	ADIF=0;
 
	Value = ADRESH;
	Value = Value << 2;
	Value += ADRESL >> 6;
	return Value;
}
 
float ReadProbe(char No)
{
	float Sum = 0;
	char i;
	for (i = 0; i < 10; i++)
	{
		Sum = Sum + ReadAD(No);
		DelayMs(10);
	}
	return Sum / 10;
}
Personlige værktøjer