Programming/Nesting Order ???


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008
    Posts
    38

    Default Programming/Nesting Order ???

    Hi All,
    I've been dabbling for a few years with PBPro, but still find certain programming methods a challenge.

    My main question: Is there a 'preferred order' to layout programming code/loops/nesting within nests etc.

    For example, i might have a 16x2 LCD, a few buttons (or keypad), a few leds, switches or rotary encoder and/or a few external lines to the outside world.

    I wanted to know what is the best method to organise my code so everything is running smoothly.
    Quite often when i press buttons or spin a rotary encoder, my LCD won't update, or doing one thing will delay the operation of another and so on....

    I'd assume my buttons/keypad/rotary encoders should be HIGHer importance in looping, and the LCD, serout/control-lines out would be of lower importance?

    Obviously my loops need to be sorted in way from MOST important to LEAST important with repspect to running in realtime or at leisure.

    I know someone will say "use an interupt" but i haven't got that deep into using interupts yet...

    Thanx in advance,
    Marty.

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Your descriptions sound pretty sound.

    One thing I do is use flags to detect if an LCD needs updating or not. The setting and testing only take a few clock cycles, but save a lot. Another trick is to avoid updating the LCD too often. For instance, if your loop is going at 50Hz, there is no way you'll be able to read the display that fast. Anything much faster than about 10Hz is time wasted. You can set up a counter so you only update once every 5 loops or so.

    Take note that the LCD commands are very slow, and made even worse by the built-in delay. (Which was put there to increase success rates, accommodating a variety of LCD screens.) You may want to play with the LCD Declare's to see if you can reduce the delay times to make your loop faster. The more characters you send, the more the delay effects your overall loop time. You might even want to set up a test loop just to time how long it takes to make your LCD update; the information should help you make decisions.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gtvmarty View Post
    My main question: Is there a 'preferred order' to layout programming code/loops/nesting within nests etc.
    Yep...Your Order. You're the programmer. The order is up to you.

    For example, i might have a 16x2 LCD, a few buttons (or keypad), a few leds, switches or rotary encoder and/or a few external lines to the outside world.
    In my mind, the user comes first, everything else is secondary. You get stuck in a loop checking buttons and the LCD won't update and the user probably doesn't get any feedback that your button press has been recognized. Find something to make some feedback, blink the backlight on the LCD, blink an LED, add a small speaker and make it beep.

    I know someone will say "use an interupt" but i haven't got that deep into using interupts yet...
    It's the only way to go... Play with them. They're easier than you think...

  4. #4
    Join Date
    Jul 2008
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    Thanx for the info so far guys....

    I've since found (well hidden) in the back of the PB manual that i should be using for..next loops for delays instead of "pause 1000", otherwise i need to wait for the 1sec to elapse before my key's are read in etc (obviously missing keystrokes during that 1 second).
    That's a MAJOR part of my problem solved.

    Yep, i had been thru all the "flashing-LCD-by-writing-too-often-in-a-loop" problems ;-)


    I'm still not keen on interupts ;-) but am finding (with lotsa fiddling) that i can nest loops within loops nicely now, and i do have priorities to loop more often for keys than LCD writes etc.

    Thanx again,
    Marty.

Similar Threads

  1. Reverse Bit Order?
    By Art in forum General
    Replies: 3
    Last Post: - 23rd January 2010, 22:52
  2. In what order do we construct a PBP program?
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2008, 08:18
  3. Large-ish PCB order...others wanted...
    By skimask in forum Off Topic
    Replies: 0
    Last Post: - 16th June 2006, 02:43
  4. How can i control pic input pins order?
    By tanero in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th August 2005, 12:46
  5. bit order inverting
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th July 2005, 03:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts