Variable will not work to send ascii value to serial display
Potato
Posts: 18
See the attached program, EID_01.spin. The idea is to look at two hex encoder switches (P10 - P17), assign their value to a byte,
call serial LCD display and display the ascii character which the switches are set to ie. A for 65 (base 10)
I am new to spin and would appreciate any help.
Thanks "Potato"
Note the file will not attach so here is a cut and paste:
'' File Name: EID_01.spin
'' August 18, 2009
'' version 1.0
'' EID_01.spin
'' │
'' └──Serial_Lcd.spin
'' │
'' └──Simple_Serial.spin
''
'' P0 J5 pin 2
'' P1 J5 pin 3
'' P2 J5 pin 4 .. J5 pin 1 is gnd
''
'' P10 1 LSB
'' P11 2
'' P12 4
'' P13 8
'' P14 1 MSB
'' P15 2
'' P16 4
'' P17 8
''
'' P24 Serial Display 19_200
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
LCD_Pin =24 'Set up constantants
LCD_Baud = 19_200
LCD_Lines =2
OBJ
LCD : "Serial_Lcd" ' Objects to be used
Serial : "Simple_Serial" '
VAR
byte StationID
PUB XYZZY ' this is the start of the top object (Any name will do)
'
LCD.init(LCD_Pin, LCD_Baud, LCD_Lines) ' se up LCD
LCD.cursor(0) ' Turn Off Cursor
LCD.backlight(true) ' Turn On Backlight
dira~~ 'P2 is an output pin with a LED attached
outa~ 'Turn off LED
StationID := ina[noparse][[/noparse]10..17] 'assigns StationID value of HEX switches [noparse][[/noparse]00 to FF]
'Two hex switches are connected to pins 10 through 17
'LSB switch to pins 10 - 13 MSB switch to pins 14 -17
'
'
repeat '
LCD.cls ' Clear LCD screen
LCD.str(string("Emergency ID 1.0")) ' Print string
outa := ina[noparse][[/noparse]10] ' LED tied to pin 2, on if P10 is a one
waitcnt(clkfreq+cnt) ' one second delay
LCD.cls '
LCD.str(string(StationID)) ' display ascii value of switch setting <<<<<<<does not work<<<<<<<<
LCD.str(string(65)) ' THIS DOES WORK
waitcnt(clkfreq/2+cnt) ' 1/2 second delay
call serial LCD display and display the ascii character which the switches are set to ie. A for 65 (base 10)
I am new to spin and would appreciate any help.
Thanks "Potato"
Note the file will not attach so here is a cut and paste:
'' File Name: EID_01.spin
'' August 18, 2009
'' version 1.0
'' EID_01.spin
'' │
'' └──Serial_Lcd.spin
'' │
'' └──Simple_Serial.spin
''
'' P0 J5 pin 2
'' P1 J5 pin 3
'' P2 J5 pin 4 .. J5 pin 1 is gnd
''
'' P10 1 LSB
'' P11 2
'' P12 4
'' P13 8
'' P14 1 MSB
'' P15 2
'' P16 4
'' P17 8
''
'' P24 Serial Display 19_200
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
LCD_Pin =24 'Set up constantants
LCD_Baud = 19_200
LCD_Lines =2
OBJ
LCD : "Serial_Lcd" ' Objects to be used
Serial : "Simple_Serial" '
VAR
byte StationID
PUB XYZZY ' this is the start of the top object (Any name will do)
'
LCD.init(LCD_Pin, LCD_Baud, LCD_Lines) ' se up LCD
LCD.cursor(0) ' Turn Off Cursor
LCD.backlight(true) ' Turn On Backlight
dira~~ 'P2 is an output pin with a LED attached
outa~ 'Turn off LED
StationID := ina[noparse][[/noparse]10..17] 'assigns StationID value of HEX switches [noparse][[/noparse]00 to FF]
'Two hex switches are connected to pins 10 through 17
'LSB switch to pins 10 - 13 MSB switch to pins 14 -17
'
'
repeat '
LCD.cls ' Clear LCD screen
LCD.str(string("Emergency ID 1.0")) ' Print string
outa := ina[noparse][[/noparse]10] ' LED tied to pin 2, on if P10 is a one
waitcnt(clkfreq+cnt) ' one second delay
LCD.cls '
LCD.str(string(StationID)) ' display ascii value of switch setting <<<<<<<does not work<<<<<<<<
LCD.str(string(65)) ' THIS DOES WORK
waitcnt(clkfreq/2+cnt) ' 1/2 second delay
Comments
should be
The first line has the bits the wong way round so you get A6 hex - 01100101 -> 10100110
Thanks for pointing out my error of reversing MSB and LSB.
I think I am doing something wrong with the syntax. ?
Potato
LCD.str(string(StationID)) does not work because the method "str" expects a zero-terminated string or a hardcoded value
like in the line
LCD.str(string(65)) ' THIS DOES WORK
if you want to send a decimal value use
LCD.dec(StationID)
best regards
Stefan
When I put the line LCD.dec(StationID) it will not compile and
says: Expected a subroutine name and highlights .dec
I looked in Serial_LCD as well as Simple_Serial and the name, LCD_dec is not there.
I know we are close now but no cigar.
Potato
will output stationid as a 2 number decimal
lcd.putc(stationid) will output it as the ascii value i.e. "a'
Then, I want to send the value(00 to 255) to the display. This will tell me if the code is working. As I change the switches, I should see the ascii value of my variable
displayed change. Although not all all switch numbers will be a displayable characters, this tells me that the switches, and code are working.
Then:
After I get this working my goal is to refer to the variable StationID and compare that variable with another variable, say X. If the two variables match (StationID = X) I want to take a specific
action.
Additionally, I want to display on my LCD screen "Station ID: " decimal value ie. Station ID 254
I really appreciate your help. This is a great forum for a new prophead to learn.
Thanks to everyone for helping.
Potato
it will teach you how the methods str und dec work
this democode needs NO additional hardware at all
propeller-PCB and serial connection to your PC is all
not even an LCD !
Ok I didn't saw that you use the object Serial_LCD uses the object simple_serial
with the object serial_lcd you can use
LCD.str(string("Station ID "))
LCD.putc(StationID)
best regards
Stefan
Post Edited (StefanL38) : 8/17/2009 10:11:22 PM GMT
Now you referred to democode however I am so new, I don't know where to look for your attached program.
Don't you love the feeling when you finally get something to work! Now i rotate my Hex incoder switches and walk through the ascii character set!
Makes you want to sit back and smoke a cigarette (NO NO) and exclaim ugh.
Thanks,Potato
yes very good feeling
somehow the attachment went lost
see edited posting above
best regards
Stefan