Is that all of the code? I'd like to see the delay's and the random = function.... Can you send me the entire source code file off list?=20 Tim >>> gaidinmd@HOTMAIL.COM 12/23/03 08:56PM >>> I'm confused about the function of PBCONTROL. Is that an input pin or an output pin? The Low command will automatically make it an output. If you're looking more for a "While button =3D pushed, do this" type command, you want a "While PORTB.x =3D 0...Wend" statement. One more point- you really need to learn, use and love GoSub and Return. Really. Really. Constant Goto hopping is a good way to end up in a padded room. I know you don't want to hear this, but assembly code is the only way to really know what PIC programming is all about. With the 16F series, you have less than 40 commands to learn. If you don't have a book, you need to get one. I'd suggest the Peatman books. Mike H. >Related Setup Code >----------------------------- >'set timer > option_reg =3D %11011000 'set TMR0 to internal clock > >'set variables >RND VAR WORD 'set RND as variable > >Problem Subroutine >---------------------------- >PB3SUB: > Low PBCONTROL 'turn off PB's > Low GLED 'turn off Green LED > High RLED 'turn on Red LED > RND=3DTMR0 'load TMR0 into RND > Random RND 'randomise RND > RND =3D (RND // 31) + 1 'returns a number between 1-31 > For LOOP1=3D1 TO (RND*1000) 'pause for RND secs > Next LOOP1 > RND=3DTMR0 'load current TMR0 into RND >(different >value) > Random RND 'randomise RND a 2nd time > Low RLED 'turn off Red LED > RND =3D (RND // 31) + 1 'returns a number between 1-30 > IF RND>=3D15 Then > GoTo PB1SUB 'if RND is higher than mid point run = PB1 >sub-routine > Else > GoTo PB2SUB 'if RND is lower than mid point run = PB2 >sub-routine > EndIF > GoTo MAIN > >Note >------- >The above subroutine currently runs to the end of line two and then hangs >until >the button is released (which is odd as the first line turns off the push >button.......unless it cycles through so quickly it is sampling the = button >state >again before it is released). > >If I 'rem' out all the lines that relate to 'RND' or 'Random' and add a >delay >between 'High RLED' and 'Low RLED' the red LED comes on for the duration = of >the >delay (this leads me to believe my problem lies with either my method of >trying >to read the value of TMR0 or with the 'Random' command. > >If anyone can shed any light on this or suggest a way of achieving my = goals >I >would appreciate the info. _________________________________________________________________ Get reliable dial-up Internet access now with our limited-time introductory= offer. http://join.msn.com/?page=3Ddept/dialup=20 -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics