RS232 with 16F628 problem


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2005
    Posts
    49

    Question RS232 with 16F628 problem

    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.
    Attached Images Attached Images  
    Last edited by SuB-ZeRo; - 5th June 2005 at 07:16.
    Asking is not a shame but not learning is a SHAME!!!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Code:
    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.

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Red face I try...

    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.
    Asking is not a shame but not learning is a SHAME!!!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    code example for your PIC
    Code:
    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
    Attached Files Attached Files
    Last edited by mister_e; - 5th June 2005 at 12:02.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Unhappy Works but not good...

    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
    Asking is not a shame but not learning is a SHAME!!!

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Talking Yes it works :)

    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.
    Asking is not a shame but not learning is a SHAME!!!

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Strange problem with Serin/Serout on 16F628
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 22nd August 2008, 00:16
  2. Replies: 3
    Last Post: - 12th February 2007, 18:32
  3. Wavecom with 16F628 communication problem
    By ericbeaugiuet in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd June 2006, 11:05
  4. 16F628 problem
    By Brown in forum mel PIC BASIC
    Replies: 1
    Last Post: - 6th May 2005, 19:56
  5. 16F628 on-chip eeprom problem
    By atomski in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 4th March 2004, 07:43

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts