Maker Pro
Maker Pro

Led flashing for one second using Mikro c

Hi All,
I am currently writing some code in C on Mikro C platform. The program is supposed to doba led chaser on port D of pic18f54k20, I am using debug PCB on pickit 3. Then it's supposed to flash led on port c bit 0 every second. It does the led chaser routine but never goes into the interrupt.
I have attached the code, any help would be appreciated. Note in the interrupt routine I gave truedt both intcon 0x20 and intcon 0x02 to clear the interrupt flag.
Thanks in advance.
Rajinder
 

Attachments

  • IMG_20160310_123002907.jpg
    IMG_20160310_123002907.jpg
    128.9 KB · Views: 153

Harald Kapp

Moderator
Moderator
The code is almost illegible in the Jpeg.
Please use the Insert...->Code function (docuemnt symbol on top, left of teh diskette symbol) to paste the code in a well readable format.
 
I set up, the prescaler, timer0 to be in 8 bit mode, I then set the intcon register to 0xA0, enable global interrupts and enable timer0 interrupt. It's in the main code.
 
How are you telling the compiler that the routine "Interrupt" is your 0x08 interrupt address? I am not familiar with Micro C.
Adam
 
Most of your code looks fine to me.
Have you tried putting "Timer0_ISR" at the start of the interrupt routine like so:

Code:
void interrupt Timer0_ISR(void)
{
}

I also noticed your using TMR0L, I'm not familiar with setting up 8-bit or 16-bit modes.. but I assume if you've set it to 8-bit you would just use TMR0.
 
I would also check that your prescaler is correct, I used to use this formula.

Freq. out = Freq. osc / [prescaler * (256 - TMR0) * count]


Maybe set Prescaler to 1/1 and create a count for 31250. I might be wrong :eek:


Freq. out = 8MHz / [ 1/1 * (256 - 0) * 31250 ]

Freq. out = 8MHz/256 * 31250

Freq. out = 1Hz
 
Ok, thanks will have a look. I tried just lighting an led in the interrupt, first thing. To see if the interrupt was being serviced, but it didn't light. I think the issue may be that, not sure. I am new to Mikro c.
 
There's alot of things which can go wrong when writing code, I'm fairly new to C aswell.. only be writing C since august.

Generally I've found that writing small chunks of code first can help, like you said lighting the LED first is a good idea.

I would try lighting the LED without an interrupt first, so you know your ports are setup correctly.
 
Top