' Program: BGXPLOT1.BS2 (Plot graphs with BS2/BGX-128L) ' This program demonstrates how to create an animated ' chart-recorder-style graph on the BGX-128L serial ' graphics LCD. The display is in the style of medical ' equipment, which leave old data stationary on the screen, ' incrementally erasing it as new data is plotted. This ' approach is efficient and easy on the eyes. For the ' demo, our data comes from a pot--twiddle the pot to ' see the graph change. ' Set the BGX-128L for 9600 bps and connect its serial input ' to BS2 pin P0. Connect a 10k pot/0.1uF cap to pin P1 as ' shown in the schematic (or in Stamp manual under RCTIME). ' ==BGX-128L CONTROL CONSTANTS========================= N9600 con $4054 ' BS2 baudmode constant, 9600 bps. S_PIN con 0 ' Serout pin to ILM-216. CLRLCD con 12 ' ASCII form feed = clear screen. CTL_P con 16 ' Control-P (position cursor). CTL_B con 2 ' Start inverse-video print. CTL_C con 3 ' End " " CUT0 con 64 ' 1-byte shortcut for 0. ESC con 27 ' Escape (begins graphics instruction). ' ==CHART CONSTANTS==================================== ' You can change HEIGHT, WIDTH, and PCOLOR to modify the ' plot display. Try changing PCOLOR to WHITE for an ' inverse-video look. BLACK con 1 ' Black pixel-ink. WHITE con 0 ' White (background color) pixel-ink. HEIGHT con 47 ' Max Y val of plotting area. WIDTH con 128 ' Width of the plotting area. PCOLOR con BLACK ' Color of the plot. ECOLOR con PCOLOR ^ 1 ' Erase color (opposite of PCOLOR). ' ==PROGRAM VARIABLES================================== new var word ' New value to be plotted. old var byte ' Previous plot value. xOld var byte ' Previous X-axis location. xNew var byte ' New X-axis location. ' ==DEMO PROGRAM======================================= pause 1000 ' Wait for LCD to initialize. ' Send some dummy data to finish pending instructions (in case ' BS2 is reset while program is running), then clear screen. serout S_PIN,N9600,[CUT0,CUT0,CUT0,CUT0,CLRLCD] ' Move to screen position 48 (4th line, 1st character) and ' print label in inverse video. serout S_PIN,N9600,[CTL_P,112,CTL_B," BS2 Strip Plot ",CTL_C] Again: gosub getPotVal ' Get the data. gosub plotChart ' Plot it. goto Again ' Do it continuously. ' ==SUBROUTINES======================================== ' PLOTCHART: Plot the current value of the variable 'new'. ' First, draw a vertical line in the ECOLOR (erase-color) at the ' current x position to erase any old data. Next set the PCOLOR ' (plot color) and draw a line from the old x/y position to the ' new x/y position. If we're wrapping around from the right-hand ' end of the graph, make xOld 0 to avoid drawing a 'retrace' line ' from right to left [xOld = xOld // (WIDTH-1)]. Finally, save ' the new x/y values as old for the next trip. plotChart: new = HEIGHT - (new max HEIGHT) ' Subtract to flip (higher values at top). xNew = xNew + 1 // WIDTH serout S_PIN,N9600,[ESC,"I",(CUT0+ECOLOR)] serout S_PIN,N9600,[ESC,"L",(xNew+CUT0),(CUT0),(xNew+CUT0),(CUT0+HEIGHT)] xOld = xOld // (WIDTH-1) serout S_PIN,N9600,[ESC,"I",(CUT0+PCOLOR)] serout S_PIN,N9600,[ESC,"L",(xOld+CUT0),(old+CUT0),(xNew+CUT0),(new+CUT0)] old = new xOld = xNew return ' GETPOTVAL: For demo data, take a pot measurement through pin 1. Cap is ' 0.1uF to +5V; pot is 10k to ground, as shown in BS2 manual RCTIME entry. getPotVal: ' Output pot value high 1: pause 1 ' Discharge cap on pin 1. rctime 1,1,new ' Measure charge time (approx. 0-600) new = new/14 ' Scale to 0-60 approx. return