PicBasic Pro Math Problem??


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Location
    Vancouver
    Posts
    2

    Default PicBasic Pro Math Problem??

    Hello All....


    It's been a while since I have done any coding, and I'm stumped as to the problem, I'm sure it's a math problem, or an array problem.

    The following code is where I'm having the problem:

    @ DEVICE pic16F648A, HS_OSC
    '@ DEVICE pic16F648A, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F648A, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F648A, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F648A, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F648A, BOD_ON
    ' Brown-Out Detect
    '@ DEVICE pic16F648A, LVP_ON
    ' Low-Voltage Programming
    @ DEVICE pic16F648A, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE pic16F648A, PROTECT_OFF
    ' Program Code Protection

    DEFINE OSC 20
    DEFINE LCD_DREG PORTA
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 1
    DEFINE DEBUGIN_REG PORTB
    DEFINE DEBUGIN_BIT 1
    DEFINE DEBUGIN_BAUD 9600
    DEFINE DEBUGIN_MODE 1

    CMCON = 7 'set PORT A to Digital
    TRISA = %00000000
    TRISB = %00000000
    clear
    Pause 2000 'Wait for LCD to startup
    Lcdout $FE,1 'Clear Display
    high PORTB.0 'Turn LCD backlight OFF
    myVar VAR byte[10] 'Array for inbound serial data
    X VAR BYTE 'Holds "I" start position
    FL VAR word
    ID VAR word

    Begin:
    debugin [STR myVar\10] 'I010010101001010 Data string

    FOR X = 0 TO 9
    IF myVar[X] = "I" THEN Sort ' Look for "I"
    NEXT X
    GOTO BEGIN

    Sort:
    low PORTB.0 'Turn LCD backlight ON

    lcdout $FE,1,"String=",myvar[2]
    lcdout $FE,$C0,myvar[3],myvar[4],myvar[5],myvar[6],myvar[7],myvar[8],myvar[9]
    'The above line outputs the correct string
    Pause 2000

    FL = 0
    fl = myVar[5]
    fl = FL + (myVar[4]*10)
    fl = fl + (myVar[3]*100)
    FL = fl + (myVar[2]*1000)
    lcdout $FE,1,"FL=",dec4 fl 'Output to LCD
    'The above line output is wrong, it should be 0100
    ID = 0
    ID = myVar[9]
    ID = ID + myVar[8]*10
    ID = ID + myVar[7]*100
    ID = ID + myVar[6]*1000
    Lcdout $FE,$C0,"ID=",dec4 ID 'Output to LCD
    'The above line output is wrong, it should be 1010
    pause 5000
    High PORTB.0 'Turn LCD backlight ON
    Lcdout $FE,1 'Clear the LCD
    GOTO Begin

    END

    Any help would be muchly appreciated.

    Thanks in advance.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Glen,

    It might help for us to know what the symptoms are, and what it's supposed to be doing.
    <br>
    DT

  3. #3
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    The solution should be easy:

    You want to convert an ASCII-string to a decimal number.

    You forgot, a ASCII-number has not the value from 0 to 9, but from $30 to $39. So you must truncate some bits !

    Try FL=...(myvar[...] & $F) * 10... !!!!
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  4. #4
    Join Date
    Mar 2006
    Location
    Vancouver
    Posts
    2


    Did you find this post helpful? Yes | No

    Smile Problem Solved!!!!

    Thanks BigWumus...

    The code is working perfect, I missed the ASCII part, good thing for the forums.

    Sorry Darrel Taylor, I should have been more explicit with my post. (Boss breathing down my neck).

    Thanks again...

    Glen65

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


    Did you find this post helpful? Yes | No

    Default

    My fault Glen, I didn't see you had the symptoms intermixed with the code.

    I tend to not look at code that isn't within [CODE] tags, cause it's so hard to read, all scrunched to the left.

    Thanks to BigWumpus, my lazyness was overcome.

    Carry On,
    &nbsp;&nbsp;&nbsp;Darrel

Similar Threads

  1. Problem on writing EEPROM in Winpic800 with picbasic pro
    By selimkara in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th May 2007, 16:33
  2. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  3. PicBasic Pro problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2007, 22:22
  4. Math problem...with picbasic pro
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2005, 19:28
  5. Problem with Picbasic Pro and PIC10F202, PIC10F206
    By mikaljan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th May 2005, 21:02

Members who have read this thread : 1

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