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.

Using RS232 to transmit analog signal to PC

Status
Not open for further replies.

beum

New Member
Hi, everyone.

I plan to build an device capable to transmit signal from strain gauge to PC using UART function of PIC16F877.

my c code is as follow:
#include <16f876.h>
#fuses hs, noprotect, nowdt, brownout, nolvp
#device adc=10
#use delay (clock=20000000)
#use rs232 (baud=96500, xmit=PIN_C6, rcv=PIN_C7, parity=N)
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7

void main()
{
int value;

setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);


do
{ value=read_adc();
value = getc();
printf("%2x/n/r",value);
}
while(TRUE);
}


And i also have no idea to read my signal coming out from RS232 in PC.
Is there any freeware to read signal of most form from rs232?

Is my C code correct?

Thanks for any help , advice. very appreciate it.

beum.
 
more details.

i use PORT A to input the signal.
i use function generator to input the signal.

i have two chip, both 16F876 and 16F877.
 
And i also have no idea to read my signal coming out from RS232 in PC.
Is there any freeware to read signal of most form from rs232?

You can use Hyperterminal on your PC if you convert the value to ASCII in your pic first.
 
thanks for suggestion

it's nice to receive reply.

Do you mind to show me how to convert it to ASCII code?
i am quite confused with the "printf" code..


thanks
 
Your processor/compiler might have "itoa" (integer to ascii) but the "least code" method I find useful with my processor/compiler is

sprintf(Ascii_RESULT, "%d", BYTE_TO_CONVERT);

Beware that this typically sticks a NULL character (0x00) in the follow on memory location. (2 bytes)
and "Ascii_RESULT" is an ADDRESS and not a variable.
 
Last edited:
thanks for reply

grateful for both reply :)

i will try it out later and consult over here again if any problem encountered cant be solved..

thanks again.


but i want to know is there any freeware available to receive analog signal from PIC? in waveform, i mean
 
This is one of the reasons I like AVRs over PICs. There is a fully ported version of GCC for AVR. Free opensource and a wide user base.
 
Do you have a post somewhere where you explain in detail what the advantages of AVRs are? I'm newer to this, and I'm learning PICs because everyone I've met who actually works with microcontrollers uses them. But since I'm still a beginner I might as well consider all options, and you keep mentioning how much you like AVRs.
 
That's because I do like them Triode =) I spent over a month researching the differences between PICs and AVRs before I chose. I even gave a few other processors a shot but the support for anything aside from PIC/AVR is horrible in general.


The primary thing about PIC's is their instructions are executed once every 4 system clocks. So at 20mhz the clock has to tick 4 times to execute an instruction. With an AVR they're fully pipelined which means every clock tick an instruction is executed. This is only true for basic mathmatic operations, branching instructions take up to 4 clock ticks to execute on an AVR but math and I/O operations are all single cycle, and I think PICs might hae this as well but an AVR I/O line can be toggled in a single cycle witout reading the state of the I/O pin. Basically this means that for a given clock speed an AVR is ALWAYS faster. There is actually a software only USB implementation out there for AVR's, the same can not be done with any normal PIC.

The second true advantage is ease of ASM programing. A PIC only has one working register and has to switch banks to access more which requires yet more instructions. An AVR has 32 general purpose registers, 16 of which are directly accessible via the math unit at any time, the other 16 only certain instructions work on. So programming fast efficient code in ASM on an AVR is an order of magnitude or better than a PIC. They have index registers as well that make for efficient C programming on AVR's.

Some PIC's do have PLL units to increase the processor speed relative to the incoming clock rate... Thing is, so do AVR's, so for raw speed PICs lose period. This goes for the rates they're capable of on their I/O lines as well. Which is why you can bit bang USB on a wide range of AVR chips, but you can't do it on any PIC. AVR's have fewer devices compared to PICs (PICs do have USB capable versions) but the simplicity of choices and inherant flexibility of the AVR line beats PIC every way I look at it. If you REALLY need native USB you should be using a dedicated USB IC and the micro controller to push it data. The fact that you can add USB connectivity to many AVR's with software code alone speaks volumes to their ability to adapt to any use.

Keep in mind this is from the perspective of a hobbyist not a professional. If I were working in the embeded industry I would HAVE to learn PIC's they have better market penetration. It's almost like Linux vs Windows. Linux is more a powerful and flexible operating system, but everyone uses Windows. I don't like messing with my PC so I use Windows cause everyone else does. I DO like messing with micro controllers though so I picked AVR's =)
 
Last edited:
Thanks, Id like to ask more questions but I dont want to hijack the thread. Maybe we should start a thread on this.
 
HiTech C lite is a free compiler that should be bundled with the MPLAB installer. Yes it's a full featured PIC C compiler and should have ADC libraries.
 
Your processor/compiler might have "itoa" (integer to ascii) but the "least code" method I find useful with my processor/compiler is

sprintf(Ascii_RESULT, "%d", BYTE_TO_CONVERT);

Beware that this typically sticks a NULL character (0x00) in the follow on memory location. (2 bytes)
and "Ascii_RESULT" is an ADDRESS and not a variable.

Hi Shingadaddy,

my compiler CCS shows Ascii_RESULT as an error, how to do it?mind to show more help?

thanks.
 
i am trying to use this command

sprintf(outString,"A2D = %d.%d volts",voltage);
and get this error

Error [1098] ../../common/printf.c; 14. conflicting declarations for variable "_sprintf" (C:\Documents and Settings\Owner\Desktop\HI-TECH Software\PICC\PRO\9.60\samples\LCDemo\main.c:70)
can someone help me?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top