Hi, You are forgetting that after the rotate the lsb is left in the carry and what was in the carry is now in the msb. You can get fancy and first set the carry to the value of pwm.0 or try the following for fun. char LpDec @ pDecArg; char HpDec @ pDecArg+1; bHB_LED = pDecArg & 1; HpDec = LpDec; pDecArg >>= 1; Now although this C code looks overly complex, look at the code it makes. Ignore for the moment that Bytecraft C 1.4 sets the RPx bits for any jump destination. The first statement is the same as the bit operations as if it were a ch.0 test. One difference with this code is that the value is only tested once. If the location were a port pin that was changing from an outside source the CC5x compiler generates code that might never light the LED since the first test fails and then the second test fails because the input value changed. Very dangerous in real time systems. Once the LED value is set the shift is kind of neat. Copy the Least Sig byte of the word into the upper byte. Then shift it right one bit. The RRF 3F moves the lsb of the 8 bit variable into the carry. The RRF 3E then moves that bit into bit 7 and loses the lsb into the carry. It may look like a waste of memory to use two bytes but you can see the compiler here just stuffs the character we want to rotate into a variable used for all sorts of I/O. 08C5 1283 BCF STATUS,RP0 bHB_LED = pDecArg & 1; 08C6 1303 BCF STATUS,RP1 08C7 183E BTFSC 3E,0 08C8 28CB GOTO 08CBh 08C9 1205 BCF PORTA,4 08CA 28CE GOTO 08CEh 08CB 1283 BCF STATUS,RP0 08CC 1303 BCF STATUS,RP1 08CD 1605 BSF PORTA,4 08CE 1283 BCF STATUS,RP0 HpDec = LpDec; 08CF 1303 BCF STATUS,RP1 08D0 083E MOVF 3E,W 08D1 00BF MOVWF 3F 08D2 1003 BCF STATUS,C pDecArg >>= 1; 08D3 0CBF RRF 3F 08D4 0CBE RRF 3E You might want to enter and leave this function with a LpDec = pwm; ... pwm = LpDec; Or be real sneaky and position your variables so a temporary one is declared just after pwm. Example: unsigned char pwm; unsigned char i; unsigned int var16 @ pwm; Regards, John Dammeyer > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Simon-Thijs de Feber > Sent: Monday, April 08, 2002 11:01 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC]:PWM > > > Hello All, > > Yesterday evening i have been struggling with a PWM > function. > > A char should be loaded with e.g. 0xF0, afterwards > rotated right, and every passing LSB should be put on > a output pin. > > So i did this in CC5x > > led1 = pwm.0; > pwm = pwm >> 1; > > this generates something like > > BTFSS pwm,0 > BCF led1 > BTFSC pwm,0 > BSF led1 > CLR 0x05, C //clear carry > RRF pwm,1 > > The clear carry is not required cause i want a > continues rolling function. > > So i removed the "clear carry" in an inline assembly > block and included that in my code, but that has not > solved the problem. > > any one an idea ? > > > grtz > > Simon > > > > > > > > > __________________________________________________ > Do You Yahoo!? > Everything you'll ever need on one web page > from News and Sport to Email and Music Charts > http://uk.my.yahoo.com > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.