Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC4550 frequency counter problem

Status
Not open for further replies.

sawula

New Member
I am trying to build a humidity sonsor using HS1101 and 555 timer. The humidity is calculated based on the freuency. And I found several coding example and combiled them to find the frequency first using Mikroc pro. But when I run that in the Proteus nothing displays on the virtual terminal. But the serial communication is working. The entire codings are posted below.


Can any one Please help me! It's an urgent matter!

Thank you

char error;
void Comm_Write(unsigned char *s);
void interrupt(void);
void Long2str(void);

void main( void)
{
ADCON1 |= 0x0f; // disable analog inputs
error = Soft_UART_Init(&PORTA, 4, 3, 9600, 0); // Initialize Soft UART at 9600 bps rx tx
TRISB.B2 = 1 ; //RB2 interrupt pin as input
T0CON = 11001000;
INTCON2 |= 10010000; //interrupt on rising edge
Delay_ms(2000);
Comm_Write("Serial OK"); //Check serial

do
{
cntr = 0 ; // clear counters
ovrflw = 0 ; // T0IF, INTF and GIE enabled
INTCON = 10100000 ; // T0IF, INTF and GIE enabled

while(ovrflw < 39063) ; // wait 1 second : 39062.5 = 40 000 000 / 4 / 256, rounded up 40MHz crystal
INTCON.GIE = 0 ; // stop all interrupts
Long2Str() ;
Comm_Write(str) ; // write string
} while( 1);
}

void interrupt(void)
{
if(INTCON3.INT2IF)
{ /* * RB2 interrupt */
cntr++ ; // inc. transition counter
INTCON3.INT2IF = 0 ; // clear interrupt flag to enable next call
}
else if(INTCON.TMR0IF)
{ /** TIMER 0 overflow */
ovrflw++ ; // inc. overflow counter
INTCON.TMR0IF = 0 ; // clear interrupt flag to enable next call on overflow
}
}

void Long2str(void)
{
unsigned char i, j ;
if(cntr == 0)
{
str[0] = '0' ;
str[1] = 0 ;
}
else
{
str[0] = 0 ;
i = 0 ;
while(cntr > 0)
{
for(j = i + 1 ; j > 0 ; j--)
{
str[j] = str[j - 1] ;
}
str[0] = cntr % 10 ;
str[0] += '0' ;
i++ ;
cntr /= 10 ;
}
}
}

void Comm_Write(unsigned char *s)
{
while(*s)
{
Soft_Uart_Write(*s) ;
s++ ;
}
}
 

Attachments

  • Image 1.png
    Image 1.png
    131.3 KB · Views: 214
  • humiity.zip
    197.5 KB · Views: 134
Status
Not open for further replies.

Latest threads

Back
Top