ckshivaram
Advanced Member level 6
- Joined
- Apr 21, 2008
- Messages
- 5,060
- Helped
- 2,150
- Reputation
- 4,306
- Reaction score
- 2,088
- Trophy points
- 1,403
- Location
- villingen (Germany) / Bangalore
- Activity points
- 30,088
Ok.. I will try this first..transmitting and receiving some data between two PIC18f using SPI would give you a clear understanding of SPI protocol
In that case, use all the resources you have and start working on them until you think you've earned proficiency in each of the units and then you can "glue" them together for your big project. :grin: And come back here when you need help on something. :smile:
#include<htc.h>
void init_adc();
unsigned int adc_read();
void main()
{
unsigned int adc_value;
init_adc();
TRISD = 0x00;
while(1)
{
adc_value=adc_read();
PORTD = adc_value;
}
}
void init_adc()
{
/* select channel 0, enable ADC */
ADCON0bits.ADON = 1;
/* Voltage reff is VDD, configure AN0 as analog */
ADCON1bits.VCFG0 = 0;
ADCON1bits.VCFG1 = 0;
//ADCON1 |= 0b1110;
/*2 x TAD, FOSC/32 */
ADCON2bits.ACQT0 = 1;
ADCON2bits.ADCS1 = 1;
TRISAbits.TRISA0 = 1; // input
ADCON2bits.ADFM = 0; // A/D result is left justified
}
unsigned int adc_read()
{
ADCON0 = 0x00;
ADCON0bits.ADON = 1; //turn on adc
ADCON0bits.GO_DONE = 1; //start converstion
while(GO_DONE); //wait for converstion to finish
ADCON0bits.ADON = 0; //turn off adc
return ADRESH;
}
since you are repeating ADC in a while loop, so i 'think' no need to turn off ADC in every reading...
Yes.as you can see im using left justified and discarding the 2 bits in ADRESL.. does it mean I am just like using 8bit adc resolution if I discard the 2bits of ADRESL?
shouldn't the main program/function (the main(){} block) come at the end, after all other subroutines and functions?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?