PDA

View Full Version : SEROUT,HSEROUT or DEBUG ? max 232 or no max232 ?



Dennis
- 21st November 2009, 17:12
I currently have my PC's serial port ready to send and receive to the PIC 18F4520....
I have a max232n connected and have connected the pic to the correct pins on the max232n.
I would like to receive the data in hyperterminal.
BUT would also like to experiment with HSEROUT and DEBUG etc

SO here are the questions.

Of the following choices SEROUT,HSEROUT or DEBUG which one do I choose
1.To communicate between two pics

2.From PC to PIC which one should I choose in the following instances
A.Without a max232n
B.With a max232n


3.From PIC to RF

4.From PIC to IR

For all the above when may I use the internal oscillator and when not ?

And lastly ....
Assuming the Port I would like to transmit/send the data out of is PORT C6
and the receiving port is PORT C 7,
would the line be something like


Loop:
SerOut PinNumber,T2400,DataOut
Pause 100 'Delay for Receive viewing
goto Loop

mackrackit
- 21st November 2009, 18:14
Of the following choices SEROUT,HSEROUT or DEBUG which one do I choose
1.To communicate between two pics
SEROUT,SEROUT2,HSEROUT


2.From PC to PIC which one should I choose in the following instances
A.Without a max232n
B.With a max232n
A.Without a max232n
SEROUT,SEROUT2,DEBUG
B.With a max232n
ANY


3.From PIC to RF

4.From PIC to IR
ANY


For all the above when may I use the internal oscillator and when not ?
Bauds 4800 and below most times


And lastly ....
Assuming the Port I would like to transmit/send the data out of is PORT C6
and the receiving port is PORT C 7,
would the line be something like


Loop:
SerOut PinNumber,T2400,DataOut
Pause 100 'Delay for Receive viewing
goto Loop

Looks OK

Dennis
- 21st November 2009, 18:41
Thanks a million DAVE

Now trying out SEROUT and it's working like a charm :-)

You answers have cleared up the confusion !

Once again THANK YOU

Keep well

kind regards

Dennis

Dennis
- 21st November 2009, 19:02
So far I have tested ..SEROUT,SEROUT2 and DEBUG :)

I just have an issue with somehow passing a variable around in my code it seems using SEROUT,SEROUT2 and DEBUG.

So far I can capture a keypress (thanks to mister e's matrix keypad routine and advice and tips from several others - thank you!)
The keypress from the keypad is stored in a variable called myvar.
I send myvar to the LCD using


lcdout dec myvar 'display keypress variable


and on the LCD the DECimal number lets say I press 1 on the keypad appears as ||1 and for the number 2 on keypad it appears as ||2 and so on.
If I change the code to convert myvar as BINary numbers like this


lcdout BIN myvar 'display keypress variable

then when I press the number 1 on the keypad I get ||1 on the LCD and then the keypad 2 shows as ||2 and so on.
NOW .....
If I use serout to send myvar to hyperterminal or MicroStudio serial port window like this


SerOut PORTC.6,T2400,["the key pressed is",myvar]


I just get "the key is pressed' followed by a windings kinda characters like smileys, blocks and so forth :-(

If I send a string with serout like this


SerOut PORTC.6,T2400,["the key pressed is"]

Then everytime I press a key I see "the key is pressed" appearing in hyperterminal.

Here is my code ....I would really appreciated if someone could point me towards finding a solution as ultimately I would like to TX the binary keypress to be RX for another PIC




'*************************************
'Keypress display on LCD and TX to wherever
'*************************************

'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines

'Port IO directions and presets for port pins begin here
'TRISX = %76543210 << tris bit order numbering
'TRISA = %11111111 'All pins are outputs
'// Define port pins as inputs and outputs ...
TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs,
TRISB = %11111111 'for 4x4 keypad all input
TRISC = %10000000
TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
'End of Port IO directions and presets for port pins begin here


'variables begin here
myvar var byte
dataout var byte
'end of variables

'LCD defines begin here
DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to
DEFINE LCD_EREG PORTD 'defines the port where E line is connected to
DEFINE LCD_EBIT 3 'defines the pin where E line is connected
DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used)
DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used)
DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 200 'delay in micro seconds
'END of LCD DEFINES

'includes begin here
INCLUDE "modedefs.bas"
include "c:\pbp\samples\keypad.bas"
'end of includes

'Keypad code begins here
DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
DEFINE KEYPAD_ROW_BIT 0 ' ROW0 = PORTB.4
DEFINE KEYPAD_COL 4 ' 4 COL keypad
DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.0
DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature
'end keypad code

'Main code begins here

Pause 2000 ' Wait for LCD to startup
start:
'read keypress variable
@ READKEYPAD _myvar

lcdout $fe, 1 'clear lcd screen

lcdout BIN myvar 'display keypress variable
SerOut PORTC.6,T2400,["the key pressed is",myvar] 'SerOut PinNumber2,T2400,DataRec
pause 1000
lcdout $fe,1 'clear lcd screen
goto start

'End of all code


Thank you

Kind regards
Dennis

mackrackit
- 21st November 2009, 19:19
Try
N2400

Gusse
- 21st November 2009, 19:42
Dennis,

Have you read this?
Communications Example : PC to PIC bi-directional dialogue (http://www.picbasic.co.uk/forum/showthread.php?t=573)

Thanks to Melanie! This helped me a lot when I did code, which communicated with PC.
:)

BR,
-Gusse-

Edit 1: I have used baud rate up to 38400 very successful. It might work even higher data rate (haven't try so far).
Edit 2: Running on 16F876A with 10MHz crystal, haven't tested with PIC that has internal oscillator. 1k5 resistors between PC and PIC (TX & RX).

Dennis
- 21st November 2009, 20:04
Will definitely check it out and do the suggested tests :-)
Thank you

Dennis
- 21st November 2009, 20:07
Have tried N2400 ... no luck :-(
Correct me if I'm wrong but surely is well if the string arrives correctly ?

Darrel Taylor
- 21st November 2009, 21:28
DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used)
DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used)
I don't think it's a good idea to set those to 0.
It will end up overwriting bit0 at address 0 in RAM which is normally PBP's R0 system variable.

Try it without those lines.

hth,

Dennis
- 21st November 2009, 23:53
Darrel ....
10 points on spotting this issue ... dude can I borrow those 'fine-tooth comb code-eyes' ???

So I removed the lines...
and here are the results .....
1. LCD response is a million times faster.
2. Keypresses happen almost instantly now
3. The LCD was not responding to


lcdout $fe,1 'clear lcd screen

Now it responds like it should ...each keypress displays correctly, no funny wingdings like characters :-)
and ... the LCD display clears after every keypress :-)
YAY
The LCD and keypress system is working like it should WOOOHOOOOO !!

Thanks a million
:-)

Kind regards
Dennis

PS... I still want to know how you noticed that ?? Past experiences ?

Now all that remains is solving my SEROUT variable passing issue so I can see proper characters in hyperterminal :-)
I keep getting a little square in hyperterminal as the keypress occurs but on the LCD it appears correct :-(

the key pressed isthe key pressed isthe key pressed is

mackrackit
- 22nd November 2009, 00:03
Have tried N2400 ... no luck :-(
Correct me if I'm wrong but surely is well if the string arrives correctly ?

Now all that remains is solving my serout variable passing issue so I can see proper characters in hyperterminal :-)
now I am confused....

Dennis
- 22nd November 2009, 00:09
At least I'm not alone then :-)

I'm sure it has to do with passing the variable 'cos a 'string like this' appears just fine !

And if I LCDOUT myvar that works fine on the LCD

What doesn't work fine is when I SEROUT the variable myvar and try read it in hyperterminal

WEIRD or what ?

In fact with SEROUT using N2400 the output is worse and even the string of text is wingings :-)
See next post here for the output screenshot... this tells me that T2400 is correct !

Dennis
- 22nd November 2009, 00:27
See the Received window

Darrel Taylor
- 22nd November 2009, 00:37
WOOHOO!


dude can I borrow those 'fine-tooth comb code-eyes' ???Well, I do have 4 eyes, so I guess you can have a couple of them. :)
Need a new pair of specs anyhow.

For the SEROUT prob...
Steve's keypad routine returns a result that represents the number of the key. For a 4x4 pad it's 1-16.

With a LOOKUP statement you can change them to match your keypad ...

LOOKUP myvar,[0,"123A456B789C*0#D"],myvar

hthm,

Dennis
- 22nd November 2009, 00:56
Darrel


.'
?Is Steve mister e ??
Code-wise I tried , Bruce's code and Trent Jackson's code ....
Mister e's is what I'm using at the moment, it was the one that worked for me, but the other would probably work now that the LCD problem is cleared up ;-) ...

Where is the keypad code you are referring to ? I am willing to give it a bash :-)

Kind regards

Dennis

Oh and I sure did get my fair share of moving wires and resistors around to get the correct column and row assingments ;-)
Roll on virtual ports hey ?

Darrel Taylor
- 22nd November 2009, 01:17
Yup, Steve is mister-e.

By changing from key numbers to ASCII with the Lookup, your serout should work better.
<br>

Dennis
- 22nd November 2009, 01:28
Darrel :-)

So with 8 sets of eyes in total now :D ... should I add the LOOKUP prior to making the assembly key lookup like this ?


start:
'read keypress variable
@ READKEYPAD _myvar
LOOKUP myvar,[0,"123A456B789C*0#D"],myvar
'lcdout $fe, 1 'clear lcd screen
'pause 2000
lcdout dec myvar 'display keypress variable myvar

'transmit section
SerOut PORTC.6,T2400,["the key pressed is",myvar] 'SerOut PinNumber2,T2400,DataRec
pause 1000
'transmit section ends

'receive section
'SerIn PORTC.7,T2400,DataRX
'LCDOUT datarx 'displays data received from serin datarx
'receive section ends
lcdout $fe,1 'clear lcd screen

goto start


Kind regards
Dennis


@ READKEYPAD _myvar

Darrel Taylor
- 22nd November 2009, 01:35
Except for the DEC modifier, good to go.



start:
'read keypress variable
@ READKEYPAD _myvar
LOOKUP myvar,[0,"123A456B789C*0#D"],myvar
'lcdout $fe, 1 'clear lcd screen
'pause 2000
lcdout <strike>dec</strike> myvar 'display keypress variable myvar

'transmit section
SerOut PORTC.6,T2400,["the key pressed is",myvar] 'SerOut PinNumber2,T2400,DataRec
pause 1000
'transmit section ends

'receive section
'SerIn PORTC.7,T2400,DataRX
'LCDOUT datarx 'displays data received from serin datarx
'receive section ends
lcdout $fe,1 'clear lcd screen

goto start

Dennis
- 22nd November 2009, 01:45
OK got your message after I tried with the DEC modifier ;-) nothing worked !
So I removed it and .....
The LCD now shows the correct characters as per what I type in 123 etc and the ABCD keys as well as # and * ....YAY.....
but sadly now nothing appears in hyperterminal ....
Does SEROUT now need to be replaced by SEROUT2 ?
Will try it later and post results either way :-)
Need some sleep now ..
Thanks so much for your continued help :-) much appreciated !

Keep well

Kind regards
Dennis

OH .. by the way .. do you maybe know how I could capture a keyin of the number say 135 # so that it is actually stored as binary or decimal 135 ?

Darrel Taylor
- 22nd November 2009, 01:58
but sadly now nothing appears in hyperterminal ....
Does SEROUT now need to be replaced by SEROUT2 ?
If you have PBP 2.60 then that will help. SEROUT has a buad rate problem.


OH .. by the way .. do you maybe know how I could capture a keyin of the number say 135 # so that it is actually stored as binary or decimal 135 ?
If you have 2.60, it's real easy with ARRAYREAD.
<br>

Dennis
- 22nd November 2009, 10:32
Hi Darrel

Problem seems to be solved now.

And the solution was in the very problem itself ...passing the variable !!

I created a new variable called datatx
and then after the displaying myvar to LCD with LCDOUT,
all I did was let datatrx = myvar
then SEROUT myvar
And whammo it works :-) YAY ...!

Thanks so much for all your help !

Here's the code for reference and for anyone who might find it useful
It captures a keypress, diplays it on the LCD and send the captured keypress via SEROUT.

Kind regards
Dennis



'*************************************
'Keypress display on LCD and TX to wherever
'*************************************

'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines

'Port IO directions and presets for port pins begin here
'TRISX = %76543210 << tris bit order numbering
'TRISA = %11111111 'All pins are outputs
'// Define port pins as inputs and outputs ...
TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs,
TRISB = %11111111 'for 4x4 keypad all input
TRISC = %10000000
TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
'End of Port IO directions and presets for port pins begin here


'variables begin here
myvar var byte
datatx var byte
datarx var byte
'end of variables

'LCD defines begin here
DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to
DEFINE LCD_EREG PORTD 'defines the port where E line is connected to
DEFINE LCD_EBIT 3 'defines the pin where E line is connected
'DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used)
'DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used)
DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 200 'delay in micro seconds
'END of LCD DEFINES

'includes begin here
INCLUDE "modedefs.bas"
include "c:\pbp\samples\keypad.bas"
'end of includes

'Keypad code begins here
DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
DEFINE KEYPAD_ROW_BIT 0 ' ROW0 = PORTB.4
DEFINE KEYPAD_COL 4 ' 4 COL keypad
DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.0
DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature
'end keypad code

'Main code begins here

Pause 2000 ' Wait for LCD to startup
start:
'read keypress variable
@ READKEYPAD _myvar
LOOKUP myvar,[0,"123A456B789C*0#D"],myvar

'lcdout $fe, 1 'clear lcd screen
'pause 2000
lcdout myvar 'display keypress variable myvar

datatx = myvar '<<<<here's the solution :-)
lcdout datatx
'transmit section
'THE PROBLEM LINE >>> SerOut PORTC.6,T2400,["the key pressed is ",datatx]
SerOut PORTC.6,T2400,["the key pressed is ",datatx] 'SerOut PinNumber2,T2400,DataRec (FIXED!!
pause 1000
'transmit section ends

'receive section
'SerIn PORTC.7,T2400,DataRX
'LCDOUT datarx 'displays data received from serin datarx
'receive section ends
lcdout $fe,1 'clear lcd screen

goto start

'End of all code

Darrel Taylor
- 22nd November 2009, 16:49
I created a new variable called datatx
and then after the displaying myvar to LCD with LCDOUT,
all I did was let datatrx = myvar
then SEROUT myvar
And whammo it works :-) YAY ...!


Well, I'm glad it's working, but I don't think that's what fixed it.

All that did was copy a byte var to another byte var then displays the copied var. It's no different than displaying the original var in the first place.

And since it works, I assume that means you don't have PBP 2.60, so I won't need to show an ARRAYREAD example.
<br>

Dennis
- 22nd November 2009, 18:24
Hi again Darrel

Would love to see an ARRAY read example if you have the time ..if not just point me to a place to read about or reference it :-)

Kind regards

Dennis

Heckler
- 9th March 2010, 15:43
Not sure what sort of ARRAYREAD example you are looking for... but here is one example.

I am simply reading in a NMEA string from a gps unit and then parsing the NMEA sentence using ARRAYREAD.

The underscore at the end of each line of the arrayread statement allows you to wrap the text so you do not have such a LONG sentence, yet it is still all one PBP statement.



serin2 gps,188,3000,tmout,[WAIT("$GPRMC,"),STR GPRMC\63\"$"]

arrayread gprmc,[DEC2 hh,DEC2 mm,dec2 ss,_
wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait("."),dec4 latminn,_
wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait("."),dec4 lonminn,_
wait(","),EW,wait(","),dec knots,dec Knotss,dec course,_
wait(","),DEC2 dy,DEC2 mt,DEC2 yr]

Dwight

RobertDW
- 20th April 2017, 03:23
Hi Dennis I'm brand new to the forum.
I see your question about the usage of max232 is my question as well, I have built an interface with a Wi-Fi chip and asked them if I needed the MAX232 chip to stabilise the signal quality using the picbasic "SEROUT" function and showed them an oscilloscope image of the signal produced and they were very busy and answered with "device connect to Wi-Fi is RS232 interface, the MAX232 chip is needed but not if UART".Did you find out if the process is RS232 or UART ?83978398

mackrackit
- 20th April 2017, 04:26
You replied to a seven year old thread... It would be best to start a new thread.

When you start the new thread be sure to include the PIC you are using along with the WIFI module you are using. Without knowing this we would just be guessing about the best solution for you.

ardhuru
- 27th April 2017, 08:44
Hi,

Can I assume your wifi device is a variation of the ESP8266? If so, you would NOT require a MAX chip between the PIC and the Wifi module. Serout, Hserout should work, as also debug (the last in mode 0).

Only thing to remember is the Wifi module, depending on the version you have might not be 5 volt tolerant.

Regards,

Anand Dhuru

RobertDW
- 28th April 2017, 17:09
Hello ardhuru,
I took mackrackit's advice and moved my quiry to http://www.picbasic.co.uk/forum/showthread.php?t=22510
cheers