> -----Original Message----- > From: Goring, Steve [SMTP:Steve.Goring@BSKYB.COM] > Sent: Thursday, July 04, 2002 6:01 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC]:BAR GRAPH > > Hi list ... > > Hopefully someone will be able to help me out here, I am controlling the > speed of a > remote DC motor using a simple Hex switch. ( 16 discrete speed steps ( PWM > )) > > I could have used either an ADC or rotary encoder to get finer resolution, > but in this > application it is not necessary, in fact on or off would be just fine. > > I also happen to have a 1 line 16 character lcd and thought it would be > nice > to show > the speed as a bargraph ? > > My problem, is that I cannot think how to get started - I have had success > in the > past with CGram so I was thinking maybe increment a register and light a > segment > on the lcd per speed step, unfortunately I now have a mental block as to > actually > implement this. > > So, if someone could outline the steps that would be needed that would be > great .. > > Thanks > > Steve > I think a solid block is already defined in the LCD character set so you wouldn't even need to generate your own as you don't need any better resolution than one character block. The easiest way is to simply send the clear/home command to the lcd, and then write as many blocks as the value of you PWM count e.g. (sorry it's in (pseudo) C) void UpdateBargraph(char count) // count holds PWM value 0 -15 { char i; if(count > 15) // clamp number of chars to send count = 15; lcd_clear(); // send command 0x01 to LCD (clear and home) for(i=0;i<=count;i++) lcd_write(0xFF); // write solid block character } The only downside with this is that it may cause flicker if the display is updated very often. To avoid this would need some cunning and some more code to only write the characters that are needed to make the bar shorter or longer void UpdateBargraph(char count) { static prvcount; char i; if(count > 15) // clamp number of chars to send count = 15; if (count < prvcount) // bar graph needs to be shorter { lcd_goto(count + 1); // move cursor to first blank character for(i=0 ;i < (prvcount - count); i++) lcd_putch(' '); // write spaces to the ends of the display } else if (count > prvcount) // bar graph needs to be longer { lcd_goto(prvcount + 1); // move cursor to first blank character for(i=0; i < (count - prvcount); i++) lcd_putch(0xFF); // write solid blocks } prvcount = count; // store current bar value for next update } I presume you already have some code to control the LCD? If not then there are dozens of examples on the net for PIC code. The above should be pretty trivial to convert to assembler if that's what you are using. Regards Mike -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body