Dear All,
Could someone explain line by line what this program is doing? Iam new to programming and I am using it as a sample, but don't understand what most of the statements are doing.
Could someone explain line by line what this program is doing? Iam new to programming and I am using it as a sample, but don't understand what most of the statements are doing.
Code:
#include <htc.h>
__CONFIG(UNPROTECT & BORDIS & PWRTEN & WDTDIS & INTIO &
MCLREN & FCMDIS & IESODIS);
#define _XTAL_FREQ 8000000
void init(void)
{.
// Configure Ports directions: 1=input, 0=output
TRISD = 0x00;
TRISC = 0xFF;
TRISA = 0xFF;
// 8Mhz Internal Clock
OSCCON = 0b01110000;
// Turn off comparators
CMCON0 = 0x07;
//Turn on ADC
ANSEL = 0b00000001; // select AN0 as an analogue channel (RA0)
ADCON1 = 0b01010000; // select A/D conversation clock Fosc/16
ADCON0 = 0b00000001; // left justified, Vss and Vdd as refs, AN0 is on
// Clear PortD
PORTD = 0x00;
// PWM Setup
PR2 = 0x9A;
CCP2CON = 0b00001100; //capture /compare/pwm module
CCPR2L = 5;
TMR2ON = 1;
}
unsigned int ADCval;
void main(void)
{
init();
RD7 = 1;
while (1){
if(GODONE == 0){
ADCval = ADRESH ;//0-1023 //A/D result high register
ADCval = ADCval >> 2;
CCPR2L = ADCval;
GODONE = 1; // Start the next conversion
}
}
}