IF...THEN inside a Loop


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default If...then

    Sorry - I made a silly mistake in the code I posted. The case where X=1 shows my error.

    However, the real code that was/is causing trouble was for a larger range of X and included '>=', '<='.

    My poor attempt to simplify the real problem failed!

    I'll tidy up the real code and post it soonest.

    Thanks for your input.

    Regards Bill legge

  2. #2
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default PIC BASIC PRO LONG and IF..THEN

    Sorry for my earlier muddled post. I've done some more work on the problem and have pinned down my difficulty.

    I am compiling using PBPL and using a graphic LCD with 4 driver chips.
    The GLCD is 240 pixels wide and I need to activate the Chip Selects as the display sweeps along:

    0 to 63 CS1
    64 to 127 CS2
    128 to 191 CS3
    192 to 239 CS4

    The chip selects are connected to PORTB and my code is:

    Code:
    clear
    DEFINE OSC 40	' Run on PIC18F8722, HSPPL
    ADCON1	= $0F	' Set PortA to digital
    
    TRISB=0               ' Make Port B outputs
    PORTB=0	             ' clear the port
    
    X	var	byte
    
    Loop:
    PORTB=$0		
    for X = 0 to 239
    	if X<64 then PORTB=$01
    	if X>63 and X<128 then PORTB=$02
    	if X>127 and X<192 then PORTB=$04
    	if X>191 then PORTB=$08		
    	pause 5
    next X
    goto Loop
    If I compile using PBP it works properly and the chip selects turn on/off as X goes from 0 to 239.

    If I compile using PBPL it does not work.

    I need to use the LONG compilation. Any idea what is going wrong?

    Regards Bill Legge

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Bill,

    No idea what's wrong at this point.
    But I did run your program as is, no changes, on an 18F252.

    Works the same with either PBPW or PBPL.

    You can also do the same thing like this ...
    Code:
    for X = 0 to 239
      PORTB = DCD (X >> 6)
      pause 5
    next X
    Added:
    So that it only affects those 4 pins, you could do this ...
    Code:
    PORTB = (PORTB & $F0) | DCD (X >> 6)
    Last edited by Darrel Taylor; - 11th July 2009 at 04:12. Reason: Added:
    DT

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Silly question.
    PM or MPASM ?
    Or does it matter?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default IF...then pbpl

    I'm using MPASM because the PBP does not support the PIC18F8722

    Regards Bill Legge

  6. #6
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default If...then pbpl

    Darrel T

    Thanks very much for the code using DCD. It works fine with both PBP and PBPL.

    I'd still like to find out why the IF...THEN won't work with PBPL?

    Regards Bill Legge
    In Australia

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. newbie Q - edge detection?
    By RMCRAVEN in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 9th October 2006, 08:20
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

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