second picture is the register values. I am completely and utterly lost as to how to do this, no instructions were given beyond what you see here. The microcontroller used is a PICkit 3 on a PIC16F87XX trainer board, and we are using a 6V bench power supply to act as a sensor.
void main (void){
int new_result;
float Voltage_result;
int result_1;
int result_2;
unsigned char input;
PORTB = 0x00;
TRISB = 0x00; //Port B all output
init_comms();
while(1) {
printf("\r\r\rPress a key to see voltage reading:\n");
input = getch();
new_result = ADC_1();
new_result = (new_result / 68)+1;
Voltage_result = (new_result - 1)/3;
printf("\r Value shown on LEDs is %d", new_result);
printf("\r\r Voltage is %fV", Voltage_result);
__delay_ms(1000);
result_1 = ADC_1();
int ADC(void)
{
int AN0_val = 0;
int AN1_val = 0;
int AN2_val = 0;
int AN3_val = 0;
int AN4_val = 0;//** Initalise Ports FOR ADC **//
PORTA = 0x00;
PORTB = 0x00;
TRISA = 0xFF //Port A is all inputs.
//** Set Up ADC Parameters **//
ANSEL = 0b00001111; //All AN0-AN8 are analogue is now analog input
ANSELH = 0x00; //Set the analog high bits to 0
ADCON1 = 0x80; // Sets ADRESL to contain the first 7 bits of
conversion, ADRESH will have the final 3 bits.
//*AN0 Conversion *//
ADCON0 = 0xC1; //1100 0001 - AN1 set up ADC ADCON0 Register it sets
the frequency to internal oscillator and enables the ADC
__delay_us(10);
ADCON0 = ADCON0 | 0x02; //This sets the go/!done bit that starts
conversion. Bit will be cleared when ADC is complete while (ADCON0
& 0x02); //wait here until conversion is complete
AN0_val = (ADRESH << 8) + ADRESL; //result is 16 bits with
10-bits for measurement. Shift upper 8 bits left 8 bits into high
byte and add low byte.
//*AN1 Conversion *//
ADCON0 = 0xC5;
__delay_us(10);
ADCON0 = ADCON0 | 0x02;
while (ADCON0 & 0x02);
AN1_val = (ADRESH << 8) + ADRESL;
//*AN2 Conversion *// ADCON0 = 0xC9;
__delay_us(10);
ADCON0 = ADCON0 | 0x02;
while (ADCON0 & 0x02);
AN2_val = (ADRESH << 8) + ADRESL;
//*AN3 Conversion *//
ADCON0 = 0xCD;
__delay_us(10);
ADCON0 = ADCON0 | 0x02;
while (ADCON0 & 0x02);
AN3_val = (ADRESH << 8) + ADRESL;
//*AN4 Conversion *//
ADCON0 = 0xD1;
__delay_us(10);
ADCON0 = ADCON0 | 0x02;
while (ADCON0 & 0x02);
AN4_val = (ADRESH << 8) + ADRESL;
return (); //the result is passed to main() or whatever calls this
function
}
Second picture is the register values. I am completely and utterly lost as to how to do this, no ...
second picture is the register values. I am completely and utterly lost as to how to do this, no instructions were given beyond what you see here. The microcontroller used is a PICkit 3 on a PIC16F87XX trainer board, and we are using a 6V bench power supply to act as a sensor. We use C to code NOT C++, please make sure to use the right language. Using the register values that you calculated in your pre-lab assignment, write...