Log in

View Full Version : Problem about serial communication how to send a byte(127) from PC to PIC?



mengckid
- 18th March 2006, 15:01
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?

mister_e
- 18th March 2006, 19:55
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.

mengckid
- 19th March 2006, 05:21
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

mengckid
- 19th March 2006, 05:30
[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

mister_e
- 19th March 2006, 08:52
PC Side:
MsCommOutput="127"

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

mengckid
- 20th March 2006, 01:34
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