PDA

View Full Version : RS232 with 16F628 problem



SuB-ZeRo
- 5th June 2005, 07:13
I am useing that shema on the picture.But i have a little problem.
I am trying to count the button =B1 and it shows on LCD (it works)
In the other way button 2 =B2 shows all button count (it works)
but i can't sent these countings to the pc
if someone can show me how can i sent the counts to the pc when the pc got the count the pc will sent to pic " ok i got it" and the pic will erase only the count but i really can't find how. :(

mister_e
- 5th June 2005, 09:09
What about your actual code? wich software are you using on the PC side to get from your PIC? The easy on is the serial windows in MicroCode Studio

let's assume you have an 4Mhz Crystal


TXSTA=$24
RCSTA=$90
SPBRG=25 'Set BaudRate to 9600 bauds

HSEROUT["Button count=",#B1,13,10]


What you need to do your task is a few lines in Visual Basic or else PC language. In VB, you'll use MSComm32.ocx and presto it's done.



HSERIN[WAIT("ok i got it")] ' wait PC confirmation
B1=0

SuB-ZeRo
- 5th June 2005, 09:49
Yes i try what u wrote but not work.I know VB. and i use mscom and set mscom to com port 2 i put a text box and com.ocx and a timer timer invertal=100 ms
timer codes:
Text1.Text = Text1.Text & msc.CommEvent
and i can only read 00000000000000...... nothing else i check the board 10 times everything is ok!
when i chance the baudrate like N9600 to another something comes but like 1001 or 1004 after i try basic thigs like
'''''''''''''''code start
Include "modedefs.bas"
b1 var byte
b1=100
loop:
serout portb.2,n9600,["deneme:",#b1,13,10]
pause 5000
goto loop:
end
'''''''''''''''code ends
and again nothing only 000000000...... comes to the screen
plz give me an basic example like code only send to pc "hello world"
and if u know VB. give me an example how to read
thanx for your interest.

mister_e
- 5th June 2005, 11:59
code example for your PIC



RCSTA=$90
TXSTA=$24
SPBRG=129 '9600 bauds @20MHZ use the according for your crystal

Start:
HSEROUT["HELLO",13,10]
PAUSE 500
GOTO START


i've attach the VB stuff

SuB-ZeRo
- 5th June 2005, 16:58
Yes it work but i get another characters in the screen.
here is my configration
i am useing 16F628 with 4.433619 Mghz Xtall and 20 Pf capacitors
Max232 connected with pic (connection is correct if not i can't see anything)
I used the codes that u sent me but i chance a little
''''''''''''''''''''''''THE CODES
RCSTA=$90
TXSTA=$24
SPBRG=103 'FOR 2400 BAUD RATE

Start:
HSEROUT["HELLO",13,10]
PAUSE 500
GOTO START

'''''''''''''''''''''''THE CODES END
And in the VB. example i chance the com port 1 to 2
and baudrate=2400
and here what i see in the mini terminal
text1.text=*)Âu‚*
i can't see the HELLO :(
i really can't find the problem

mister_e
- 5th June 2005, 21:56
i don't have any of those 4.XXX crystal here and that cause you timing problem... for sure since PBP don't know that specific speed. Easy way to solve the problem, use the internal 4mhz one wich you can select at the programing time or by setting the configuration fuse into your program.
set configuration fuse into your program (http://www.picbasic.co.uk/forum/showthread.php?t=543)

another way, let's calculate the right SPBRG value for your crystal. By using the formula in the datasheet use SPBRG=114 or 115 try both.

SuB-ZeRo
- 5th June 2005, 23:51
SPBRG=114 is the correct number.How can u calculate the number 114?Can u teach me?Or is there any simple program that calculates that value?It really works good :) u help me soo much i really don't know how to thank u.

mister_e
- 6th June 2005, 03:19
Great!

The way to calculate the SPBRG is in the datasheet. section 12.1 table 12-1

I set BRGH=1 in the TXSTA value so you use

BaudRate=Fosc/(16(x+1))

few math mods later you get
X=(Fosc/(BaudRate*16))-1

now you can easily do you own VB calculator for that :)