Shop OBEX P1 Docs P2 Docs Learn Events
Need help with the DAT block and calling data from it — Parallax Forums

Need help with the DAT block and calling data from it

eagletalontimeagletalontim Posts: 1,399
edited 2009-11-13 00:01 in Propeller 1
I currently have a 7 segment display that will show numbers 1 - 9. Since I am converting from the SX language to the Propeller language, I need a little boost tongue.gif I have found some code that shows the DAT area being used kind of like the DATA area on the SX. I am trying to make certain pins outputs when a number is called by storing the sequence in the DAT area. For some reason, I cannot get it working correctly. Can someone help me understand this a little better.

Here is the basic function of how I have it :

  ' the variable tmp is set inside a sub which will be the number which needs to be displayed (1-9)
  outa[noparse][[/noparse]16..22]~   'toggle pins off
  dira[noparse][[/noparse]16..22]~~  'Ensure the are outputs
  outa[noparse][[/noparse]16..22] := numbers[noparse][[/noparse]tmp - 1]  ' set pins to 1/0 depending on numbers[noparse][[/noparse]#]????

DAT
  numbers long %100_0000, %010_0000, %110_0000, %100_0000   'these are random sequences just for testing purposes.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-11 05:25
    What's wrong? What you wrote seems perfectly reasonable. You have a table of 32 bit values called "numbers" and you're accessing the entry that corresponds to the value you want to display ("tmp" from 1 to 9). The selected entry gets copied to I/O pins 16 through 22.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-11-11 07:32
    I would not use longs. As it's a 7 segment display a byte per number is enough.
    And I don't understand why you use [noparse][[/noparse]tmp -1] as index. If tmp is an integer ( like tmp := 5 ) then your range of tmp will be 0 to 9. That's already the right index.
    If tmp is a ascii encoded number ( like tmp := "0" ), then you need to subtract $30 or "0" as then the range of tmp will be "0" to "9" which is $30 to $39 as hex integer-value.


    You should always provide the whole code. In many posts the initial problem description contained code which was correct because the problem was hidden in other parts. Extracted code already contains assumptions about the problem of the extractor. But the less experience you have the more you can go wrong with your assumptions.

    Post Edited (MagIO2) : 11/11/2009 7:39:33 AM GMT
  • JonnyMacJonnyMac Posts: 9,207
    edited 2009-11-11 17:24
    MagIO2 is right on both counts: 1) No need to use longs, bytes work fine (see attached) and, 2) You'll get more effective help when you start posting problematic programs instead of pulling sections out.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-11-12 00:19
    I am worried that posting my whole code will allow someone to duplicate what I make and sell them as I do. Competition is tough in this market so I try to learn as much as I can about specific coding instead of posting the entire thing over and over basically giving an update to anyone who wants it. I do understand that other coding that may not be posted could cause a conflict as well. I will mess with it a bit more and hopefully get it working correctly without too much help. I like to try and learn on my own, but sometimes, I just need a little boost or explanation on how something works.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-11-12 06:53
    Ok, but if you rip off the important part, then there is no way for helping you. Guessing is unpleasant for us. And ... hey ... who will copy this code ? ;o)

    But seriously, if you have to rip off you should at least create a working reproducer. I can embed your snippet in a piece of code where it works, so obviously your ripped of code must be the problem.

    Post Edited (MagIO2) : 11/12/2009 6:58:53 AM GMT
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-11-12 12:16
    You do have a point [noparse]:)[/noparse] Next time, I will post a working sample. Come to find out, I had my outa to far indented which caused the code to only run when the tmp value hit 9. All other numbers it was blank [noparse]:([/noparse]
  • JonnyMacJonnyMac Posts: 9,207
    edited 2009-11-12 16:35
    Use Ctrl + I to show indentation -- this will help you spot errors more quickly. And do post full listings; it's not likely that if you're asking for help anyone is going to steal code from you.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-11-13 00:01
    Thanks for letting me know about that. That is much easier to work with now [noparse]:)[/noparse] It's not the point of stealing the code, it is basically the ability to take the entire idea. There are others out there that can program much faster than I can and would be able to hit the market faster that I would be able to. Since this is my only product at the time, I really have to watch what I post tongue.gif
Sign In or Register to comment.