Question

Using the register values that you calculated in your pre-lab assignment, write a C program which displays the eight most sigNTCON PIE1 ADCON1 TRISB PORTB ADCON0 11000000(0xCO) 01000000 (0x40) 00001111(0xOf) 00000000(0x0) 00000000 (0x0) 00000101(0x05

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.

Using the register values that you calculated in your pre-lab assignment, write a C program which displays the eight most significant bits of the ADC result on LED3-LED10. Your main loop will hold a variable with the most recent result of an A/D conversion, of which the eight MSBs will be written out to a port connected to the LEDs. You are to set up the ADC to interrupt your program when the conversion is complete, and to update the variable. Once the variable has been updated, you should start another A/D conversion before exiting the ISR
NTCON PIE1 ADCON1 TRISB PORTB ADCON0 11000000(0xCO) 01000000 (0x40) 00001111(0xOf) 00000000(0x0) 00000000 (0x0) 00000101(0x05)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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
}

Add a comment
Know the answer?
Add Answer to:
Second picture is the register values. I am completely and utterly lost as to how to do this, no ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT