need help in lookup


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    36

    Default need help in lookup

    please help i want to shiftout numbers from 0 to 9 .i used data eeprom it works good but it pause at 0 , now i want to use lookup or somthi9ng without saving data in eeprom .i want to shift out numbers to the leds using ic 74hc 164.it works when i use this (data @ 0,252,96,218,242,102,182,190,224,254,246) but i want to use lookup or other way not to save in the eeprom please
    this my code but doesnt work it sends unknown digit .


    define _HS_OSC & _LVP_OFF & _WDT_OFF & _CP_OFF
    define _BODEN_OFF & _MCLRE_ON & _PWRTE_ON
    DEFINE SHIFT_PAUSEUS 1000

    DEFINE OSC 4

    Include "modedefs.bas"

    B2 var word
    B1 var word

    SDO VAR PortB.0
    SCLK var PortB.1

    TRISB = 0
    porta = %00111
    SCLK = 8
    main:

    for b1 = 1 to 10

    b1 = b1+1
    b2 = b1
    pause 1000
    SHiftOUT SDO,SCLK,0,[b2]

    pause 1000

    next b1

    goto main


    lookup2 b1,[252,96,218,242,102,182,190,224,254,246],b2 'these numbers i want to shoutout them to the leds from 0 tro 9
    end
    Last edited by malwww; - 7th May 2009 at 18:17.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malwww View Post
    please help i want to shiftout numbers from 0 to 9 .i used data eeprom it works good but it pause at 0 , now i want to use lookup or somthi9ng without saving data in eeprom .i want to shift out numbers to the leds using ic 74hc 164.it works when i use this (data @ 0,252,96,218,242,102,182,190,224,254,246) but i want to use lookup or other way not to save in the eeprom please
    this my code but doesnt work it sends unknown digit .


    define _HS_OSC & _LVP_OFF & _WDT_OFF & _CP_OFF
    define _BODEN_OFF & _MCLRE_ON & _PWRTE_ON
    DEFINE SHIFT_PAUSEUS 1000

    DEFINE OSC 4

    Include "modedefs.bas"

    B2 var word
    B1 var word

    SDO VAR PortB.0
    SCLK var PortB.1

    TRISB = 0
    porta = %00111
    SCLK = 8
    main:

    for b1 = 1 to 10

    b1 = b1+1
    b2 = b1
    pause 1000
    SHiftOUT SDO,SCLK,0,[b2]

    pause 1000

    next b1

    goto main


    lookup2 b1,[252,96,218,242,102,182,190,224,254,246],b2 'these numbers i want to shiftout them to the leds from 0 through 9
    end
    Looks as if you almost got it, move your lookup routine up in your code to somewhere before the shiftout statement.
    Code:
    Include "modedefs.bas"
    
    B2 var byte
    B1 var byte
    
    SDO VAR PortB.0
    SCLK var PortB.1
    portB = 0          'set port latches low prior to tris
    TRISB = 0          'set all portB as outputs
    porta = %0000111   'set this way because ???
    'SCLK = 8
    
    b1 = 0
    b2 = 0
    main:
    for b1 = 0 to 9 + 1
    lookup2 b1,[252,96,218,242,102,182,190,224,254,246],b2 'these numbers i want to shoutout them to the leds from 0 tro 9
    
    
    
    SHiftOUT SDO,SCLK,0,[b2]
    
    pause 1000
    
    next b1
    
    goto main
    I changed your vars to byte as the were all less than 0 to 255
    I cleared the vars before the main loop
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Apr 2009
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    thank you very much joe for helping me .have a great day .

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello malwww,
    If you have been following other threads, you have seen a similar one to yours. If you are using byte variables only then use lookup instead of lookup2 as the code is 1/3 as big and you can use a table of up to 255 choices. Lookup2 gives only 85 choices, which can be byte or word variables.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Apr 2009
    Posts
    36


    Did you find this post helpful? Yes | No

    Smile

    hi joe thank you again for explaining to me ,i have another question please if you dont mind...i i want to write atring (lookup) to the external eeprom then i read it and send it out just to get more ideas bcz im new in pbp ,but its easy to lern than asm. have a great weekend joe


    '' I2CREAD and I2WRITE Commands

    Include "modedefs.bas"
    DEFINE I2C_SLOW 1
    DEFINE SHIFT_PAUSEUS 1000
    SDO VAR PortB.0
    SCLK var PortB.1

    SCLK = 8
    SO con 0
    DPIN var PORTA.0
    CPIN var PORTA.1
    B0 var byte
    B1 var byte
    B2 var byte
    B3 var byte
    n var byte
    portB = 0
    TRISB = 0
    'for n = 0 to 15

    lookup n,[252,96,218,242,102,182,190,224,254,246],b0 ' numbers from 0 to 9

    For B2 = 0 To 15

    I2CWRITE DPIN,CPIN,$A0,b2,[str B0\8]
    Pause 20


    Next B2
    'next n
    loop: For B3 = 0 To 15
    I2CREAD DPIN,CPIN,$A0,B3,[B1]
    pause 1000

    SHiftOUT SDO,SCLK,0,[b1]
    '

    Next B3



    Goto loop
    end

    i wrote this code but it doesnt shiftout the numbers from 0 to 9 like i have in the string .but it works good with last programe you fixed for me .see u joe
    Last edited by malwww; - 10th May 2009 at 08:10.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malwww View Post
    hi Joe thank you again for explaining to me ,I have another question please if you dont mind...I want to write a string (lookup) to the external eeprom then I'll read it and send it out just to get more ideas because I'm new in pbp ,but its easier to learn than asm. have a great weekend Joe
    Code:
    '' I2CREAD and I2WRITE Commands
    
      Include "modedefs.bas"          
      DEFINE I2C_SLOW 1
      DEFINE SHIFT_PAUSEUS 1000
    SDO VAR PortB.0
    SCLK var PortB.1
             
    SCLK = 8
    SO      con     0                      
    DPIN    var     PORTA.0                 
    CPIN    var     PORTA.1               
    B0      var     byte
    B1      var     byte
    B2      var     byte
    B3      var     byte
    n       var     byte 
    portB = 0          
    TRISB = 0 
     'for n = 0 to 15 <font color = red>' commented out </font color>
    
    <font color=green>you have setup your variables, and stored nothing in them yet, and are proceeding to lookup the value of "n" which is unknown to you,</font color>
    lookup  n,[252,96,218,242,102,182,190,224,254,246],b0 ' numbers from 0 to 9
     <font color=green>'the following loop will output the value stored in "n" filtered through the lookup table 15 times,
    always the same number,in each eeprom location. 
    why the str modifier? 
    Seems to me the numbers in the lookup table are
    not string values, as they would be arranged between
    quotation marks like so "252","96" . . .</font color>
            For B2 = 0 To 15
                            
                    I2CWRITE DPIN,CPIN,$A0,b2,[str B0\8]  
                    Pause 20                
            
            
            Next B2
            'next n
    
    loop:   For B3 = 0 To 15          
                    I2CREAD DPIN,CPIN,$A0,B3,[B1] 
                     pause 1000
                    
                    SHiftOUT SDO,SCLK,0,[b1]
                           '
                          
            Next B3
    
            
    
            Goto loop
            end
    i wrote this code but it doesnt shiftout the numbers from 0 to 9 like i have in the string .but it works good with last programe you fixed for me .see u joe
    are you seeing what you need to change ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. Lookup Table
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th March 2008, 10:38
  3. ADCIN and LOOKUP ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th June 2007, 21:02
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. Confused On Dig & Lookup
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th December 2006, 21:49

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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