Hi Dean, If its always 50% then just divide by 2, which is efficiently implemented by a right shift by one bit. CCS-C should optimise it to a rotate right operation. int Val, Result; Result = Val / 2; if the percentages change then you will need to change that to multiply by 100 then divide by the percentage. Note - be careful you don't over run the integer. You need to do the multiply first. In CCS-C the "int" type by default is 8 bits. This is always compiler dependant, if you want to make sure of the size your using try using int8, int16 and int32 as the types. So if you had a 8 bit number and you wanted to get an arbitrary percentage, you would need to promote it to a 16 bit number so you don't overflow it int8 Val, Result; int8 Percent; int16 temp; temp = (int16) Val * 100; temp = temp / Percent; Result = (int8)temp; the type in brackets is a cast to that type of the following identifier. hope that helps, Ash. --- Ashley Roll Digital Nemesis Pty Ltd www.digitalnemesis.com Mobile: +61 (0)417 705 718 > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of MATTHEWS, DEAN (D.) > Sent: Thursday, 21 February 2002 7:15 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]:working out percentages > > > Hello, > > I am using a PIC16f877 and CCs compiler. Is there a maths > function that will enable me to calculate 50% of an integer > variable in a register and store the answer in another > variable, or would I calculate it myself. > > Also is an integer 8 bit or 16 bit long. some books say it > is 8bit and others 16 bit. > > Dean Matthews > Reliability Engineering > Ford Engine Plant Bridgend > Waterton industrial estate > cf31 3pj > South Wales, U.K > Tel No: 0044(1656)672597 > Fax No: 0044(1656)672558 > Email: dmatth14@ford.com > Room 25/118 > ` Please consider your environmental responsibility before > printing this e-mail > > > -----Original Message----- > From: M. Adam Davis [mailto:adampic@UBASICS.COM] > Sent: 31 January 2002 14:53 > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]:16F877 and LCD > > > Since there seems to be a good bit of interest in this, I'll see about > modifying one of my current projects to portB instead of A. > > The code for the 'f877 with the LCD EN and RS on PORTA, and the data > lines on PORTC is here: > http://ubasics.com/adam/pic/node.c > > I don't know when I'll have time to modify it, but you can load it up. > > The first thing it does is sends "Micro Basics HAT" to the > top line of a > 16x2 LCD display (should be the top line of any display) then > goes on to > perform its basic duties (which in this case is measuring pulse length > on two pins for a 2-axis acceleraometer). To get it to do anything > after that you'll need to rip out all the 'while(accel...)' > statements. > At that point it'll start displaying 3 hex numbers on the bottom line > of a 2 line LCD. > > If you are only using one line on your LCD, make sure you're > initializing it correctly. Check out the numerous website > and tutorials > on initializing alphanumeric LCD displays. My initialization sets up > the display for two lines, and while it shouldn't matter it > sometimes can. > > -Adam > > > Michael Pettersson wrote: > > >Hello All! > > > >I'm new with PIC and the 16F877 and have started testing the > CC5Xfree from > >http://www.bknd.com > > > >I have a project that I would like to start with but I need > a LCD for this. > >My first attampts was not succesful and now I need some help. > > > >Could anyone help me with a LCD 4 bit parallell test > software with the > >cc5xfree software and against the 16F877 micro? > > > >Thanks! > > > >Michael > > > >-- > >http://www.piclist.com#nomail Going offline? Don't AutoReply us! > >email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > > > > > > > > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- > 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: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads