; Note: a 2 by 16 LCD is assumed ;****************** Constant Definitions ****************** symbol control = outpinsA ;control lines to the AY chip symbol BC1 = A.0 ;A.0 is BC1 on the AY chip symbol BDIR = A.1 ;A.1 is BDIR on the AY chip symbol bus = outpinsB ;data/address bus to AY chip symbol buttons = pinsC ;These are time constants based on a 40 MHz clock. The numbers ;may seem inconsistent since they refer to the pause, pauseus ;or pulsout commands which all use different base units. symbol AYpulse = 2 ;AY write pulse is 2 uS symbol LCDpulse = 1 ;LCD Enable pulse is 200 uS symbol uSec40 = 200 ;40 uSec reset pause symbol mSec2 = 10 ;2 mSec reset pause symbol mSec = 5 ;one mSec symbol secFifth = 1000 ;fifth of a second symbol secHalf = 2500 ;half of a second symbol secOne = 5000 ;one second symbol sec3 = 15000 ;3 seconds ;AY-8910 control codes and register addresses symbol inactive = %00000000 symbol latchAddr = %00000011 symbol Reg7 = %00000111 ;Register 7 - data direction symbol Reg15 = %00001111 ;Register 15 - Port IOB symbol IOBOut = %11111111 ;IOB data direction-out ;Here are various LCD commands which can be used. symbol clrHome = 1 ;clear the display, home the cursor symbol home = 2 ;home the cursor only symbol RtoL = 4 ;print characters right to left symbol insR = 5 ;insert characters to right symbol LtoR = 6 ;print characters left to right symbol insL = 7 ;insert characters to left symbol lcdOff = 8 ;LCD screen off symbol lcdOn = 12 ;LCD screen on, no cursor symbol curOff = 12 ;an alias for the above symbol block = 13 ;LCD screen on, block cursor symbol under = 14 ;LCD screen on, underline cursor symbol undblk = 15 ;LCD screen on, blinking and underline cursor symbol left = 16 ;cursor left symbol right = 20 ;cursor right symbol panR = 24 ;pan viewing window right symbol panL = 28 ;pan viewing window left symbol mode1 = 32 ;one-line mode (4-bit data) symbol mode2 = 40 ;two-line mode (4-bit data) symbol bus4 = 32 ;4-bit data bus mode symbol bus8 = 48 ;8-bit data bus mode symbol line1 = 128 ;go to start of line 1 symbol line2 = 192 ;go to start of line 2 ;****************** Variable Definitions ****************** symbol char = b0 ;ASCII character to be displayed symbol cmd = b0 ;an alias for the char byte symbol i = b1 ;loop variable symbol j = b2 ;and another one symbol row = b3 ;offset into message table symbol index = b4 ;pointer to current character symbol temp = b5 ;temporary LCD data byte built here symbol choice = b6 ;*********************** Messages ************************* eeprom 0, ("Press a cursor ") ;0 eeprom 16, ("button now. ") eeprom 32, ("You are pressing") ;2 eeprom 48, ("Up ") ;3 eeprom 64, ("Down ") ;4 eeprom 80, ("Left ") ;5 eeprom 96, ("Right ") ;6 eeprom 112,("Center ") ;7 eeprom 128,("more than one. ") ;8 ;********************** Main Program ********************** pgm: setfreq em40 ;40 MHz external resonator dirsA = %00001111 ;A.0-A.3 are outputs dirsB = %11111111 ;B.0-B.7 are outputs dirsC = %00000010 ;C.2-C.6 are inputs pwmout C.1, 5, 11 gosub init ;initialize AY and LCD display main: row = 0 ;print main message gosub print1 row = 16 gosub print2 main1: choice = not buttons ;read switch port choice = choice >> 2 ;shift into lowest part of byte choice = choice & %00011111 ;mask off junk above select case choice ;covert choice to message address case 0 row = 0 ;no buttons pressed case 1 row = 48 case 2 row = 64 case 4 row = 80 case 8 row = 96 case 16 row = 112 else ;more than one button pressed row = 128 end select if choice = 0 then main ;no buttons pressed gosub print2 ;else print updated message row = 32 gosub print1 goto main1 end ;************* Initialize AY and LCD on power-up ************* init: control = inactive ;clear BC1, BDIR ;set up the AY Port IOB for output control = latchAddr ;latch address to register 7 bus = Reg7 control = inactive bus = IOBOut ;make Port IOB all outputs pulsout BDIR,AYpulse control = latchAddr ;latch address to register 15 bus = Reg15 control = inactive bus = 0 ;clear Port IOB pulsout BDIR,AYPulse bus = %00100011 ;set to 8-bit mode bus = %00000011 ;do directly at outset pauseus uSec40 cmd = bus4 ;switch to 4-bit mode now gosub sendCmd pauseus uSec40 cmd = bus4 ;manufacturer recommends reduncancy gosub sendCmd pauseus uSec40 cmd = lcdOn ;display on, no cursor gosub sendCmd pauseus uSec40 cmd = clrHome ;clear display gosub sendCmd pauseus mSec2 char = LtoR ;print left to right by default gosub sendCmd pause uSec40 char = mode2 ;use two-line format gosub sendCmd pause uSec40 return ;*************** Send a Character to the LCD ************** ;To transmit a character, RS must be high. sendChr: control = latchAddr ;latch address mode bus = Reg15 ;access Port IOB control = inactive ;address now latched temp = char >> 4 ;shift high nibble right bus = temp | %00110000 ;Enable high (and RS) pulsout BDIR,AYpulse ;latch data pause LCDpulse ;keep high for 200 uS bus = temp | %00010000 ;Enable low, RS still high pulsout BDIR,AYpulse ;latch data temp = char & %00001111 ;grab low nibble bus = temp | %00110000 ;Enable high,RS high pulsout BDIR,AYPulse ;latch data pause LCDpulse bus = temp | %00010000 ;Enable low pulsout BDIR,AYPulse ;latch data return ;**************** Send a Command to the LCD *************** ;To transmit a command, RS must be low sendCmd: control = latchAddr ;latch address mode bus = Reg15 ;access Port IOB control = inactive ;address now latched temp = char >> 4 ;shift high nibble right bus = temp | %00100000 ;Enable high,RS low pulsout BDIR,AYpulse ;latch data pause LCDpulse bus = temp ;Enable low, RS still low pulsout BDIR,AYpulse ;latch data temp = char & %00001111 ;grab low nibble bus = temp | %00100000 ;Enable high,RS low pulsout BDIR,AYPulse ;latch data pause LCDpulse bus = temp ;Enable low, RS still low pulsout BDIR,AYPulse ;latch data pause mSec return ;*************** Print first row to the LCD ************** ;The variable 'row' points to the start of the string. print1: cmd = line1 ;print on first line gosub sendCmd goto continue print2: ;print on second line cmd = line2 gosub sendCmd continue: ;continue here in either event for i = 0 to 15 index = row+i read index, char ;fetch next character and gosub sendChr ;transmit to the LCD next i return ;**************** Clear LCD and home cursor *************** clearLCD: cmd = clrHome ;clear display gosub sendCmd pause mSec2 return