elrayes
Full Member level 5
- Joined
- Jun 3, 2008
- Messages
- 244
- Helped
- 20
- Reputation
- 40
- Reaction score
- 7
- Trophy points
- 1,298
- Location
- Egypt/Canada
- Activity points
- 2,777
c18 timer 0
Hi all
I just want to use timer0 in PIC18F4550 and really i'm tired of reading and trying, beside i'm a very bad programmer, so try to help me in this code, I'm using MPLAB C18 compiler, this code is used to light some LED's on PORT D when the timer expires, i used ISR to implement all this, the code building is fine and downloaded on the target but the MCU isn't working:
#include<p18f4550.h>
#include<stdlib.h>
#include<timers.h>
#pragma interrupt high_isr
#pragma interruptlow low_isr
void init_int(void)
{
//configuring interrupts
INTCON = 0xA0;
INTCON2 = 0x04;
}
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
#pragma code
#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{
_asm goto low_isr _endasm
}
#pragma code
#pragma interrupt high_isr
void high_isr(void)
{
if(INTCONbits.TMR0IF == 1)
{
INTCONbits.TMR0IF = 0;
PORTD = 0x0f;
}
}
#pragma interruptlow low_isr
void low_isr(void)
{
}
#pragma code
int x = 0x0000;
void main(void)
{
TRISD = 0x00;
LATD = 0x00;
OpenTimer0( TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_8);
WriteTimer0(0x0000);
while(1)
{
high_isr();
}
}
hope someone could solve this.
thanks
Hi all
I just want to use timer0 in PIC18F4550 and really i'm tired of reading and trying, beside i'm a very bad programmer, so try to help me in this code, I'm using MPLAB C18 compiler, this code is used to light some LED's on PORT D when the timer expires, i used ISR to implement all this, the code building is fine and downloaded on the target but the MCU isn't working:
#include<p18f4550.h>
#include<stdlib.h>
#include<timers.h>
#pragma interrupt high_isr
#pragma interruptlow low_isr
void init_int(void)
{
//configuring interrupts
INTCON = 0xA0;
INTCON2 = 0x04;
}
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
#pragma code
#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{
_asm goto low_isr _endasm
}
#pragma code
#pragma interrupt high_isr
void high_isr(void)
{
if(INTCONbits.TMR0IF == 1)
{
INTCONbits.TMR0IF = 0;
PORTD = 0x0f;
}
}
#pragma interruptlow low_isr
void low_isr(void)
{
}
#pragma code
int x = 0x0000;
void main(void)
{
TRISD = 0x00;
LATD = 0x00;
OpenTimer0( TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_8);
WriteTimer0(0x0000);
while(1)
{
high_isr();
}
}
hope someone could solve this.
thanks