Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What is this program doing?

Status
Not open for further replies.

friskyy

New Member
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.
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
}
}
}
 
Download the instruction set summary and the data sheet for your PIC and look it up yourself, both and much more information is available freely from Microchip.
 
Download the instruction set summary and the data sheet for your PIC and look it up yourself, both and much more information is available freely from Microchip.

Kinda hard to do when the code is written in PIC C while the instruction set summary in the PIC datasheet is in PIC ASM. ;)
 
oops, that was kind of silly of me Jon. Look at the #include file for that PIC, it'll explain what the registers/peripherals are at least reading the code itself isn't hard. Can't believe I didn't notice it was C =\
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top