+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    mengckid's Avatar
    mengckid Guest

    Default Problem about serial communication how to send a byte(127) from PC to PIC?

    Hi...guys, nice to meet u here,guys...i am facing a problem about serial communication, the PIC i am using is PIC 16F874A model

    Here, i got a problem about serial communication how to send a byte(127) from PC to PIC, at the same time, PC will receive 127,127,127,127...continuosly or non-stop?

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

    Default

    On the PC-Side you can send your Byte in Text, wich will send 3 bytes 1,2,7 OR simply send the decimal Value 127, or.. or.. or...

    ON the PIC Side, depending the way you sent the data on the PC side, you may need to use Serial qualifier like DEC or else

    PBP manual in SERIN2 section for detailed explanation.

    And if you search just a little bit on this forum, you may found 1-2 threads about serial communication.
    Steve

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

  3. #3
    mengckid's Avatar
    mengckid Guest

    Default This is my code, and the compiler i am using is Microcode PicBasic Pro

    My code:

    INCLUDE "modedefs.bas" 'include serout defines
    DEFINE OSC 4

    TRISB =%00000001 'port b=output except pin 1 (RX) is input
    TRISC = %10111000 ' set output for pwm portc.2

    RX var word
    RY var word
    RZ var word
    temp var word

    CCP1CON = %00001111 'turns PWM mode on, clears lowest two bits of duty cycle

    high PORTB.2

    main:
    PIE1.5 = 1
    INTCON = %11000000
    ON INTERRUPT GoTo handler

    '-------- interrupt start --------'

    disable
    handler:
    serin PORTB.0, T2400, RX, RY, RZ 'Receive menu number
    if (RX != "1") AND (RY != "2") and (RZ!= "7") then error
    RX = RX - $30
    RY = RY - $30
    RZ = RZ - $30
    temp=(RX*100)+(RY*10)+(RZ*1)
    gosub speed

    speed: pwm PORTC.1,temp,100
    serout PORTB.1,T2400,[#temp,100]
    resume
    enable

    ERROR: RX = RX - $30
    RY = RY - $30
    RZ = RZ - $30
    temp=(RX*100)+(RY*10)+(RZ*1)
    clear
    gosub speed

  4. #4
    mengckid's Avatar
    mengckid Guest

    Default

    [QUOTE=mister_e]On the PC-Side you can send your Byte in Text, wich will send 3 bytes 1,2,7 OR simply send the decimal Value 127, or.. or.. or...

    ON the PIC Side, depending the way you sent the data on the PC side, you may need to use Serial qualifier like DEC or else

    PBP manual in SERIN2 section for detailed explanation.

    And if you search just a little bit on this forum, you may found 1-2 threads about serial communication.[/QUOT

    Hi, mister_e,

    On the PC side,i will send 3 bytes 1,2 and7...and then pic will do the on interupt routine to check the incoming bytes received was 127 or not? if nope will go to ERROR routine to clear all the variables inside pic...

    The way i sent the data on the PC side, i design a GUI by using Visual Basic 6.0...i think should be nope problem.

    By the way, can help me check my code, i think got some problems.

    First, when PC send 127, PC will receive back two characters, first character is unknow word or number, the second character is 127d.

    after that, PC send 000, PC will receive 0d, then PC send 127 again, PC will receive 127,127 prefect. However, i try to send any number from PC, PC cannot receive any character? So, what is problem?

    Cheers, n thanks
    By, steven

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

    Default

    PC Side:
    MsCommOutput="127"

    PIC Side:
    SERIN2 SerPin,BAUD,[DEC YourVar]
    if YouVar=127 then goto GetABeer
    Steve

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

  6. #6
    mengckid's Avatar
    mengckid Guest

    Default Reply:

    Thus, another problem is PWM command...

    let say,
    MsCommOutput="127"

    PIC Side:
    SERIN2 SerPin,BAUD,[DEC YourVar]
    if YouVar=127 then goto GetABeer

    I put YouVar into pwm, portc.1,YouVar,100
    my DC motor will run at half speed at the short period (0.05mili secs), then motor will run at full speed after that.

    So, what is the problem? I feel very happy to know the reason...anyway, thanks u

Similar Threads

  1. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  2. help for serial communication pic to pic
    By jasem700 in forum Serial
    Replies: 7
    Last Post: - 27th February 2009, 16:06
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. PIC to PIC Serial Communication
    By v_merino in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd July 2004, 07:05
  5. serial communication problem
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th July 2004, 17:41

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