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.

timer1 flag bit sets?

Status
Not open for further replies.

Joe G

Member
I'm finally starting to learn C, (got a picket3 from santa) When, in my interrupt, I check for the timer1 flag
like this:

if (PIR1bits.TMR1IF=1) // Timer 1
PIR1bits.TMR1IF = 0;
ADC_Init();

the flag gets set????? what am I doing wrong? I'm using mplab with a pic18lf26k80 in C


I'm also using timer0, which is ok

thanks
 
Last edited:
You need to use double equals for comparison, so,

if (PIR1bits.TMR1IF==1) // Timer 1

And, assuming you only want to do the ADC if timer1 is set do,
Code:
if (PIR1bits.TMR1IF==1){ // Timer 1
    PIR1bits.TMR1IF = 0; 
    ADC_Init();
}

To keep formatting in your code type [code] before it and [/code] after.


Have fun,

Mike.
 
Last edited by a moderator:
Yep, that'll do it........fixed that oops quick,
thanks...

also, how do I do a sleep? in assembly I just write sleep I tried that and Sleep- still dosen't go to sleep, my pic just lies there wide awake ;)
 
You don't mention which compiler you are using but you should be able to drop into asm to do a sleep comand. something like,
Code:
    _asm sleep _endasm

or
    asm{
        sleep
    }

Check your compiler manual for how to do asm.

Mike.
 
If you put a sleep command in using assembler then I'd reccomend putting a nop (no operation) on the next line, as the next line is executed after the sleep command, before the chip does actually sleep.
 
thanks, that's what I did do, other wise like, as you stated it goes to the next line. I had completely forgotten I could use assembly in C. I'm actually starting to like C instead of assembly, My brain dosen't hurt as much when doing maths. I've been rewriting some of my projects in C for practice.

thanks again.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top