Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RS232 to PC questions.. Thanks!

Status
Not open for further replies.

Zane83

New Member
Hi,

I'd done my ADC programming and seems like i have to try it on hardware. Since that i'm using 16F877A, the conversion result is in 10bits. I saw Nigel's tutorial and its good for sending 8 bits by using rotating method. May i know what if i have to transmit the 10bits to PC?

Is it by configuring the startbit and stopbit to solve my problem? Or send the last 2 bits before 104us after sending the last bit in my NumL register? I stored my 10 bits conversion result in NumL and NumH. I'm using ADRESL for the ADC. Thanks for your help. Do appreciates if anyone could give me some better ideas from mine!

Thanks again!
 
You can break the 10 bits into two characters anyway you like. The only requirement is that boths sides of the hose have to use the same interpretation.
 
There are a number of ways you can do this.

One way would be to split it into 5 bit words. Your problem then is knowing which 2 lots of 5 bits to put back together at the PC end. One solution to get around this would be to set the top bit of the second 5 bits sent.

The pic code would look something like,
Code:
		bsf	STATUS,RP0
		movfw	ADRESL;        get low byte
		bcf	STATUS,RP0
		movwf	ADCVal;         store for later
		andlw	b'00011111';   keep the lower 5 bits
		call	SendRS232;    send it
; now shift the ADC value right 5 bits.
		rrf	ADRESH,F
		rrf	ADCVal,F
		rrf	ADRESH,F
		rrf	ADCVal,F
		rrf	ADCVal,F
		rrf	ADCVal,F
		rrf	ADCVal,F
		movfw	ADCVal
		andlw	b'00011111';   keep the lower 5 bits
		iorlw	b'10000000';   set top bit
		call	SendRS232

On the PC end you would do something like
Code:
Loop:
	temp= GetRS232
	if temp>128 then 
		Print "ADC = "; (temp-128)*32+lower
	else
		lower=temp
	endif
	goto Loop

Alternatively, you would convert the ADC value to ASCII (see Nigel's tutorial) and send a string such as "ADC=0513" (+crlf) if the ADC returned 0x201. This method allows hyperterminal to be used to view the results.

HTH


Mike.
 
Last edited:
Thanks papabravo and mike. I'll try with it.

Anyway, i'm actually MPLab for PIC programming. May i know that is the loop used for PIC programming or for the PC part (receiving from PC)? I'm not familiar with the coding below. Thanks.

PHP:
Loop:
	temp= GetRS232
	if temp>128 then 
		Print "ADC = "; (temp-128)*32+lower
	else
		lower=temp
	endif
	goto Loop
 
The code for the PC is pseudo BASIC. If your having a problem understanding it then I think you are going to struggle writing the PC code.

Mike.
 
Probably the easiest way (which is already present in my tutorials) is to send the data as a simple ASCII string terminated with CR/LF - this cures all the problems over which byte is which, and the number of bits. Plus it makes the PC side EXTREMELY easy to do.

Check tutorial 11.4
 
Last edited:
Nigel,
That was my second suggestion. I even mentioned your tutorial.:D

Mike.
 
Nigel Goodwin said:
Probably the easiest way (which is already present in my tutorials) is to send the data as a simple ASCII string terminated with CR/LF - this cures all the problems over which byte is which, and the number of bits. Plus it makes the PC side EXTREMELY easy to do.

Check tutorial 11.4

Thanks alot Nigel and Mike. I'll check the tutorial again.

Seriously this is the first time i try to interface and send data to PC from PIC using RS232.:confused: Hope you don't mind, if there are any things which i have to take note, do let me know. Thanks!
 
hi zane83 ,
i think you missed the part where Pommie sugested using Hyperterminal?
are you thinking of collecting the data on the pc without a terminal program?

in this link another terminal progam which collects your data via RS232 and uses a PIC 16C773 to get the data and another to send the data to their pc terminal program
**broken link removed**
although it uses a serial memory device for storing the data .
 
williB said:
hi zane83 ,
i think you missed the part where Pommie sugested using Hyperterminal?
are you thinking of collecting the data on the pc without a terminal program?

in this link another terminal progam which collects your data via RS232 and uses a PIC 16C773 to get the data and another to send the data to their pc terminal program
**broken link removed**
although it uses a serial memory device for storing the data .

Hi williB,

i think i used before the Hyperterminal in lab before, to send data from chip Motorola 68k uP using application board. But it's all well set up when i used it so i don't really know the configuration bout it. My fault. Sigh~

Actually i'm thinking of receiving the data by using Visual Basic (which i heard could be used to receive data from RS232 port). Is it necessary to use Hyperterminal again if i intend to use VB to receive data? Where actually the data located when it is sent through RS232 into our PC?

Thanks
 
In VB use the mscomm control to access your serial port.
Use mscomm.input to retrieve characters fom the input buffer.

Like Nigel already suggest, send ASCII characters!!
If you need to send 1 byte of data containing number 125, send three bytes 31h; 32h and 35h with a CRLF or any other character to seperate the data bytes.

The mscomm control holds back some bytes, bytes containing 0 aren't passed by the mscomm control (maybe others also but I didn't try it), so you can't send the data directly like I was first doing.

You don't need hypertermianl at all but it's an easy way to test your PIC program. If hyperterminal show the data the PIC send, your PIC program is Ok, you can start with your VB code.
 
mcs51mc said:
The mscomm control holds back some bytes, bytes containing 0 aren't passed by the mscomm control (maybe others also but I didn't try it), so you can't send the data directly like I was first doing.

To make MSComm control receive all bytes,
Set
MSComm1.NullDiscard=false
MSComm1.RThreshold=1

The first one is obvious, the second is required if you use a USB to RS232 converter but won't do any harm anyway. The USB to RS232 converters that use the FT chip interpret a receive threshold length of 0 as 65536 :eek: This causes a huge delay in your data.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top