HELP! Serial input between Pic and PC (urgent)


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    11

    Unhappy HELP! Serial input between Pic and PC (urgent)

    Hello,

    I was wrote a simple program to test on the hyperterminal but it cannot function. I am using max232 to communicate the pic (16F877A)and pc. So, can somebody pls help me to check about it? I was try to figure out where is the problem for a few day already.

    **remark: I'm not using the USART function is due to the pin was reserved for others function.

    Source Code:
    '################################################# #########
    Define OSC 10
    include "Modedefs.bas"
    ADCON1 = 6

    TRISA = %111000
    TRISB = 0

    B0 var byte

    PORTB = 0

    Main:

    serin PORTA.3,T9600,B0
    pause 1000

    if (B0==1) then PORTB = %00010001
    if (B0==2) then PORTB = %00100010
    if (B0==3) then PORTB = %00110011
    if (B0==4) THEN PORTB = %01000100
    If (B0==5) THEN PORTB = %01010101
    if (B0==6) then PORTB = %01100110
    if (B0==7) then PORTB = %01110111
    if (B0==8) then PORTB = %10001000
    if (B0==9) THEN PORTB = %10011001
    if (B0=="A") THEN PORTB = %10101010
    if (B0=="B") then PORTB = %10111011
    if (B0=="C") then PORTB = %11001100
    if (B0=="D") then PORTB = %11011101
    if (B0=="E") THEN PORTB = %11101110
    if (B0=="F") THEN PORTB = %11111111
    PAUSE 1000


    GOTO MAIN

    '################################################# #######
    Thanks in advance

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    For starters, you are using already 2 seconds delay inthe loop. I am sure you are going to loose many data between this time spent on waiting.

    Please provide more info on the program at PC side. What is sending and at what rate?

    Also == has to be replaced by = and the () are not needed here.

    One recommendation would be to have the PC send a start character like : and PIC wait for this character and then grab the next one.

    like this:
    serin PORTA.3,T9600,[":"],B0

    Also ged rid off the pause commands.

    Ioannis

  3. #3
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hello,

    The setting for the hyperterminal are:
    #################
    bit per second = 9600
    Data bits = 8
    Parity = None
    Stop bits = 0
    Flow Control = 0
    #################

    I need to send the character form pc to pic, say i type the 1 into the hyperterminal then the led on the pic side will on %00010001

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    The code as you wrote it will respond only to characters "A" to "F" and only if you have caps lock!

    1, 2, 3 etc are coded as binary in your program, not ASCII. You have to use even for them the " ", e.g. "1", "2" etc.

    Also as I have told you on the previous post, at least the first delay should go away.

    A very good example can be found here:

    http://www.picbasic.co.uk/forum/show...hlight=parsing

    and a bit confusing here:

    http://www.picbasic.co.uk/forum/show...ghlight=Serial

    Ioannis

  5. #5
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hello,

    1. Mr Ioannis, thanks for your reply. I was modified my program but still have no result.

    Source Code:
    '################################################# #########
    Define OSC 10
    include "Modedefs.bas"
    ADCON1 = 6

    TRISA = %111000
    TRISB = 0

    B0 var byte

    PORTB = 0

    Main:

    serin PORTA.3,T9600,B0

    if B0="1" then PORTB = %00010001
    if B0="2" then PORTB = %00100010
    if B0="3" then PORTB = %00110011
    if B0="4" THEN PORTB = %01000100
    If B0="5" THEN PORTB = %01010101
    if B0="6" then PORTB = %01100110
    if B0="7" then PORTB = %01110111
    if B0="8" then PORTB = %10001000
    if B0="9" THEN PORTB = %10011001
    if B0="A" THEN PORTB = %10101010
    if B0="B" then PORTB = %10111011
    if B0="C" then PORTB = %11001100
    if B0="D" then PORTB = %11011101
    if B0="E" THEN PORTB = %11101110
    if B0="F" THEN PORTB = %11111111

    GOTO MAIN
    ############################################

    2. What is the difference between T9600 and N9600? If I'm using a max232 IC then which type should i use?

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


    Did you find this post helpful? Yes | No

    Default

    With SERIN and a MAX232 you need to use T9600.

    Try Sending Data fom your PIC to your PC to see what happen.

    I feel some hardware and configuration fuse problem here...

    You may also try with DEBUG/DEBUGIN...
    Last edited by mister_e; - 6th December 2007 at 04:10.
    Steve

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

Similar Threads

  1. Send binary file to pic over pc serial port
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 3rd May 2011, 13:47
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  4. High Speed Serial Comm PC - PIC and PIC - PIC
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 16th January 2007, 21:55
  5. Replies: 5
    Last Post: - 20th March 2006, 01:34

Members who have read this thread : 0

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