Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 if(++count == adcVal) //do something
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 /******************************************************************** | Tutorial 11C - PIC12F675 ADC Demo | ******************************************************************** This program shows how to use the ADC (Analog-to-Digital converter) pin on a PIC12F675. This tutorial will work with the Hi-Tech C compilers. iBoard connection as follows: PIN Module ------------------------------------------- GPIO0 LED1 GPIO1 LED2 GPIO2 LED3 GPIO3 Switch (Reset) GPIO4 10K Potentiometer ********************************************************************** | [url]WWW.PICCIRCUIT.COM[/url] (C) Copyright 2010 | ********************************************************************** | This source code may only be used with PICCIRCUIT products only. | | If you distribute the source code, the source code must have this | | entire copyright and disclaimer notice. No other use, reproduction | | or distribution is permitted without written permission. | ********************************************************************** | Program: main.c | | Version: 1.0 | |-------------------------------------------------------------------*/ #define XTAL_FREQ 4MHZ /* Crystal frequency in MHz */ #include <pic.h> #define GPIO,05h #define ontime GPIO0 #define offtim GPIO1 #define relay GPIO2 #define led GPIO4 unsigned int ADC_Value=0,i,j,k,l,m; void delay(unsigned int j); // ============================================================ // Configuration Bits // ============================================================ __CONFIG(INTIO & WDTDIS & UNPROTECT & BORDIS & MCLREN); /************************************************************** Initialise System **************************************************************/ void delay(unsigned int j) { for(j=0;j<6000;j++); for(k=0;k<6000;k++); for(l=0;l<6000;l++); } /************************************************************** Main Program /**************************************************************/ void main(void) { TRISIO = 0b00000011;//Set GP0-GP1 as i/p GP2-GP5 as o/p ANSEL = 0b00110011; //Frc, GPIO0(AN0)& GPIO1(AN1) Analog input CMCON = 0x07; //Turn off analog comparator INTCON = 0x0B; while(1) { ADCON0 = 0b10000000; //Channel 03 (AN3), A/D converter ON GODONE = 1; //Start Conversion while(GODONE){} //Wait for conversion complete m=0.01*(ADRESH+(ADRESL<<8)); // 10 bit value converted into 0-10 scale relay=1; delay(m); delay(m); delay(m); relay=0; delay(m); delay(m); delay(m); delay(m); } }