Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! 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

Newbie level 6
Joined
Nov 11, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,378
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++ ;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top