'{$STAMP BS2p} '{$PBASIC 2.5} ' Demonstration program showing how to use an LCD display with a Basic ' Stamp 2p (the LCD code portions are courtesy of Parallax Inc.) and ' the Melexis MLX90601EZA-CAA Infrared thermometer module. The output ' pin No. 8 from the module is connected to the IR_Temp pin on the ' Stamp. The algorithm shown in the main routine is based on using the ' timing of the BS2p to convert the pulse with signal into a ' temperature. The actual formula is: ' T = ((value-12.8ms)/51.2ms)*(140 Deg C) - 20 Deg C ' The value is in milli-seconds, and the temperature, T is in Deg. C. ' --------------------------------------------------------------------- ' I/O Definitions ' --------------------------------------------------------------------- IR_Temp PIN 15 ' IR Thermometer Input Signal ' --------------------------------------------------------------------- ' Constants ' --------------------------------------------------------------------- WakeUp CON %00110000 'Wake-up FourBitMode CON %00100000 'Set to 4-bit mode OneLine5x8Font CON %00100000 'Set to 1 display line, 5x8 font OneLine5x10Font CON %00100100 'Set to 1 display line, 5x10 font TwoLine5x8Font CON %00101000 'Set to 2 display lines, 5x8 font TwoLine5x10Font CON %00101100 'Set to 2 display lines, 5x10 font DisplayOff CON %00001000 'Turn off display, data is retained DisplayOn CON %00001100 'Turn on display, no cursor DisplayOnULCrsr CON %00001110 'Turn on display, with underline cursor DisplayOnBLCrsr CON %00001101 'Turn on display, with blinking cursor IncCrsr CON %00000110 'Auto-increment cursor, no display shift IncCrsrShift CON %00000111 'Auto-increment cursor, shift display left DecCrsr CON %00000100 'Auto-decrement cursor, no display shift DecCrsrShift CON %00000101 'Auto-decrement cursor, shift display right ClearDisplay CON %00000001 'Clear the display HomeDisplay CON %00000010 'Move cursor and display to home position ScrollLeft CON %00011000 'Scroll display to the left ScrollRight CON %00011100 'Scroll display to the right CrsrLeft CON %00010000 'Move cursor left CrsrRight CON %00010100 'Move cursor right MoveCrsr CON %10000000 'Move cursor to position (must add address) MoveToCGRAM CON %01000000 'Move to CGRAM position (must add address) ' --------------------------------------------------------------------- ' Variables ' --------------------------------------------------------------------- value VAR Word tmp VAR Word tmp1 VAR Word tmp2 VAR Word ' --------------------------------------------------------------------- ' Main Routines ' --------------------------------------------------------------------- Init: ' Initialize LCD GOSUB InitLCD Start: ' Write Initial text to LCD LCDCMD 1, cleardisplay LCDOUT 1,MoveCrsr+1,["IR Temperature"] LCDOUT 1,MoveCrsr+64,["Tmp="] LCDOUT 1,MoveCrsr+75,["Deg F"] Main: ' Read Thermometer and display results PULSIN IR_Temp, 1, value ' Read IR Thermometer pulse width IF value < 16000 THEN GOTO main ' Check to see is value is less than 12 ms tmp = value/125 ' Begin converting measured pulse width into tmp=tmp-133 ' the temperature with one decimal point tmp=tmp*71 ' accuracy. The result is also being tmp1=tmp/128 ' being converted into degrees Fahrenheit tmp1=tmp1-4 tmp2=tmp//128 tmp2 = tmp2*10 tmp2=tmp2/128 LCDOUT 1,movecrsr+69,[DEC3 tmp1, ".", DEC tmp2] ' Display result to LCD GOTO main END ' --------------------------------------------------------------------- ' Subroutines ' --------------------------------------------------------------------- InitLCD: PAUSE 1000 LCDCMD 1,WakeUp 'Send wakeup sequence to LCD PAUSE 10 'Pause is necessary to meet the LCD specs LCDCMD 1,WakeUp PAUSE 1 LCDCMD 1,WakeUp PAUSE 1 LCDCMD 1,FourBitMode 'Set buss to 4-bit mode LCDCMD 1,TwoLine5x8Font 'Set to 2-line mode with 5x8 font LCDCMD 1,DisplayOff 'Turn display off LCDCMD 1,DisplayOn 'Turn display on with blinking cursor LCDCMD 1,IncCrsr 'Set to auto-increment cursor (no display shift) LCDCMD 1,ClearDisplay 'Clear the display RETURN