pic16f676

Thread Starter

reema paul

Joined Jun 28, 2010
12
hello all,
i was having doubt in generation of 50hz pulse using pic16f676.
it will be nice if i can get the code.
also even after configuring pin 3(RA4) as o/p port..its giving me an o/p of 2.5 volts..i.e jumping between 5 and 0 v.how can i make it either low or high?is it associated with any other function?
expecting a quick reply!
thanks
 

Thread Starter

reema paul

Joined Jun 28, 2010
12
#include "htc.h"
unsigned char Dutycnt=0;
unsigned int SV,BV,CT,SV0=0,BV0=0,CT0=0,x=0;
void init_timer(void)
{
TMR1H=0X0b;
TMR1L=0Xdc;
T1CON=0X00;
T1CKPS1=1;
T1CKPS0=1;
TMR1IE=1;
PEIE=1;
GIE=1;
}
void interrupt timer_isr(void)
{
TMR1ON=0;
if(RC4==1)
{
x++;
if(x==2)
{
x=0;
RC4=!RC4;
}
}
if(RC3==1)
{
x++;
if(x==2)
{
x=0;
RC3=!RC3;
}
}
TMR1IF=0;
TMR1H=0X0B;
TMR1L=0XDC;
TMR1ON=1;
}
void init_a2d(void)
{
ADCON0=0x81;
ADCON1=0x00;
ANSEL=0X07;
}
unsigned int read_a2d(void)
{
unsigned int adc;
ADCON0=0x83;
while(ADCON0==0x83);
adc=ADRESL+(ADRESH*256);
return(adc);
}

void main(void)
{
unsigned int i;
ANSEL=0X07;
CMCON=7 ;
TRISA=0X07;
TRISC=0X00;
PORTC=0X00;
PORTA=0X00;
init_a2d();
init_timer();
while(1)
{
CHS0=1;
CHS1=0;
CHS2=0;
BV=read_a2d();
if(BV>=615)//greater than equal to 14v
{
/*RC1=0;
RC2=1;
RC4=0;
*/
RA4=0;
RC4=0;
RA5=0;
RC3=1;
TMR1ON=0;
}
if(BV<=448)//less than 10v
{
//RC2=0;
//RC1=1;
//RC4=0;
RA4=0;
RC3=0;
RC2=1;
TMR1ON=0;
}


if(BV>448&&BV<=483)//buzzer between 10v n 10.75v
{
//RC2=0;
//RC1=0;
RA4=0;
RC4=1; //BUZZER
TMR1ON=1;
}
else
RC4=0;
RA4=0;
TMR1ON=0;
//if(BV>702)
//BV=702;
}
BV0=BV;
}
}
********************EOP************************

THOU HAVE MADE RA4 ZERO THROUGHOUT,STILL O/P REMAINS AT 2.5V N OSCILLOSCOPE GIVING SQUARE PULSES!
 
Last edited:
Top