I have gone back to C18 (thanks M chip for new version!!!), but sticking it out with the mplabx, mainly because its alot like the other IDE's I use like Kiel V5. Anyway, still knawing my way through the ADC libs, I want to use the ADC on the 18f4685 in the past with no problems. But I want to try and go it alone and write my own routines. Anyway in the examples by micro chip is the following.
Just checking I have this right, because I havnt found the info in C18, but in the 8051 compiler i use the bit that says
ADCResult+=(unsigned int) ReadADC();
would mean, it takes the result and keeps adding it together, in this case 16 times, so on second loop it would take the first result and add it to the second, then on the 3rd loop, it would take the result and add it to the total of the previous two results.
is that the same for all C including C18.
sorry I have really made this hard to understand!!!!
what I am trying to ask is does += mean it takes the total and keeps adding the new result to it?
In my head the question is clear but I always make a mess explaining
.
What I am doing is looking at there example and seeing how I can alter the macro's and function's to my own way. So far what I am doing is just writing raw register bits, for example
Once i get everything working that way, I will go about building my macro's and function's, I know its the long way round, but it is helping me to read and properly grasp the datasheet. (hopefully)
Code:
for(i=0;i<16;i++)
{
ConvertADC();
while(BusyADC());
ADCResult += (unsigned int) ReadADC();
}
ADCResult /= 16;
Just checking I have this right, because I havnt found the info in C18, but in the 8051 compiler i use the bit that says
ADCResult+=(unsigned int) ReadADC();
would mean, it takes the result and keeps adding it together, in this case 16 times, so on second loop it would take the first result and add it to the second, then on the 3rd loop, it would take the result and add it to the total of the previous two results.
is that the same for all C including C18.
sorry I have really made this hard to understand!!!!
what I am trying to ask is does += mean it takes the total and keeps adding the new result to it?
In my head the question is clear but I always make a mess explaining
What I am doing is looking at there example and seeing how I can alter the macro's and function's to my own way. So far what I am doing is just writing raw register bits, for example
Code:
/* Setup analog functionality and port direction */
ADCON1bits.VCFG0 =0; //Voltage ref set to AVDD
ADCON1bits.VCFG1 =0; //Voltage ref set to AVss
//The following code set's Anologue function on AN0-AN3 0b1011;
ADCON1bits.PCFG3 =1;
ADCON1bits.PCFG2 =0;
ADCON1bits.PCFG1 =1;
ADCON1bits.PCFG0 =1;
// The followings sets ANO-AN3 As inputs.
TRISAbits.RA0 =1;
TRISAbits.RA1 =1;
TRISAbits.RA2 =1;
TRISAbits.RA3 =1;
Once i get everything working that way, I will go about building my macro's and function's, I know its the long way round, but it is helping me to read and properly grasp the datasheet. (hopefully)