please who can help me for sample code


Results 1 to 7 of 7

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Hi jasem700,
    I understand what you want to do, and it's not too tough. Look at the block diagram and take a swing at what commands you need to use to acheive your goal. For instance, how might you receive some data? You have choices of serin, serin2, hserin, i2cread, . . . pick one!
    then you need a place to store that information, a variable. You are storing a 4 digit number, correct? so the number will not be larger than 9999, and 9999 will not fit into a byte as a byte only holds up to 255 so the next larger variable is a word which will hold up to 65535.
    So in the paragraph above we know we have to store a word so here is how to do it:
    MyVar VAR WORD , you can call the variable almost anything like HOT_COFFEE or WHISKEY make it something meaningful to you, the compiler doesn't care.

    let's try serin as a way to get the number in.
    Code:
    include"modedefs.bas"
    main:
    SERIN PortA.0,T9600,MyVar
    GOTO main
    end
    the code above will receive your number and loop over and over, pretty useless as is,
    you need more code to make it do what you want, but it does get the information.
    Now that you have captured the number you need to isolate the digits, and again you need a place to store those numbers, yep you guessed it variables again, and they will be bytes as they are smaller than 255 ,so let's name them digit, so . . .
    Code:
    include"modedefs.bas"
    digit1 var byte
    digit2 var byte
    digit3 var byte
    digit4 var byte
    MyVar VAR WORD
    main:
    SERIN PortA.0,T9600,MyVar
    GOTO main
    end
    The DIG command isolates which digit you store in the variable like so
    myvar = 1298
    digit1 = MyVar DIG1
    digit2 = MyVar DIG2
    digit3 = MyVar DIG3
    digit4 = MyVar DIG4
    Now you have your number stored in MyVar and have them isolated as individual digits.
    Do you follow so far ?
    Code:
    include"modedefs.bas"
    digit1 var byte
    digit2 var byte
    digit3 var byte
    digit4 var byte
    MyVar VAR WORD
    main:
    SERIN PortA.0,T9600,MyVar
    digit1 = MyVar DIG1
    digit2 = MyVar DIG2
    digit3 = MyVar DIG3
    digit4 = MyVar DIG4
    GOTO main
    end
    As you see, building blocks add code as you need it and the large program begins to materialize.
    Next you have to figure out which port will output your 7 segment display will use, each segment will
    have a port address. Lay out the port in a binary fashion where 1 is on and 0 is off and you can figure out what to
    energise to display the number you want to display. Use a lookup table to assign the port output to achieve this and store in more variables. Let's call those variables Display, so Display1 var BYTE . . . and you would write it like
    LOOKDOWN2 digit1,[ your number for zero, yournumberforone, . . . ],display1
    this will give you the appropriate LED pattern for the number in digit1 variable ready to display.
    then to display you would simply make a statement like portB = display1
    Last edited by Archangel; - 17th February 2009 at 08:39.
    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. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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