Timer

Status
Not open for further replies.

mrgobis

New Member
Hi,
I am trying to write a simple program with Timer 0 using C 18 compiler. Please have a look at the following code and the following error code and let me know where i am going wrong.

#include <p18f4520.h>
#include <timers.h>
#define DELAY 16000

void mian (void)
{
TRISC = 0x00;
T0CON = 0b11000111;

while(1)
{
PORTC =0xFF;
TMR0 = 0;

while ( TMR0 < DELAY)
{
}

PORTC =0x00;
TMR0 = 0;

while ( TMR0 < DELAY)
{
}
}
} // end

the following are the build errors

D:\PIC Projects\Loops2\LOOPS2.C:15:Error [1105] symbol 'TMR0' has not been defined
D:\PIC Projects\Loops2\LOOPS2.C:15:Error [1101] lvalue required

Please help me on this.

regards,
G.Nathan
 

Do you have to OPEN and CONFIG the timer with OpenTimer0 ??
MPLAB C18 Lib manual pg 58.

I am looking at the timer stuff myself.
 
Last edited:
TIMER O with PIC C 18

Hi,

Thanks for spotting the spelling error, i have read document on C18 Library. i am not sure how to open the timer and configure it. I have also tried many time. Please find the code below and please tell me where do i have to open the timer and configure.

#include <p18f4520.h>
#include <timers.h>
#define DELAY 160

void main (void)
{
TRISC = 0x00;
OpenTimer0( TIMER_INT_OFF & T0_8BIT & T0_SOURCE_INT & T0_PS_1_32 );

while(1)
{
PORTC =0xFF;
TMR = 0;

while ( TMR0 < DELAY)
{
}

PORTC =0x00;
TMR0 = 0;

while ( TMR0 < DELAY)
{
}
}
} // end code

following are the error message, It says TMR0 is not difined. Can some body tell me how to define the TMR0. I am sure i am making a school boy error here

D:\PIC Projects\Loops2\LOOPS2.C:13:Error [1105] symbol 'TMR' has not been defined
D:\PIC Projects\Loops2\LOOPS2.C:13:Error [1101] lvalue required

regards,
G.Nathan
 
The error states that TMR is not defined and I think you are reading it as TMR0. Change the line TMR=0 to TMR0=0 and all will be well. As you suspected, a schoolboy error and one I'm sure you won't repeat.

Mike.
 
Good all! i've been trying to design a code in assembly for 16f84a for digital clock, pls is there any body that can help me out there am new in assembly.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…