''*************************************** ''* Display Test * ''* Author: William Hardie * ''* Started: 2-14-11 * ''* Version 1.1 * ''* Revision Date 8-22-11 * ''*************************************** '' '' Initial design,chg to display only 6-18-11 '' Display is 2x16 or 4x20 Serial LCD CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 '80 MHz ''LCD Assignments LCD_Pin = 24 ' Output Pin For LCD pin P24 LCD_In0 = 25 ' Input Pin for LCD testing P25 LCD_IN1 = 26 ' Input Pin for LCD testing P26 ''Parallax 2x16 or 4x20 Serial LCD ' Either 27976,27977,or 27979 LCD_Baud = 9600 ' LCD Baud Rate 2400,9600,or 19200 LCD_Lines = 4 ' Either 2 or 4 lines LCD_Colms = 20 ' Either 16 or 20 columns LCD_BkLite = 1 ' Either 0 for false,1 for true LCD_Sound = 1 ' Either 0 none, 1 for sound ''Above constants change to type & format of display used LCD_BKSPC = $08 ' move cursor left LCD_RT = $09 ' move cursor right LCD_LF = $0A ' move cursor down 1 line LCD_CLS = $0C ' L clear LCD (with 5 ms delay) LCD_CR = $0D ' move pos 0 of next line LCD_BL_ON = $11 ' backlight on LCD_BL_OFF = $12 ' backlight off LCD_OFF = $15 ' Display off LCD_ON1 = $16 ' LCD on; cursor off, blink off LCD_ON2 = $17 ' LCD on; cursor off, blink on LCD_ON3 = $18 ' LCD on; cursor on, blink off LCD_ON4 = $19 ' LCD on; cursor on, blink on LCD_LINE0 = $80 ' H LCD Home LCD_LINE1 = $94 ' 1 move to line 1, column 0 LCD_LINE2 = $A8 ' 2 move to line 2, column 0 LCD_LINE3 = $BC ' 3 move to line 3, column 0 '' Custom Character definition label #$F8, LCD_CC0, LCD_CC1, LCD_CC2, LCD_CC3 #$FC, LCD_CC4, LCD_CC5, LCD_CC6, LCD_CC7 '' Video Debug Constants 'VIDEO_OUT = 9 'Video pin P9 VAR byte pcog 'PST cog ID byte dcog 'LCD cog ID byte bklt 'Backlite 0 for off,1 for on byte cc 'custom character byte byte scale 'music scale byte note 'music note byte sw0 'start switch byte sw1 'skip switch long stack[60] OBJ pst : "Parallax Serial Terminal" dis : "LCDDisplay" PUB Main 'Start PST for troubleshooting pcog := pst.Start (115200) 'Start PST in Cog delayhalf pst.Clear if pcog 'check for cogid pst.str(string("pst started in cog ")) pst.dec(pcog-1) 'indicate cog number pst.newline else Main ''Start LCD in a Cog dcog := dis.LCD_Start(LCD_Pin,LCD_Baud,LCD_Lines,LCD_Colms,LCD_BkLite) ''Check for LCD cog ID if dcog pst.str(string("dis started in cog ")) pst.dec(dcog-1) 'indicate cog number pst.newline else pst.str(string("display cog not available")) pst.newline delay200m 'IMPORTANT,delay to init display dis.cls 'clear garbage off screen pst.str(String("display is Ready",13)) dis.putstr(@Splash1) 'Show splash message dis.putstr(@Splash2) dis.waittime(1000) '' individual tests for display '' backslash is used to stop ABORT from going above this stack level \Soundtest \CCLoadtest \BKLTtest \Stringtest \ONOFFtest \CursorTypetest \CursorMovetest \SOLtest \ClrLinetest \CCWritetest ''Finish all tasks, home, and set cursor on display dis.putchar(LCD_ON3) 'cursor on/blink off dis.putchar(LCD_CR) dis.putstr(@done) 'end test program ''end of main object PUB Soundtest ''Test sound system dis.home dis.putstr(@sound) CkSwitch if LCD_Sound == 1 'if piezospeaker is on display dis.putchar($D4) 'Enter single note for alarm dis.putchar($DB) '1/4note(1/2sec),scale 7,E note dis.putchar($E3) dis.waittime(2000) 'wait 2 second dis.putchar($D2) 'play all notes at 1/16 speed repeat scale from $D7 to $DB step $01 'octive 3 to octive 7 dis.putchar(scale) dis.putchar($D4) dis.putchar($E8) 'delay 1/2 sec dis.putchar($D2) repeat note from $DC to $E7 step $01 'Notes A,A#,B,C,C#,D,D#,E,F,F#,G,G# dis.putchar(note) dis.putchar($D5) dis.putchar($E8) 'delay 1 sec dis.putchar($D3) '1/8 note play music dis.putchar($D9) 'octive 5 repeat 6 dis.putchar($DE) 'B dis.putchar($E3) 'E dis.putchar($E5) 'F# dis.putchar($E7) 'G# repeat 4 dis.putchar($DE) 'B dis.putchar($E3) 'E dis.putchar($E7) 'G# dis.putchar($E6) 'G dis.putchar($E5) 'F# dis.putchar($E2) 'D# repeat 6 dis.putchar($DE) 'B dis.putchar($E3) 'E dis.putchar($E5) 'F# dis.putchar($E7) 'G# repeat 4 dis.putchar($DE) 'B dis.putchar($D1) '1/32 note dis.putchar($E3) 'E dis.putchar($D3) '1/8 note dis.putchar($E7) 'G# dis.putchar($E6) 'G dis.putchar($E5) 'F# dis.putchar($E2) 'D# repeat 5 dis.putchar($DE) 'B dis.putchar($D1) '1/32 note dis.putchar($DE) 'B dis.putchar($D3) '1/8 note dis.putchar($DE) 'B dis.putchar($DE) 'B dis.putchar($E3) 'E dis.putchar($E5) 'F# dis.putchar($E7) 'G# dis.putchar($E3) 'E dis.putchar($E6) 'G dis.putchar($DA) 'octive 6 dis.putchar($DE) 'B dis.putchar($DC) 'A dis.putchar($D9) 'octive 5 dis.putchar($E7) 'G# dis.putchar($E5) 'F# dis.putchar($E3) 'E else dis.putstr(@nosound) 'if no speaker on display dis.waittime(1000) dis.putchar(LCD_CLS) PUB CCLoadtest ''Load custom characters dis.home dis.putstr(@loadcc) CkSwitch dis.putstr(@loadingcc) dis.waittime(500) dis.txchar(LCD_CC0) 'Send char 0 address cc := 0 repeat 8 'Send each byte dis.txchar(CC0[cc]) cc:= cc + 1 dis.txchar(LCD_CC1) 'Send char 1 address cc := 0 repeat 8 'Send each byte dis.txchar(CC1[cc]) cc:= cc + 1 dis.txchar(LCD_CC2) 'Send char 2 address cc := 0 repeat 8 'Send each byte dis.txchar(CC2[cc]) cc:= cc + 1 dis.txchar(LCD_CC3) 'Send char 3 address cc := 0 repeat 8 'Send each byte dis.txchar(CC3[cc]) cc:= cc + 1 dis.txchar(LCD_CC4) 'Send char 4 address cc := 0 repeat 8 'Send each byte dis.txchar(CC4[cc]) cc:= cc + 1 dis.txchar(LCD_CC5) 'Send char 5 address cc := 0 repeat 8 'Send each byte dis.txchar(CC5[cc]) cc:= cc + 1 dis.txchar(LCD_CC6) 'Send char 6 address cc := 0 repeat 8 'Send each byte dis.txchar(CC6[cc]) cc:= cc + 1 dis.txchar(LCD_CC7) 'Send char 7 address cc := 0 repeat 8 'Send each byte dis.txchar(CC7[cc]) cc:= cc + 1 dis.cls PUB BKLTtest ''Test for backlight. if no bklt, then see message on display. dis.home dis.putstr(@testbklt) CkSwitch if LCD_Bklite == 0 'check for backlight option dis.putstr(@nobklt) dis.waittime(1000) else 'do if option is there dis.home bklt := 0 'Set backlite off Bklt_On_Off dis.putstr(@off) dis.waittime(1000) dis.home bklt := 1 'Set backlite on Bklt_On_Off dis.putstr(@on) dis.waittime(1000) dis.home bklt := 0 'Turn off again Bklt_On_Off dis.putstr(@off) dis.waittime(1000) PUB Stringtest {{Test sending strings command putstr will fill blanks to end of line command putstrNF will not fill blanks after data }} dis.home dis.putstr(@teststr) CkSwitch dis.home dis.putstr(@Welcome1) 'howdy dis.putstr(@Blank) dis.waittime(500) dis.putchar(LCD_LINE1) 'Move down a line dis.putstr(@Welcome2) 'partner pst.Str(@Welcome1) 'Howdy pst.char(13) 'new line pst.Str(@welcome2) 'Partner pst.char(13) 'new line dis.waittime(1000) dis.home if LCD_Lines ==2 'if 2 line display dis.putstrNF(@TwoLine) dis.waittime(2000) else 'if 4 line display dis.putstrNF(@FourLine) dis.waittime(4000) dis.cls dis.putstrNF(@TooLine) 'put two more lines to show wrap dis.putstr(@blank) dis.clrln(3) dis.waittime(2000) if LCD_Colms == 20 'if 20 columns dis.cls dis.putstr(@CH1) 'enter fixed data dis.putstr(@CH2) dis.putstr(@CH3) dis.gotoxy(18,2) dis.putchar($03) 'enter CC degree symbol dis.stl3 dis.putstr(@CH4) dis.waittime(2000) dis.gotoxy(12,0) 'enter variable data dis.putstrNF(@DATA1) dis.gotoxy(11,1) dis.putstrNF(@DATA2) dis.gotoxy(12,2) dis.putstrNF(@DATA3) repeat 5 dis.gotoxy(11,3) 'fake data changing dis.putstrNF(@DATA4) dis.waittime(500) dis.gotoxy(11,3) dis.putstrNF(@DATA41) dis.waittime(500) dis.home else 'skip if 16 columns PUB ONOFFtest ''Test display on/off dis.cls dis.putstr(@testonoff) CkSwitch dis.putstr(@goingoff) dis.waittime(1000) dis.putchar(LCD_OFF) 'turn display off dis.waittime(1000) dis.cls dis.putstr(@backon) 'chg data while off dis.putstr(@addwhenoff) dis.putchar(LCD_ON2) 'turn it back on dis.waittime(2000) PUB CursorTypetest ''Test cursor type dis.home dis.putstr(@cursortype) CkSwitch dis.home dis.putstr(@cursorOffNB) 'cursor off/blink off dis.putstrNF(@firstchar) dis.putchar(LCD_BKSPC) dis.putchar(LCD_ON1) dis.waittime(2000) dis.home dis.putstr(@cursorOnNB) 'cursor on/blink off dis.putchar(LCD_ON3) dis.waittime(2000) dis.home dis.putstr(@cursorOnB) 'cursor on/blink on dis.putchar(LCD_ON4) dis.waittime(2000) dis.home dis.putstr(@cursorOffB) 'cursor off/blink on dis.putchar(LCD_ON2) dis.waittime(2000) PUB CursorMovetest ''Test cursor movement ''Put characters and move cursor to another location dis.home dis.putstr(@cursormove) CkSwitch dis.putchar(LCD_LINE0) 'Home dis.cls 'Clear display dis.putchar("A") dis.waittime(1000) dis.gotoxy(6,0) 'move cursor right 5 col dis.putchar("B") dis.waittime(1000) dis.putchar(LCD_LF) 'move cursor down a line dis.putchar(LCD_RT) 'move cursor one position right dis.putchar("s") dis.putchar("t") dis.waittime(1000) repeat 4 dis.putchar(LCD_BKSPC) 'move left 3 col dis.putchar("F") dis.putchar("a") dis.waittime(1000) dis.putchar(LCD_LINE0) 'Home dis.waittime(500) repeat 7 dis.putchar(LCD_RT) 'Move right 6 col dis.putstrNF(@doubleEE) dis.waittime(1000) dis.putchar(LCD_CR) 'move to next line,col 0 dis.putstrNF(@fly) dis.waittime(2000) dis.cls dis.waittime(500) if LCD_Lines == 4 'if 4 line display dis.stl1 dis.putchar("E") dis.waittime(500) dis.putchar(LCD_LINE3) dis.putchar("P") dis.waittime(500) dis.stl2 dis.putchar("L") dis.waittime(500) dis.putchar(LCD_LINE0) dis.putchar("H") else 'if 2 line display dis.stl1 dis.putchar("I") dis.waittime(500) dis.putchar(LCD_LINE0) dis.putchar("H") dis.waittime(1000) dis.cls PUB SOLtest ''Test start of line dis.home dis.putstr(@Sofline) CkSwitch dis.home 'go to line 0, col 0 dis.putstrNF(@Welcome1) dis.waittime(1000) GoToSOL 'find start of line dis.waittime(1000) PUB ClrLinetest ''Clear entire line dis.home dis.putstr(@clrline) CkSwitch dis.home 'enter information dis.putstr(@Splash1) dis.putstr(@Splash2) dis.waittime(1000) dis.clrln(0) 'lines are 0 to 3 dis.waittime(1000) dis.clrln(1) dis.waittime(1000) PUB CCWritetest ''Write each custom character to display dis.cls dis.putstr(@sendCC) CkSwitch dis.home cc := 0 repeat 8 dis.putchar(cc) 'write each character dis.putchar(LCD_RT) 'skip a space cc := cc + 1 dis.waittime(3000) 'view for 3 sec PUB Bklt_On_Off 'enter with bklt set to 0/1 pst.dec(bklt) 'troubleshoot on PST pst.newline dis.putbklt(bklt) PUB GoToSOL | x 'go to start of line x := 0 repeat (LCD_Lines - 1) dis.gotoxy((x + 1) * 4,x) dis.waittime(2000) x := x + 1 dis.putchar(LCD_CR) dis.waittime(1000) PUB CkSwitch dis.putstr(@hold4press) 'send message dis.waittime(1000) 'leave on to read sw0 := 1 'init condition,chg for sw state sw1 := 1 'init condition,chg for sw state dira[LCD_IN0] := 0 dira[LCD_IN1] := 0 repeat until sw0 == 0 'Look for correct level sw0 := ina[LCD_IN0] sw1 := ina[LCD_IN1] if sw1 == 0 abort 'if true,abort to next level & continue if sw0 == 0 'if true do task dis.cls next '' DELAY METHODS PUB delay200m 'delay two tenth second waitcnt(clkfreq/5 + cnt) PUB delayhalf 'delay half second waitcnt(clkfreq/2 + cnt) DAT Welcome1 byte "Howdy",0 Welcome2 byte "Partner",0 Splash1 byte "LCD Display Test",0 Splash2 byte "Rev 1.01",0 Blank byte " ",0 testbklt byte "Testing Backlite",0 Nobklt byte "No BkLite option",0 firstchar byte "O",0 off byte " OFF",0 on byte " ON",0 teststr byte "Testing Strings ",0 testonoff byte " On / Off Test ",0 addwhenoff byte "Added while Off ",0 goingoff byte " Going Off ... ",0 backon byte " ... Back On ",0 cursortype byte " Cursor Type ",0 cursormove byte " Move Cursor ",0 cursorOffNB byte "Off, No Blink",0 cursorOnNB byte "On, No Blink ",0 cursorOnB byte "On, Blinking ",0 cursorOffB byte "Off, Blinking",0 doubleEE byte "ee",0 fly byte "Flies",0 clrline byte " Clear a line ",0 done byte " DONE TESTING ",0 sendCC byte "Send Custom Char",0 Loadcc byte "Load 8 chars",0 Loadingcc byte "Loading char ",0 sound byte "Play Sound",0 nosound byte "No Sound System",0 Sofline byte "Start of Line",0 TwoLine byte "Four score and seven years ago",0 FourLine byte "Football is not a Contact Sport! Football is a Collision Sport! ",0 TooLine byte "Dancing is a CONTACT SPORT!!",0 hold4press byte "0-Start, 1-Skip",0 CH1 byte "1-AIR PRESS PSI",0 CH2 byte "2-WIND MPH",0 CH3 byte "3-AIR TEMP F",0 CH4 byte "4-SIGNAL VDC",0 DATA1 byte " 122 ",0 DATA2 byte "NE 20",0 DATA3 byte " 87.3",0 DATA4 byte "+1.000",0 DATA41 byte "-0.999",0 ''Custom character matrix CC0 byte $00,$10,$08,$04,$02,$01,$00,$00 'backslash \ CC1 byte $00,$00,$0D,$12,$00,$00,$00,$00 'tilte ~ CC2 byte $00,$04,$0E,$1F,$0E,$04,$00,$00 'Diamond CC3 byte $07,$05,$07,$00,$00,$00,$00,$00 'Degree CC4 byte $04,$0E,$15,$04,$04,$04,$00,$00 'up arrow CC5 byte $00,$04,$04,$04,$15,$0E,$04,$00 'Down arrow CC6 byte $00,$00,$0E,$0E,$0E,$00,$00,$00 'center block CC7 byte $1B,$1B,$00,$00,$00,$1B,$1B,$00 'four corners {{ ┌─────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├─────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this │ │software and associated documentation files (the "Software"), to deal in the Software│ │without restriction, including without limitation the rights to use, copy, modify, │ │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to │ │permit persons to whom the Software is furnished to do so, subject to the following │ │conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies│ │or substantial portions of the Software. │ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, │ │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A │ │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT │ │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF │ │CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE│ │OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └─────────────────────────────────────────────────────────────────────────────────────┘ }}