First attempt at coding


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189

    Question First attempt at coding

    If you've been ready my thread in the general section you know that I've been trying to use some random numbers. Here is my first attempt at writing a bit of code that will be eventually used (hopefully). Does it make sense? Would it run?

    A new question is regarding what goes at the beginning. Can code just start like this or is there leading commands that are needed? I don't seem to find examples with anything else, but it could be a case of me not knowing yet what needs to be there.

    Here is the code. I'm not saying it is the most compact or best way of doing this. I'm just hoping it would compile and run:


    Symbol randomnumber = W0 ‘ assign meaningful name to word0
    Symbol bottom = B0 ‘ assign meaningful name to less significant bits of randomnumber
    Symbol gate1 = Bit0 ‘ assign meaningful name to first four bits of randomnumber
    Symbol gate2 = Bit1
    Symbol gate3 = Bit2
    Symbol gate4 = Bit3

    Read 0,bottom ‘ get seed number from eeprom
    Randomnumber=randomnumber + 5 ‘ add 5 to seed number
    Write 0,bottom ‘ write to eeprom a new seed number

    high 5 ‘ turn off master switch in multiplexer to load input pins
    ‘ first

    start:

    choose:
    Random randomnumber ‘ generate random number and place in variable randomnumber
    If randomnumber = 66535 then choose ‘ ensure an even distribution of even and odd numbers

    outlow1:
    if gate1 = 1 then outhigh1 ‘ look at bit 0 of randomnumber then make pin 1 low
    low 1 ‘ if bit = 0 and go to next bit…
    goto outlow2

    outhigh1:
    high 1 ‘ …otherwise make pin 1 high


    outlow2:
    if gate2 = 1 then outhigh2 ‘ look at bit 1 of randomnumber then make pin 2 low
    low 2 ‘ if bit = 0 and go to next bit…
    goto outlow3

    outhigh2:
    high 2 ‘ …otherwise make pin 2 high

    outlow3:
    if gate3 = 1 then outhigh3 ‘ look at bit 2 of randomnumber then make pin 3 low
    low 3 ‘ if bit = 0 and go to next bit…
    goto outlow4

    outhigh3:
    high 3 ‘ …otherwise make pin 3 high

    outlow4:
    if gate4 = 1 then outhigh4 ‘ look at bit 3 of randomnumber then make pin 4 low
    low 4 ‘ if bit = 0 and go to next bit…
    goto switch

    outhigh4:
    high 4 ‘ …otherwise make pin 4 high

    switch:

    low 5 ‘ turn on master switch in multiplexer to activate random LED

    delay:
    pause 1000 ‘ pause for 1 second
    high 5 ‘ turn off master switch in multiplexer to blink LED
    goto start ‘ go to start and do it all again


    So, is it alive or dead? I hope to start experimenting by this weekend with programming the chip.

    Thanks,

    Bart
    Last edited by bartman; - 10th November 2004 at 21:07.

Similar Threads

  1. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  2. need help in coding..
    By daphne8888 in forum mel PIC BASIC
    Replies: 1
    Last Post: - 19th March 2008, 07:31
  3. HPWM coding
    By civictypeR in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th January 2008, 14:54
  4. Manchester coding question
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th May 2007, 17:35
  5. Turbo Coding
    By obaskirt in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th November 2006, 15:54

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