#include"pic.h"
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_ON & CPD_ON );
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000
#endif
#define LED GP1
//#define SW1 GP3
//#define SW2 GP2
//#define SW3 GP1
unsigned int i,j,count_on,result; //16 bit variable
unsigned int star_en,sol_min,sol_sec,sol_millisec,minutes,on_sec,sec_1,sec_2,off_min,on_sec,result; //16 bit variable
unsigned int read_adc(unsigned char channel);
void delay_in_seconds(unsigned char sec_del);
void delay(int del);
struct datax
{
unsigned LED_start_on:1;
unsigned BUZZER_start_on:1;
unsigned CHECK_on:1;
}
struct datax flags;
void interrupt isr(void)
{
if ((TMR1IF) && (TMR1IE)) // 30MS DELAY //
{
TMR1IF=0;
TMR1H = 0x8A;
TMR1L = 0xD0;
}
}
void main() // pic 16f676 MCLR ON & OCC 14.1V;TRICLE CHARGE 12.8V
{
CMCON=0x07; // disable the comparator
TRISIO=0b00010000;
GPIO=0x00;
ANSEL=0b00001000; // adc port select
ADCON0=0b0110000; // adc control register 0
GIE = 1;
PEIE = 1;
// 30 ms delay //
T1CON = 0x01;
TMR1IF = 0;
TMR1H = 0x8A;
TMR1L = 0xD0;
TMR1IE = 1;
INTCON = 0xC0;
TMR1ON=1; // timer-1 on
while(1)
{
LED=0;
delay_in_seconds(on_sec);
LED=1;
__delay_ms(50);
LED=0;
__delay_ms(20);
LED=1;
__delay_ms(100);
LED=0;
__delay_ms(20);
LED=1;
__delay_ms(200);
LED=0;
__delay_ms(20);
LED=1;
__delay_ms(100);
LED=0;
__delay_ms(20);
LED=1;
__delay_ms(50);
LED=0;
__delay_ms(20);
__delay_ms(500);
on_sec=read_adc(3); // ON SEC
}
}
unsigned int read_adc(unsigned char channel)
{
channel=channel<<2;
ADCON0=(channel+0b10000001);
__delay_us(30);
GO=1;
while(GO);
result=(ADRESH*256)+ADRESL;
return result;
}
void delay_in_seconds(unsigned char sec_del)
{
for(i=0;i<sec_del;i++)
{
for(j=0;j<100;j++)//for(j=0;j<997;j++)
{
delay(81);
}
}
}
void delay(int del)
{ while(del--);
}
[Code]
what problem with this code?
regards
Manoj