pnjbtr
Full Member level 5
- Joined
- Feb 11, 2008
- Messages
- 255
- Helped
- 99
- Reputation
- 198
- Reaction score
- 89
- Trophy points
- 1,318
- Activity points
- 2,815
This program is for PIC16F676 in micro c compiler.
I am facing problem,when switch is pressed for time delay, adc module become inactive
and stop working.
And when time delay ends adc module start working.
Code:
sbit LED1 at RC0_bit; // 1
sbit LED2 at RA2_bit; // 2
sbit LED3 at RC2_bit; // TIMER DISPLAY
sbit SWITCH at RA3_bit; //TIMER SWITCH
int Adc; // Save analog Data
void Read_Adc()
{
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
ADC = (ADRESH << 8) + ADRESL; //10 bit res
}
void main()
{
TRISA=0b11011001; //SET PORT A AS INPUT
TRISC = 0b11000000; //SET PORT C AS OUTPUT
PORTA=0X00;
// portc=0b11111110;
if (porta.f3==0){ // TIMER SWITCH PRESSED
portc.f2=0; //off during delay
delay_ms(5000);
portc.f2=1; //on at delay end
}
else (portc.f2=1); // if switch, not pressed then instant on.
while(1)
{
CMCON=7; //DISABLE COMPARATOR
ANSEL=0b00000001;
ADCON1=0b01100000; //AD CONVERSION CLOCK SPEED=/64
ADCON0=0b10000011;//SELSECT AN0, RIGHT JUSTIFIED,VREF=VDD and bit1, ADON,fosc/32(bit6,7).bit1_godone=off
//10 bit=5/1023=0.00488
Read_Adc(); // Read Analog AN0
if (Adc > 614) { //3v
//==========================================
Portc.f0 = 1; //1st
porta.f2 = 1; //2nd
}
//============================================
if (Adc<512) // 2.498v
{
portc.f0 = 0;
delay_ms(5);
}
if (Adc>532) //2.596v
{
portc.f0 = 1;
}
//==================================================
if (Adc < 426) { // 2v
porta.f2 = 0; //2nd led off
}
if (Adc > 441 ) { // 2.15v
porta.f2= 1; //2nd led on
}
} //end of while
} // end of main
and stop working.
And when time delay ends adc module start working.