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.

simple question about timer0 PIC18F

Status
Not open for further replies.

simplicio

Junior Member level 2
Joined
Sep 1, 2004
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
154
pic18 timer0

don't I get to always understand the reason of the delay in bursting the timer0 after the reset? I am used PIC18F452


//My program

void main() { //função principal do programa
T0CON = 0b10000110; //configura timer modo 16 bits, com prescaler
TMR0L = 0Xf6; //carrega valores de contagem
TMR0H = 0XC2; //carrega valores de contagem
TRISd = 0; // PORT B is output
PORTd = 0xFF; // Initialize PORT B

do {
if (intcon.tmr0if == 1) { //se o flag de estouro do TIMER0 for igual a 1, então
PORTd = ~PORTd; // inverte o estado do portb
TMR0L = 0xF6;
TMR0H = 0XC2;
INTCON = 0b00000000; // Seta T0IE, apaga flag de entouro do TIMER0
//para uma nova contagem
}
} while(1); // loop
}
 

timer0 pic18f

Hi,
Your subroutine is not an interrupt subroutine !!!

Put your "if" test in an interrupt subroutine (look at comiler documentation for correct syntax).Don't forget TMR0 interrupt flag must cleared at the end of the interrupt routine.

Wich compiler did you use ?

CD:D
 

pic18f timer0

I use MikroC
always in the first time that resset is long to invert the portB, later it works perfect
I don't know because it happens that
 

timer0 pic18

simplicio said:
I use MikroC
always in the first time that resset is long to invert the portB, later it works perfect
I don't know because it happens that


Just read this :

/*
* Project name:
TMR0 (Simple 'Hello World' demonstration of interrupt handling)
* Copyright:
(c) Mikroelektronika, 2005.
* Description:
This code demonstrates using interrupts in mikroC. Program turns on/off
LEDs on PORTB approximately each second.
* Test configuration:
MCU: P18F452
Dev.Board: EasyPIC4
Oscillator: HS, 08.0000 MHz
Ext. Modules: -
SW: mikroC v7.0
* NOTES:
None.
*/

unsigned cnt;

void interrupt() {
cnt++; // Increment value of cnt on every interrupt
TMR0L = 96;
INTCON = 0x20; // Set T0IE, clear T0IF
}//~

void main() {
T0CON = 0xC4; // Assign prescaler to TMR0
TRISB = 0; // PORTB is output
PORTB = 0xFF; // Initialize PORTB
TMR0L = 96;
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0; // Initialize cnt

do {
if (cnt == 400) {
PORTB = ~PORTB; // Toggle PORTB LEDs
cnt = 0; // Reset cnt
}
} while(1); // endless loop
}//~!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top