PDA

View Full Version : HSERIN advice



ngeronikolos
- 26th May 2005, 10:21
Hello boys&girls,

I am using a PIC16F627 with external XT 4Mhz,ST232.My communication to my PC is already working.
I want to send from the hyperterminal 8 ASCII characters DOT1,DOT2...DOT8 using HSERIN.How can I do that?
After that the characters will be sent using I2C protocol.

I just want to know the way I will input the ASCII characters with HSERIN.

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["DOT1"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["DOT2"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["DOT3"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["DOT4"]


I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT0BOTHPLANESADDRESS, ["DOT5"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT1BOTHPLANESADDRESS, ["DOT6"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT2BOTHPLANESADDRESS, ["DOT7"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT3BOTHPLANESADDRESS, ["DOT8"]

ngeronikolos
- 26th May 2005, 12:43
THAT IS MY CODE IHAVE ALREADY WRITTEN BUT IT IS NOT WORKING PROPERTLY.
ANY IDEA?


Main:
SerData = 0
HSERIN [SerData]
IF SerData <> 0 THEN
hserout ["You typed:", SerData,10,13]
ELSE
Goto Main
ENDIF
PAUSE 1000
Goto OUT

Pause 1000


OUT:
I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["SerData[1]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["SerData[2]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["SerData[3]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["SerData[4]"]

ngeronikolos
- 26th May 2005, 16:03
That is a part of my program.Where is the wrong?The only thing I can see in hyperterminal is nikos.I can not put the 8 ASCII CHARACTERS.Hyperterminal does not allow me!!!
Any idea?

INCLUDE "MODEDEFS.BAS"

DEFINE OSC 4

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1

CMCON = 7

..................
SerData VAR BYTE [8]

Hserout [10,13,"nikos",10,13]
Pause 5000

Main:
HSerin 5000,Main,[ STR SerData\8]
PAUSE 500
HSEROUT ["You typed:", STR SerData\8,13,10]
PAUSE 500
Goto OUT

OUT:
I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT0BOTHPLANESADDRESS, ["SerData[1]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT1BOTHPLANESADDRESS, ["SerData[2]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT2BOTHPLANESADDRESS, ["SerData[3]"]

I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE1, DIGIT3BOTHPLANESADDRESS, ["SerData[4]"]


I2CWRITE SDA0, SCL0, DISPLAYCONTROLBYTE2, DIGIT0BOTHPLANESADDRESS, ["SerData[5]"]

mister_e
- 26th May 2005, 19:39
Hyperterminal is the best piece of ^^%#^ that i've never ever work with. Did you try with another program like MicroCodeStudio , RealTerm or else???

Also, don't forget that once you type something... your program will go to LaLaLand since you didn't tell to return to [main]. But probably it's an copy paste error too.

Can you also remove the PAUSE 5000 at the begining???

ngeronikolos
- 27th May 2005, 07:43
I would like to say the truth,I am working with Tera Term pro,which has no problem.
My program looks good or not?

Please advice.

mister_e
- 27th May 2005, 15:30
i tried by removing all the delay... no problems here. just smething must be 13,10 intead of 10,13

ngeronikolos
- 30th May 2005, 15:13
I tried that using the serial communicator.That is what I see WITHOUT sending any character:

--------------------------------
You typed: You typed: α

You typed: α

You typed: Φ

You typed: Φ

You typed: Φ

You typed: Φ
---------------------------------
It seems like sending by itself bytes.Where is the problem?



loop: IF RCIF = 1 THEN
Hserin [Serdata[1]] ' Get a char from serial port
else
goto starty
endif
HSEROUT ["You typed: ", SerData[1],10,13]
GOSUB OUT
Goto loop

starty: Hserout ["Nothing",10,13]
Goto loop

out:
......................................
return

Bruce
- 30th May 2005, 15:49
Here's a simple routine I use for testing. It will buffer up to 80 bytes, and
print it after receiving the end of message ~ character.


DEFINE LOADER_USED 1
DEFINE OSC 20
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1 ' Automatically clear over-run errors
DEFINE HSER_RCSTA 90h ' Enable USART receive
DEFINE HSER_TXSTA 24h ' TXSTA=%00100100. TX enable, BRGH=1 for high-speed
'DEFINE HSER_TXSTA 20h ' TXSTA=%00100000. TX enable, BRGH=0 for low-speed

GP VAR BYTE ' GP variable
BytesIn var byte[80] ' Up to 80 bytes
ByteCnt var byte ' Indicates number of bytes in buffer
EOM CON "~" ' EOM = "End Of Message" marker
OERR VAR RCSTA.1 ' Alias USART over-run bit
CREN VAR RCSTA.4 ' Alias USART continuous receive enable bit
RCIF VAR PIR1.5 ' Alias USART received character interrupt flag bit
INTCON = 0 ' Disable interrupts
ByteCnt = 0 ' Zero counter
ADCON1 = 7 ' A/D off, all digital

Main:
IF RCIF THEN ' If RCIF=1 there's a new character in RCREG
BytesIn[ByteCnt]=RCREG ' Yes. Then store it in array
IF BytesIn[ByteCnt]=EOM THEN OutMsg
ByteCnt=ByteCnt+1 ' Increment array index pointer
ENDIF
GOTO Main

OutMsg:
HSEROUT [13,10,dec ByteCnt," bytes received",13,10]
HSEROUT [STR BytesIn\ByteCnt,13,10]
FOR GP=0 TO ByteCnt ' Clear array bytes 0 to ByteCnt
BytesIn[GP]=0 '
NEXT '
ByteCnt=0 ' Reset index pointer back to first element
WHILE RCIF ' Keep reading until RCIF is clear to flush buffer
GP=RCREG ' after EOM is received
WEND
GOTO Main

END

ngeronikolos
- 31st May 2005, 09:02
Thanks my friend Bruce,
Now it is working with some problems.This is my code.
PROBLEM:When I send 8 bytes via Serial Communicator like this
qwertyui
the answer of the pic16f628-04 is:
You typed: qqqqqqqq
You typed: eeeeeeee
instead of
You typed: qwertyui
and it does not respond for the next inport stream(8bytes)

.................................................. ............................
loop: IF RCIF = 1 THEN
for i=0 to 7 STEP 1
RCREG = 0
SerData[i] = RCREG
if i=7 then type
NEXT i
endif
goto loop
type: HSEROUT ["You typed: ", str SerData\8,13,10]
GOSUB OUT
Goto loop


OUT:
.............................

ngeronikolos
- 31st May 2005, 10:57
I fix the problem and it is ok.
Question?How can I reach 38.4k baud
I try DEFINE HSER_BAUD 38400
DEFINE HSER_SPBRG 6
but notning.

My xt is 4Mhz and my pic16f627-04

Bruce
- 31st May 2005, 14:05
Unfortunately not every oscillator speed is going to produce the correct bit
timing for all data-rates.

With a 4MHz oscillator the error rate is -6.994% for 38400bps. The datasheet
shows the calculation for finding the right combination.