Jump to content

rand() Random with 8Bit Pic (c -sdcc)


Phatline
 Share

Recommended Posts

MIOS32Bit Core LPC17 © >  following Code works:

if(Potentiometer <= (rand() % 255)) {
   Gate = 0;}

What the code does:

The Potentiometer is a Variable > its a Analog Input: Value from 0-255

Gate is a Variable and it Gates a NOTE-STREAM.

All Together its a Note-Random-Killer > with the Pot you set the change to be killed...

 

MIOS 8Bit Core 18F452 © > it DOES NOT work, I got following Error:

p --disable-warning 85 --obanksel=2  -I./src -I ./include/c -I ./include/share -DDEBUG_MODE=0  main.c -o _output/main.o
main.c:224: warning 112: function 'rand' implicit declaration
main.c:224: warning 84: 'auto' variable 'rand' may be used before initialization
main.c:224: warning 84: 'auto' variable 'rand' may be used before initialization
./bin/mios-gpasm modifies _output/main.asm, result in _output/main__mios-gpasm-tmp.asm
_output/main__mios-gpasm-tmp.asm:47:Error [113] Symbol not previously defined (_rand).
_output/main__mios-gpasm-tmp.asm:694:Error [113] Symbol not previously defined (_rand).
_output/main__mios-gpasm-tmp.asm:694:Error [113] Symbol not previously defined (_rand).
make: *** [_output/main.o] Fehler 1


with the MIOS32 bit I dont had to declare nothing...

 

The Quest now:

how to program a random that has a predefinied min:0 & max:255

(I am not a C-Geek, Beginner > Detailed Answer would be great > "comparing 2 Registers in Cycles take the Result and..." > I cant perform such of that into code ;) (leider)

 

(the first workaround and try of building an Analog Noise generator to feed into a AIN with an BC549 failed by smoking en up...)

 

THANKS

Link to comment
Share on other sites

ok got it... the search had results TK: 2006

 

 

   tmp = random_seed_l * random_seed_h;
   random_seed_l = TMR0L + (unsigned char)(tmp & 0xff);
   random_seed_h = 0x69 + (unsigned char)(tmp >> 8);

it makes random numbers from 0 - 255

 

all variables have to defied bevore of course...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...