PDA

View Full Version : First attempt at coding



bartman
- 10th November 2004, 17:52
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