#include <stdio.h>
#include <stdlib.h>
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#include <xc.h>
#define _XTAL_FREQ 4000000
int Count,Timer_ON,eight,fourteen,twel,ten,result;
int sec,min;
void main()
{
ANSEL = 0x14;
ADCON0 = 0x09; // Turn on the A/D Converter with AD2 As channel Select
CMCON = 0x07; // Shut off the Comparator, so that pins are available for ADC
VRCON = 0x00; // Shut off the Voltage Reference for Comparator
TRISIO = 0xEF;
while(1)
{
if(GP5==0)
{
while(GP5==0);
GO_nDONE=1;
__delay_ms(10);
while(GO_nDONE==1);//wait for conversion completion
__delay_ms(100);
result = ((ADRESH<<8)+ADRESL);
GP4=1;
for(sec=0;sec<=result;sec++);
{
__delay_ms(1000);
}
GP4=0;
}
}
}