> I need some code or a algorithm for generating a 8 bit random number on > a PIC. Does anyone have any code or an algorithm to accomplish this? Random (actually pseudo-random!) numbers are useually generated by a shift register with XOR feedback. You can vary the length of the SR to get a suitable cyclus length. The jal compiler has a such a reandom library which is so small that I've attched it below. You should be able to translate this into assembler (in fact is it almost assembler). I deleted the copyright notice, but it is covered by the GNU LGPL so unless you want to sell a library based upon it you can use it freely. When you are too lazy to translate the code below into assembler you could download the jal compiler and let it do the job. (www.xs4all.nl/~wf/wouter/pic/jal) regards, Wouter. var byte _random_b1 var byte _random_b2 var byte _random_b3 -- make sure there is at least one bit set! asm bsf _random_b1, 0 procedure _random_shift is -- from the art of electronics, p657: -- 24 bits LFSR needs xor feedback from taps at 17, 22 and 23 assembler movlw 0 btfsc _random_b3, 1 xorlw 0xFF btfsc _random_b3, 6 xorlw 0xFF btfsc _random_b3, 7 xorlw 0xFF addlw 1 rlf _random_b1, f rlf _random_b2, f rlf _random_b3, f end assembler end procedure var bit _random_bit at _random_b1 : 0 var byte _random_byte at _random_b1 procedure randomize( byte in n = 0 ) is _random_b1 = n _random_b2 = 1 _random_b3 = 0 for 24 loop _random_shift end loop end procedure function random_bit return bit is _random_shift return _random_bit end function function random_byte return byte is for 8 loop _random_shift end loop return _random_byte end function