Thread: Dropping from a ucCount to a while loop

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    4

    Dropping from a ucCount to a while loop

    Hi All

    I am currently programming a Pickit board trying to trace a "missing tooth" ( interrupt) on the board.

    My first task is to flash the middle LED 4 times at a rate of 1 flash per second - done.

    I have code to follow the interrupt which works in a completely seperate program - great

    what I am struggling with is when i flash the LED 4 times at once per second i want to then jump to my LED flashing following the interrupts but my code just stops! I have set up by code with "firstrun" to ensure it only counts the 8 times once and stops. Can i not just create a true statement as below which then allows its to loop following the interrupts.

    at the moment my led flashes 4 times half a second on half a second off 4 times and then does nothing. I am sure I am doing something simple wrong but I am pulling my hair out now!! any one notice something I am doing wrong ? I think when it drops into first run my code is stopping then not moving back into main.

    I have attached my code as attachments as it it will be a bit messy otherwise...
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,037
    In embedded programming it is very common to have an endless loop most often in the main function.

    Likely your program is ending because I see nothing the stops it from ending.

    Edit: In your code, I would try adding an endless loop after the line below.
    Code:
    bSecondTest = TRUE;
    Edit2: Please try to use spaces instead of tabs in your code; mixing both of them makes your code look bad.

    Tim S.
    Last edited by stahta01; 07-16-2017 at 10:26 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    813
    We ask all posters to display their code in Code Tags instead of an attached file. Please read the Forum Rules FAQ.

    Also main() should only be defined to return an "int", not "void" in all cases!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,660
    Quote Originally Posted by rstanley View Post
    Also main() should only be defined to return an "int", not "void" in all cases!
    I'm guessing the OP is programming a "free standing" environment, in which case any so long as main (or whatever the documented entry point) is defined correctly for that environment, it's all good.
    c - Is there a meaningful distinction between freestanding and hosted implementations? - Stack Overflow


    @OP
    Code:
    void interrupt high_priority High_isr(void)
    {
         while(bSecondTest == TRUE)
    This is flat out wrong.
    An ISR needs to execute as little code as possible, then "get the hell out of Dodge(tm)".
    A while loop that loops forever will prevent your mainline code from ever running again.

    What happens if you fall off the end of main()?

    > I think when it drops into first run my code is stopping then not moving back into main.
    That seems about right.
    > while(TRUE) //Loop once
    Erm, no, that's loop forever.
    Which in the absence of any break statements inside the loop, it really means forever.

    Most of the comments don't really agree with what the code is doing.
    It's hard to figure out your real intent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PPP Dropping in and out
    By Hodor in forum Tech Board
    Replies: 0
    Last Post: 02-11-2014, 12:06 AM
  2. just dropping by...
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-24-2005, 12:09 PM
  3. Dropping a deuce
    By prog-bman in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-01-2005, 10:06 PM
  4. Gas dropping?
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 06-10-2004, 06:25 AM

Tags for this Thread