need expert to compile my program
Archiver
Posts: 46,084
hi all,
can anyone help me to compile two program together.
program 1: 2X16 LCD
program 2: 4X4 keypad
i want my program to work this way.
1) when a button is press on the keypad, it will show on the LCD.
example: Press 9, LCD will show a "9"
if i press 8 after it, it will continue showing. that
is "98" on the LCD.
2) the character on the keypad is "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F"
3) if "A" is press, it will delete the last character
if "E" is press, it will clear the LCD and return to main.
4) if "F" is press, it will store all the character that appear on
the LCD is store it in a variable"
the following are the two program:
' This program demonstrates initialization and printing on a 2 x 16
character LCD display.
' The set of "LCD constants", below, are provided as pre-defined and
useful LCD commands,
' though only a few are actually used in this program.
'{$STAMP BS2p}
'
Define LCD 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)
'
Main Routines
Init:
PAUSE 1000
GOSUB InitLCD
Start:
LCDOUT 1,ClearDisplay,[noparse][[/noparse]"Hello World!"]
LCDOUT 1,MoveCrsr+64,[noparse][[/noparse]"How are you?"]
STOP
'
Subroutines
InitLCD:
AUXIO
LCDCMD 1,WakeUp 'Send wakeup sequence to LCD
PAUSE 10 'These pauses are 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
'{$STAMP BS2p}
db VAR Bit ' Debounce bit for use by keyScan.
press VAR Bit ' Flag to indicate keypress.
key VAR Nib ' Key number 0-15.
row VAR Nib ' Counter used in scanning keys.
cols VAR INB ' Input states of pins P4-P7.
' Demo loop. Waits for press to indicate a keypress, then
' displays the key on the debug screen. Note that that
' this code clears the press bit when done in order to
' prepeare for the next press.
again:
GOSUB keyScan
IF press = 0 THEN again
DEBUG "key pressed = ", HEX key, CR
press = 0
GOTO again
' ==================== KEYPAD SUBROUTINE ====================
' This code scans a 0 across the row connections of the keypad,
' then looks at the column nibble to see if that 0 has shown up
' on any of those bits. If the column bits are all 1s, then
' no key is pressed. If a column bit is 0, then a key is pressed
' at the intersection of the current row and that column.
keyScan:
FOR row = 0 TO 3 ' Scan rows one at a time.
LOW row ' Output a 0 on current row.
key = ~cols ' Get the inverted state of column bits.
key = NCD key ' Convert to bit # + 1 with NCD.
IF key <> 0 THEN push ' No high on cols? No key pressed.
INPUT row ' Disconnect output on row.
NEXT ' Try the next row.
db = 0 ' Reset the debounce bit.
RETURN ' Return to program.
push:
IF db = 1 THEN done ' Already responded to this press, so done.
db = 1: press = 1 ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
' Key now contains 0-15, mapped to this arrangement:
' 0 1 2 3
' 4 5 6 7
' 8 9 10 11
' 12 13 14 15
' A lookup table is translates this to match the actual
' markings on the key caps.
LOOKUP key,[noparse][[/noparse]13,14,0,15,12,9,8,7,11,6,5,4,10,3,2,1],key
'lookup key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key
done:
INPUT row ' Disconnect output on row.
RETURN ' Return to program.
can anyone help me to compile two program together.
program 1: 2X16 LCD
program 2: 4X4 keypad
i want my program to work this way.
1) when a button is press on the keypad, it will show on the LCD.
example: Press 9, LCD will show a "9"
if i press 8 after it, it will continue showing. that
is "98" on the LCD.
2) the character on the keypad is "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F"
3) if "A" is press, it will delete the last character
if "E" is press, it will clear the LCD and return to main.
4) if "F" is press, it will store all the character that appear on
the LCD is store it in a variable"
the following are the two program:
' This program demonstrates initialization and printing on a 2 x 16
character LCD display.
' The set of "LCD constants", below, are provided as pre-defined and
useful LCD commands,
' though only a few are actually used in this program.
'{$STAMP BS2p}
'
Define LCD 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)
'
Main Routines
Init:
PAUSE 1000
GOSUB InitLCD
Start:
LCDOUT 1,ClearDisplay,[noparse][[/noparse]"Hello World!"]
LCDOUT 1,MoveCrsr+64,[noparse][[/noparse]"How are you?"]
STOP
'
Subroutines
InitLCD:
AUXIO
LCDCMD 1,WakeUp 'Send wakeup sequence to LCD
PAUSE 10 'These pauses are 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
'{$STAMP BS2p}
db VAR Bit ' Debounce bit for use by keyScan.
press VAR Bit ' Flag to indicate keypress.
key VAR Nib ' Key number 0-15.
row VAR Nib ' Counter used in scanning keys.
cols VAR INB ' Input states of pins P4-P7.
' Demo loop. Waits for press to indicate a keypress, then
' displays the key on the debug screen. Note that that
' this code clears the press bit when done in order to
' prepeare for the next press.
again:
GOSUB keyScan
IF press = 0 THEN again
DEBUG "key pressed = ", HEX key, CR
press = 0
GOTO again
' ==================== KEYPAD SUBROUTINE ====================
' This code scans a 0 across the row connections of the keypad,
' then looks at the column nibble to see if that 0 has shown up
' on any of those bits. If the column bits are all 1s, then
' no key is pressed. If a column bit is 0, then a key is pressed
' at the intersection of the current row and that column.
keyScan:
FOR row = 0 TO 3 ' Scan rows one at a time.
LOW row ' Output a 0 on current row.
key = ~cols ' Get the inverted state of column bits.
key = NCD key ' Convert to bit # + 1 with NCD.
IF key <> 0 THEN push ' No high on cols? No key pressed.
INPUT row ' Disconnect output on row.
NEXT ' Try the next row.
db = 0 ' Reset the debounce bit.
RETURN ' Return to program.
push:
IF db = 1 THEN done ' Already responded to this press, so done.
db = 1: press = 1 ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
' Key now contains 0-15, mapped to this arrangement:
' 0 1 2 3
' 4 5 6 7
' 8 9 10 11
' 12 13 14 15
' A lookup table is translates this to match the actual
' markings on the key caps.
LOOKUP key,[noparse][[/noparse]13,14,0,15,12,9,8,7,11,6,5,4,10,3,2,1],key
'lookup key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key
done:
INPUT row ' Disconnect output on row.
RETURN ' Return to program.