Skip to content

Instantly share code, notes, and snippets.

@technoburst
Created April 25, 2013 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoburst/5457806 to your computer and use it in GitHub Desktop.
Save technoburst/5457806 to your computer and use it in GitHub Desktop.
Sample program to demonstrate the use od PIC16F877A ADC library
/* *****************************************************************************
* File : PIC16F877A_ADC_lib_example.c
* Created on : April 25, 2013, 9:39 AM
* Description : Sample program to demonstrate the use od PIC16F877A ADC library
* Notes : _XTAL_FREQ macro is defined in the project settings
* Author : Anil C S
* Website : www.technoburst.net
* Email : anil@technoburst.net, technoburst@gmail.com
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
// PIC16F877A Configuration Bit Settings
#include <xc.h>
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include "adc.h"
/*
*
*/
void main(void)
{
TRISD = 0b00000000; //Setting PORTD as output port
PORTD = 0b00000000; //Initializing PORTD
ADCSetClock(FOSC_div_2);
ADCSetResultFormat(RightJustified);
ADCConfigurePorts(0);
ADCPowerOn();
ADCSelectChannel(0);
while(1)
{
if(ADCReadChannel()>512)
PORTD = 0xff;
else
PORTD = 0x00;
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment