Connect with us

Led flashing for one second using Mikro c

Discussion in 'Microcontrollers, Programming and IoT' started by Rajinder, Mar 10, 2016.

Scroll to continue with content
  1. Rajinder

    Rajinder

    493
    9
    Jan 30, 2016
    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
     

    Attached Files:

  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,012
    2,506
    Nov 17, 2011
    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.
     
  3. Rajinder

    Rajinder

    493
    9
    Jan 30, 2016
    Ok will do.
    Thanks.
     
  4. Rajinder

    Rajinder

    493
    9
    Jan 30, 2016
    Here is the code again.
     

    Attached Files:

  5. Arouse1973

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    I can't find the PIC18F54 on Microchips website, is the part number correct?
    Adam
     
  6. Rajinder

    Rajinder

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

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    Where are you setting up the interrupts? I can't see from your code, can you explain?
    Adam
     
  8. Rajinder

    Rajinder

    493
    9
    Jan 30, 2016
    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.
     
  9. Arouse1973

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    Ok yes see it now, missed it first time.
    Adam
     
  10. Arouse1973

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    How are you telling the compiler that the routine "Interrupt" is your 0x08 interrupt address? I am not familiar with Micro C.
    Adam
     
  11. Sadlercomfort

    Sadlercomfort Ash

    424
    55
    Feb 9, 2013
    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.
     
  12. Sadlercomfort

    Sadlercomfort Ash

    424
    55
    Feb 9, 2013
    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
     
  13. Rajinder

    Rajinder

    493
    9
    Jan 30, 2016
    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.
     
  14. Sadlercomfort

    Sadlercomfort Ash

    424
    55
    Feb 9, 2013
    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.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-