Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ADC_Init(void){
- //Configure Inputs
- TRISA |= 0x01;
- ANSEL |= 0x01;
- ADCON0 = (1<<0) | (0<<2); //Enable ADC and select channel 0
- ADCON1 = (0<<4) | (0<<5); //Set both references to PIC supply
- ADCON2 = (0<<0) | (7<<3) | (0<<7); //Use 20 acquisition cycles and FOsc/2, left justified
- }
- void ADC_StartConv(void){
- ADCON0 |= (1<<1);
- }
- unsigned int ADC_CheckConv(void){
- if(ADCON0 & 2) return 1;
- else return 0;
- }
- void ADC_WaitForConv(void){
- while(ADC_CheckConv());
- }
- unsigned char ADC_GetConv(void){
- return ADRESH;
- }
- void main(){
- ADC_Init();
- unsigned char Conv = 0;
- //Continuously convert!
- while(1){
- ADC_StartConv();
- ADC_WaitForConv();
- //Conv contains the converted value
- Conv = ADC_GetConv();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment