Command questions
jc3III
Posts: 21
I'm new to the propeller chip, so I bought the Propeller Professional Development Board and the book called "Programming the Propeller with Spin: A Beginner's Guide to Parallel Processing" by Harprit Singh Sandhu. I'v been learning so far until the part when he starts introducing the LCD screen. I don't have the same LCD screen as he was using, I have the Parallax 2x16 Serial LCD (Non-Backlit). I can make it turn on and I have used a couple of programs from the parallax website. It works find with those programs, but I don't know where those commands come from dealing with the LCD. I also seen other commands that I couldn't find in the manual.
From what I understand, in the OBJ block the "LCD:" is saying the program will be using methods from a particular program. I guess when it says LCD.space or whatever after the dot, in the PUB block, it's coming from the a different program? I don't know, so I was wondering if someone could clarify with me whats going on.
From what I understand, in the OBJ block the "LCD:" is saying the program will be using methods from a particular program. I guess when it says LCD.space or whatever after the dot, in the PUB block, it's coming from the a different program? I don't know, so I was wondering if someone could clarify with me whats going on.
Comments
I don't know much about your lcd screen, but in the object block, e.g.:
- LCD is the symbol name, and it is how the object will be referenced throughout the program
- MyLCD is the object name or filename. Upon compile, an object with filename is searched for in the editor tabs, the working directory, and the library directory.
In your particular situation, this file is probably located in the library directory. Which can be found by opening Windows Explorer, and expanding the the Program Files directory, and then look for Parallax Inc. I have attached an image to help you find this file.Also, "MyLCD" is a fictious filename that I created. You must seek out the actual filename that you are using.
Bruce
welcome to the propellerforum!
In your posting aboce you wrote that you have successfully tried some demo-programs.
to make my on a level that it is understandable for you I have some questions:
Do you have experience with any kind of programming language and on which level: just a raw classification no at all - some small programs with language ... I have quite a lot experience with language...
please describe in normal words your idea what you want to do next.
I add some examples but I would like to read from your own idea:
- Displaying "Hello World" on the LCD
- showing the state of some switches on the LCD
keep the questions coming
best regards
Stefan
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp2.pdf
so just to make sure that I have understood right. you have this display
http://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/52/Default.aspx?txtSearch=2x16+LCD
and you tested it with this demo-program
http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/Serial_LCD_Propeller_Code.zip
In the microcontroller world standardisation goes not so far as in the PC world.
In the PC-world plug in any USB-device and you are done. In the microcontroller world
you have to look up if interfaces are compatible to each other on the hardware side
voltage levels, impedance TTL-logic or open-collector
and the softwareside: baudrate, databits, stopbits, logic-level inversion
In your case most of the things are compatible when using one of the serial-objects
like FullDuplexSerial or FullDuplexSerialPlus. only baudrate must be adjusted.
The object 484 called LCD 2x16 Parallel says in its name it is for a parallel interface.
Propeller-Chip===>===HD44780-controller===>===LCD
Your LCD has a serial interface on voltage level 5V.
Propeller-Chip===>===serial interface===>===HD44780-controller===>===LCD
Important: the propellerchip is a 3.3V device. your LCD is a 5V device.
You have to insert a 2.2kOhm resistor between Propeller-chip and LCD on the LCD-RX-line.
For you only the bold written part Propeller-Chip===>===serial interface is of interest.
The object 484 is incompatible to your serial interface because different amount of IO-pins and different protocol and commands how to communicate with the LCD
My advice: only change one thing at at time and then test again. First step
The Demoprogram uses the object FullDuplexSerial
I recommend to change to the FullDuplexSerialPlus-object
simply replace the codelines
with
Then test again if your display shows the same as before the change.
FullduplexSerialPlus has the same commands as FullDuplexSerial but offers more useful commands
these commands are
LCD.Dec: display a decimal number
LCD.Bin: display a binary number
LCD.Str: display a string (sequence of characters
please add or attach the code from your experiment that I can see the differences between the
code in the book and what has to be changed to make it work with the serial LCD.
There is a good chance that it is working simply by replacing the book-object with the FullDuplexSerialPlus-object.
keep the questions coming
best regards
Stefan
Thank you for the information so far.
{{Aug 31 09 Harprit Sandhu
ReadPot.spin
Propeller Tool Version 1.2.6
Chapter 16 Prog 01
READING A POTENTIOMETER
This routine ready a 10K pot with a 10 mfd cap
This routine is what is used in the utilities to read the pot
Pot is always read from the same line
}}
CON
_CLKMODE=XTAL1+ PLL2X 'The system clock spec
_XINFREQ = 5_000_000 'Crystal spec
PotLine = 19 'line the pot it on
OBJ
LCD : "LCDRoutines4" 'We will be using these METHODS in this program
VAR 'these are the variables we will use.
long startCnt 'count at start
long endCount 'count at end
long delay 'time difference
long PotValue 'Value of the pot reading
PUB Go
LCD.INITIALIZE_LCD 'set up the LCD
repeat 'loop
dira[PotLine]~~ 'set potline as output
outa[PotLine]~~ 'make it high so we can charge the capacitor
waitcnt(4000+cnt) 'wait for the capacitor to get charged
dira[PotLine]~ 'make potline an input. line switches H>L
startCnt:=cnt 'read the counter at start of cycle and store
repeat 'go into an endless loop
while ina[PotLine]~~ 'keep doing it as long as the potline is high
EndCount := cnt 'read the counter at end of cycle and store
delay := ((EndCount-StartCnt)-1184) 'calculate time for line to go H>L
if delay>630000 'max permitted delay
delay:=630000 'clamp delay
PotValue:=(delay/2220) 'This reduces the value to 0-255 or 1 byte
PotValue <#=255 'clamp range
PotValue #>=1 'clamp range
LCD.POSITION (1,1) 'Go to 1st line 1st space
LCD.PRINT(STRING("PotPos =")) 'Potentiometer position
LCD.PRINT_DEC(PotValue) 'print value
LCD.SPACE(3) 'erase over overflows
LCD.POSITION (2,1) 'Go to 2nd line 1st space
LCD.PRINT(STRING("Delay =")) 'Print
LCD.PRINT_DEC(delay) 'print value
LCD.SPACE(3) 'erase over overflows
" Here is the program in it's OBJ."
{{21 Sep 09 Harprit Sandhu
LCDRoutines.spin
Propeller Tool Ver 1.2.6
Chapter 21 Program 10
LCD ROUTINES
The following are the names of the methods described in this program
INITIALIZE_LCD
INITIALIZE_LCD4 not yet working right.
PRINT (the_line)
POSITION (LINE_NUMBER, HOR_POSITION) | CHAR_LOCATION
SEND_CHAR (DISPLAY_CHAR)
SEND_CHAR (DISPLAY_CHAR)
PRINT_DEC (VALUE) | TEST_VALUE
PRINT_HEX (VALUE, DIGITS)
PRINT_BIN (VALUE, DIGITS)
CLEAR
HOME
SPACE (QTY)
Revisions
04 Oct 09 Initialize made more robust, misc unnecessary calls removed.
}}
CON 'all the constants used by all the METHODS
'in this program have to be listed here
_CLKMODE=XTAL1+ PLL2X 'The system clock spec
_XINFREQ = 5_000_000 '10 Mhz
DataBit0 = 8 'Data uses 8 bits from here on
DataBit1 = 9
DataBit2 = 10
DataBit3 = 11 'All these bits dont need to be named but
DataBit4 = 12 'are named so that they can be called by
DataBit5 = 13 'name if the need ever arises
DataBit6 = 14
DataBit7 = 15
RegSelect = 16 'The three control lines
ReadWrite = 17 '
Enable = 18 '
high =1 {define the High state}
low =0 {define the Low state}
VAR 'these are the variables we will use.
byte temp 'for use as a pointer
byte index 'to count characters
PUB Go
INITIALIZE_LCD
repeat
print(String("1234567890 L1"))
position(2,1)
print(String("On second line"))
waitcnt(3_000_000+cnt)
clear
waitcnt(3_000_000+cnt)
'===========================================================
{{initialize the LCD to use 8 lines of data
Includes a half second delay, clears the display and positons to 1,1
no variables used
}}
PUB INITIALIZE_LCD 'The addressses and data used here are
waitcnt(5_000_000+cnt) 'specified in the Hitachi data sheet
DIRA[DataBit0..Enable]~~ 'YOU MUST CHECK THIS FOR YOURSELF.
SEND_INSTRUCTION (%0011_0000) 'Send 1
waitcnt(49_200+cnt) 'wait
SEND_INSTRUCTION (%0011_0000) 'Send 2
waitcnt(1_200+cnt) 'wait
SEND_INSTRUCTION (%0011_0000) 'Send 3
waitcnt(12_000+cnt) 'wait
SEND_INSTRUCTION (%0011_1000) 'Sets DL=8 bits, N=2 lines, F=5x7 font
SEND_INSTRUCTION (%0000_1110) 'Display on, Blink on, Sq Cursor off
SEND_INSTRUCTION (%0000_0110) 'Move Cursor, Do not shift display
SEND_INSTRUCTION (%0000_0001) 'clears the LCD
POSITION (1,1)
'===========================================================
{{Sends instructions as opposed to a character to the LCD
no variables are used
}}
PUB SEND_INSTRUCTION (D_DATA) 'set up for writing instructions
CHECK_BUSY 'wait for busy bit to clear b
OUTA[ReadWrite] := 0 'Set up to read busy bit
OUTA[RegSelect] := 0 'Set up to read busy bit
OUTA[Enable] := 1 'Set up to toggle bit H>L
OUTA[DataBit7..DataBit0] := D_DATA 'Ready to READ data in
OUTA[Enable] := 0 'Toggle the bit H>L to xfer the data
'===========================================================
{{Sends a character to the LCD
}}
PUB SEND_CHAR (D_CHAR) 'set up for writing to the display
CHECK_BUSY 'wait for busy bit to clear
OUTA[ReadWrite] := 0 'Set up to read busy bit
OUTA[RegSelect] := 1 'Set up to read busy bit
OUTA[Enable] := 1 'Set up to toggle bit H>L
OUTA[DataBit7..DataBit0] := D_CHAR 'Ready to SEND data in
OUTA[Enable] := 0 'Toggle the bit H>L
'===========================================================
{{Print a line of characters to the LCD
uses variables index and temp
}}
PUB PRINT (the_line) 'This routine handles more than one Char
'called as PRINT(string("the_line"))
'"the_line" contains the pointer to line.
'because we have to point to the line
'zero terminated but will not use that.
'use the string size instead. Easier
index:=0 'Reset the counter we are using
repeat 'repeat for all chars in the list
temp:= byte[the_line][index++]'temp contains the char pointed by index
SEND_CHAR (temp) 'send the 'pointed to' char to the LCD
while index<strsize(the_line) 'keep doing it till the last char is sent
'===========================================================
{{Position cursor
}}
PUB POSITION (LINE_NUMBER, HOR_POSITION) | CHAR_LOCATION 'Position the cursor
'Horizontal Position : 1 to 16 'specified by the two numbers
'Line Number : 1 or 2
CHAR_LOCATION := (LINE_NUMBER-1) * 64 'figr loc. See Hitachi HD44780 data
CHAR_LOCATION += (HOR_POSITION-1) + 128 'figr loc. See Hitachi HD44780 data
SEND_INSTRUCTION (CHAR_LOCATION) 'send the instruction to position cursor
'===========================================================
{{Check for busy
}}
PUB CHECK_BUSY | BUSY_BIT 'routine to check busy bit
OUTA[ReadWrite] := 1 'Set to read the busy bit
OUTA[RegSelect] := 0 'Set to read the busy bit
DIRA[DataBit7..DataBit0] := %0000_0000 'Set the entire port to be an input
REPEAT 'Keep doing it till clear
OUTA[Enable] := 1 'set to 1 to get ready to toggle H>L this bit
BUSY_BIT := INA[DataBit7] 'the busybit is bit 7 of the byte read
'INA is the 32 input pins on the PROP and we
'are reading data bit 7 which is on pin 15!
OUTA[Enable] := 0 'make the enable bit go low for H>L toggle
WHILE (BUSY_BIT == 1) 'do it as long as the busy bit is 1
DIRA[DataBit7..DataBit0] := %1111_1111 'set the data port back to outputs
'===========================================================
{{Print decimal
}}
PUB PRINT_DEC (VALUE) | TEST_VALUE'for printing values in decimal format
IF (VALUE < 0) 'if it is a negative value
-VALUE 'change it to a positive
SEND_CHAR("-") 'and print a - sign on the LCD
'
TEST_VALUE := 1_000_000_000 'we get individual digits by comp to this
'value and then div by 10 to get the nxt val
REPEAT 10 'There are 10 digits maximum in our system
IF (VALUE => TEST_VALUE) 'see if our number is bigger than testValue
SEND_CHAR(VALUE / TEST_VALUE + "0") 'if it is, divide to get the digit
VALUE //= TEST_VALUE 'figure the next value for the next digit
RESULT~~ 'result we can pass it on below
ELSEIF (RESULT OR TEST_VALUE == 1) 'if the result was a 1 then div was even
SEND_CHAR("0") 'so we sent out a zero
TEST_VALUE /= 10 'we divide by 10 to test for the next digit
'===========================================================
{{Print Hex
}}
PUB PRINT_HEX (VALUE, DIGITS) 'for printing values in HEX format
VALUE <<= (8 - DIGITS) << 2 'you can specify up to 8 digits or FFFFFFFF max
REPEAT DIGITS 'do each digit
SEND_CHAR(LOOKUPZ((VALUE <-= 4) & $F : "0".."9", "A".."F"))
'use lookup table to select character
'===========================================================
{{Print Binary
}} '
PUB PRINT_BIN (VALUE, DIGITS) 'for printing values in BINARY format
VALUE <<= 32 - DIGITS '32 binary digits is the max for our system
REPEAT DIGITS 'Repeat for each digit desired
SEND_CHAR((VALUE <-= 1) & 1 + "0") 'send a 1 or a 0
'===========================================================
{{Clear screen
}}
PUB CLEAR 'Clear the LCD display and go home
SEND_INSTRUCTION (%0000_0001) 'This is the clear screen and go home command
'===========================================================
{{Go to position 1,1
}}
PUB HOME 'go to position 1,1.
SEND_INSTRUCTION (%0000_0011) 'Not cleared
'===========================================================
{{Print spaces
}}
PUB SPACE (qty) 'Prints spaces, for between numbers
repeat (qty)
PRINT(STRING(" "))
'===========================================================
{{
}}
to post code you should it do like that
Paste your code between [ code ] and [ /code ] tags, and it will show up in the forum just the way you typed into your code editor.
As you didn't you forced me to google for harprits code. If you just post it the indention gets lost. But indention of codelines is essential.
The other way is to use the Go advanced button and use the button "#" wich will insert the [ code ] and [ /code ] tags for yo
For more than 20 lines of code it is better to use the archive-function of the propeller-tool and the attachment-manager of the forum software.
Now to get Harprits code running with your serial LCD you have to change the obj-filename from
to
after that if you compile the compiler will complain about unknown identifiers because the methods in those two objects have different names.
take a look at those codelines and try to identify which command of harprits LCD-object sends a string and which sends an integer value
then look inside FullDuplexSerialPlus how the method for sending strings or decimal values is named
replace the names. Please do a first OWN try on this. If it isn't successful come back posting in detail what you tried what the result was and a concrete question.
In this way you are doing your homework which is expected you to do before the forum helps. You don't have to come far. It must just be readable that you tried at least
something small on your own and then ask a concrete question.
keep the questions coming
best regards
Stefan