Author Topic: Parallax Bs2P serial LCD code  (Read 4392 times)

chrisdlove

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Parallax Bs2P serial LCD code
« on: April 28, 2015, 12:19:47 PM »
Hi,
I've written some simple code to use the New haven serial LCD display to be used with a BS2P Parallax microprocessor.

I've attached it for your reference.

Regards,
Chris.

' {$STAMP BS2p}
' {$PBASIC 2.5}

' -----[ Revision History ]------------------------------------------------
'   Revision 10.0 4-26-15
'        1. Changed LCD code to reflect New Haven Display

' Notes:
' Voltage across LED = 1.6 V
' Voltage for a 1 = 5.0 V
' Total of all pin sync <= 50 mA or 40 mA source
' Pin can source 20 mA
' Pin can sync 25 mA

Hardware connections
NHD LCD Pin 1 - RX   =>   BS2P24 Pin 5 - P0 (arbitrarily chosen)
NHD LCD Pin 2 - Vss   =>   BS2P24 Pin 23 - Vss (Ground)
NHD LCD Pin 3 - Vdd   =>   BS2P24 Pin 21 Vdd (+5V)

' -----[ I/O Definitions ]-------------------------------------------------
LCDPin                  PIN       0               ' P0 to output LCD data

' -----[ Program Constants ]-------------------------------------------------------
UP_ARROW             CON     1               ' Up arrow custom char
DN_ARROW             CON     2               ' Down arrow custom char

' -----[ LCD Constants ]-------------------------------------------------------
LcdLine1                CON     $00           ' move to line 1, column 0
LcdLine2                CON        $40       ' move to line 2, column 0
LCDBaud9600          CON        $00F0   ' Baud rate 9600 (default NHD Baud rate)
LCDBaud19200         CON        $006E   ' Baud rate for 19200
LCDCC1                  CON        $01       ' define custom char 1, 249 - up arrow
LCDCC2                  CON        $02       ' define custom char 2, 250 - down arrow


' -----[ Variables ]-------------------------------------------------------
Counter              VAR     Byte            ' Loop counter
Date                   VAR     Byte            ' Date- numerical
LCDBaud            VAR     Byte       ' Stores LCD Baud Rate

' -----[ LCD Constants for Newhaven Display ]-----------------------------------------------
'Parameter        BAUD      Hexadecimal value
'1                300               0x01
'2                1200         0x02
'3                2400         0x03
'4                9600         0x04
'5                14400        0x05
'6                19.2K        0x06
'7                57.6K        0x07
'8                115.2K       0x08

' New Haven LCD Command Summary

' Prefix Command    Parameter    Description                                 Execution time
'    -         -          Byte            Display Character WRITE (0x00 ~ 0xFF)    100uS
' 0xFE   0x41          None         Display ON                                  100uS
' 0xFE   0x42          None         Display off                                 100uS
' 0xFE   0x45          1 Byte       Set cursor                                  100uS
' 0xFE   0x46          None         Cursor HOME                                 1.5mS
' 0xFE   0x47          None         Underline cursor ON                         1.5mS
' 0xFE   0x48          None         Underline cursor off                        1.5mS
' 0xFE   0x49          None         Move cursor left one place               100uS
' 0xFE   0x4A          None         Move cursor right one place              100uS
' 0xFE   0x4B          None         Blinking cursor ON                          100uS
' 0xFE   0x4C          None         Blinking cursor off                         100uS
' 0xFE   0x4E          None         Backspace                                   100uS
' 0xFE   0x51          None         Clear screen                                1.5mS
' 0xFE   0x52          1 Byte       Set contrast                               500uS
' 0xFE   0x53          1 Byte       Set backlight brightness                    100uS
' 0xFE   0x54          9 Byte       Load custom character                    200uS
' 0xFE   0x55          None         Move display one place left              100uS
' 0xFE   0x56          None         Move display one place right             100uS
' 0xFE   0x61          1 Byte       Change RS-232 BAUD rate                  3mS
' 0xFE   0x62          1 Byte       Change I2C address                          3mS
' 0xFE   0x70          None         Display firmware version                 4mS
' 0xFE   0x71          None         Display RS-232 BAUD rate                 10mS
' 0xFE   0x72          None         Display I2C address                         4mS

' Initialize Display:  Subroutine to initialize NEWHAVEN NHD-0216K3Z-FL-GBW-V3 (2x16 LCD display)
LCDBaud=LCDBaud9600
SEROUT LCDPin, LCDBaud, [$FE, $61, $04]             ' Set baud rate inside NHD LCD to 9600   (Pause 20 usec)
SEROUT LCDPin, LCDBaud, [$FE, $61, $06]             ' Set baud rate inside NHD LCD to 19200 (Pause 20 usec)
LCDBaud=LCDBaud19200                                ' Change Baud rate to 19200
SEROUT LCDPin, LCDBaud, [$FE, $41]                  ' Turn on LCD Display (Pause 100 usec)
SEROUT LCDPin, LCDBaud, [$FE, $51]                 ' Clear LCD Display (Pause 100 usec)
PAUSE 10                                               ' Pause delays in units of 1 msec, 1msec = 1000 microseconds

Load Custom Characters
SEROUT LCDPin, LCDBaud, [$FE, $54, LCDCC1, $04, $0E, $15, $04, $04, $04, $04, $04] ' Send UP ARROW to LCD RAM at Address 0x01 (Pause 200 usec)
SEROUT LCDPin, LCDBaud, [$FE, $54, LCDCC2, $04, $04, $04, $04, $04, $15, $0E, $04] ' Send DN ARROW to LCD RAM at Address 0x02 (Pause 200 usec)

' Test Display: 
SEROUT LCDPin, LCDBaud, ["Hello"]                   ' Write text
SEROUT LCDPin, LCDBaud, [$FE, $45, LCDLine2]  ' Reposition to Line 2, column 1
SEROUT LCDPin, LCDBaud, ["World!"]                  ' Write text
PAUSE 4000

SEROUT LCDPin, LCDBaud, [$FE, $51]                  ' Clear LCD Display (Pause 100 usec)
SEROUT LCDPin, LCDBaud, [LCDCC1, LCDCC2]    ' Display Custom Characters
END

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 249
  • Karma: 16
    • View Profile
Re: Parallax Bs2P serial LCD code
« Reply #1 on: April 28, 2015, 12:35:35 PM »
Hello Chris,

Thank you so much for sharing! I'm sure your sample code will come in handy for Parallax users  8)

Bridgette_E

  • Administrator
  • Jr. Member
  • *****
  • Posts: 19
  • Karma: 1
    • View Profile
Re: Parallax Bs2P serial LCD code
« Reply #2 on: April 29, 2015, 08:06:15 AM »
Check your messages for an exclusive offer on your next purchase!   ;) 

 

Sample Code Question for NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM LCD

Started by SteveCBoard Character LCDs

Replies: 2
Views: 3092
Last post July 31, 2014, 08:44:29 PM
by SteveC
NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started

Started by RichardRBoard OLEDs

Replies: 4
Views: 3270
Last post December 17, 2015, 03:12:49 AM
by RichardR
Korean Hex GB code for OLED multi font display NHD-2.7-12864UMY3

Started by newhavenuserBoard OLEDs

Replies: 0
Views: 768
Last post May 05, 2017, 01:17:45 PM
by newhavenuser
Demo code for NHD-0216K3Z-FS(RGB)-FBW-V3 module on an ATMEL ATtiny 2313A

Started by swulfBoard Customer Projects

Replies: 0
Views: 1
Last post December 10, 2017, 10:37:21 PM
by swulf
Resistive/Capacitive Touch Screen - Sample Code

Started by daotaBoard TFTs

Replies: 1
Views: 1297
Last post July 14, 2016, 07:57:46 AM
by Saurabh_B