Led flashing for one second using Mikro c

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
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.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Here is the code again.
 

Attachments

  • ledflashing.txt
    1.7 KB · Views: 81

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
I can't find the PIC18F54 on Microchips website, is the part number correct?
Adam
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
It's a pic 18f45k20. The one used on the debug express that comes with pic kit 3. Sorry for the wrong info.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Where are you setting up the interrupts? I can't see from your code, can you explain?
Adam
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
How are you telling the compiler that the routine "Interrupt" is your 0x08 interrupt address? I am not familiar with Micro C.
Adam
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
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.
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
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
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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.
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
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