Vizier87
Active Member
Hi guys,
Like declared before, I've just started to use MikroC (only for a week already) instead of ASM and I already think it's pretty comfortable for an impatient person like me.
Just a few more tweaks of C language itself and hopefully I can be good at this!
So...here's my problem (my Timer0 program to blink an LED, not using the normal Delay_ms directive) for my PIC18F4455:
I'm using a 20 Mhz crystal, so I suppose the delay generated should be 20Mhz/(4x65535x64)=1.19211109 Hz..
But what I got is a PORTD which turns on all the time without any flicker.
I suppose it has to do with the C language.
Any help is appreciated.
Vizier87
Like declared before, I've just started to use MikroC (only for a week already) instead of ASM and I already think it's pretty comfortable for an impatient person like me.
Just a few more tweaks of C language itself and hopefully I can be good at this!
So...here's my problem (my Timer0 program to blink an LED, not using the normal Delay_ms directive) for my PIC18F4455:
Code:
[COLOR="red"]void main() {[/COLOR]
TRISD=0; // PORTD as output
IPEN_bit=1; // to enable all high priority interrupt
GIE_bit=1; // enable interrupt globally
T0CON= 0B00000101; // 16-bit timer,internal clock, +ve edge,1:64 Prescale
[COLOR="blue"]while (1){[/COLOR] //Loop starts
TMR0H=0X00; //reset both registers
TMR0L=0X00; //
TMR0IF_bit=0; //clear the Timer0 interrupt flag
TMR0ON_bit=1; //start the Timer
if (TMR0IF_bit=1); //wait for the Timer0 interrupt flag bit to go HIGH
TMR0ON_bit=0;
PORTD=~PORTD; //toggle PORTD
[COLOR="blue"]}[/COLOR]
[COLOR="red"]}[/COLOR]
I'm using a 20 Mhz crystal, so I suppose the delay generated should be 20Mhz/(4x65535x64)=1.19211109 Hz..
But what I got is a PORTD which turns on all the time without any flicker.
I suppose it has to do with the C language.
Any help is appreciated.
Vizier87
Last edited: