CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pic to pc communication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Einly
Guest







pic to pc communication
PostPosted: Sat May 24, 2003 4:39 am     Reply with quote

Dear all,

I am trying to do commmunication between PIC 16f876 and the PC. I have successfully sent characters and string from the PIC and sent characters to PIC. However, I am not sure how to send string from PC to PIC.

This is the program that I used to send and receive characters

#include <16F876.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,parity=N)
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7

main()
{
int i;
char answer;

set_tris_b(0); //set pin b0-b7 as output
delay_ms(1000);

printf("Press any key to begin\n\r");
getc();

printf("Continue (Y/N)?\n\r");

do
{
answer=getc();
}while(answer!='Y'&&answer!='N');

printf("End\n\r");

}


Can anybody help me? How to use gets?

Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514719
John Taylor
Guest







Re: pic to pc communication
PostPosted: Sat May 24, 2003 10:46 am     Reply with quote

<a href="http://www.tayloredge.com/utilities/scmd.c" TARGET="_blank">http://www.tayloredge.com/utilities/scmd.c</a>
<a href="http://www.tayloredge.com/utilities/scmd.h" TARGET="_blank">http://www.tayloredge.com/utilities/scmd.h</a>
<a href="http://www.tayloredge.com/utilities/convert.h" TARGET="_blank">http://www.tayloredge.com/utilities/convert.h</a>

This code reads characters at the #RDA interrupt level and converts the incomming ASCCI data to a binary array. When a complete frame is received, a flag is set that is read by the main level code as "command ready". Main level code then acts on and (If required) responds.

Example main code is included in the commented section at the beginning of scmd.c which allows start to finish implementation in minutes.

The command structure is as follows:

Command-
$aaccdd...dd[cr]

Response-
!aaccdd...dd[cr]

$/! Frame start for command/response
aa Unit address for bussed system, defaults to 0x00
cc Command code
dd 0 to 16 btyes of ASCII Hex data
[cr] Frame terminator

Read scmd.c, it's pretty detailed.

I don't charge for this, (I must be retarded!) Any questions may be submitted to the contact page. If there is any interest, I can work up a VB6 example driver. Enjoy

John Taylor
Taylor Electronics Services
<a href="http://www.tayloredge.com/contact/index.html" TARGET="_blank">http://www.tayloredge.com/contact/index.html</a>


:=Dear all,
:=
:=I am trying to do commmunication between PIC 16f876 and the PC. I have successfully sent characters and string from the PIC and sent characters to PIC. However, I am not sure how to send string from PC to PIC.
:=
:=This is the program that I used to send and receive characters
:=
:=#include <16F876.h>
:=#use delay(clock=20000000)
:=#fuses hs,noprotect,nowdt,nolvp
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,parity=N)
:=#byte PORTA=5
:=#byte PORTB=6
:=#byte PORTC=7
:=
:=main()
:={
:= int i;
:= char answer;
:=
:= set_tris_b(0); //set pin b0-b7 as output
:= delay_ms(1000);
:=
:= printf("Press any key to begin\n\r");
:= getc();
:=
:= printf("Continue (Y/N)?\n\r");
:=
:= do
:= {
:= answer=getc();
:= }while(answer!='Y'&&answer!='N');
:=
:= printf("End\n\r");
:=
:=}
:=
:=
:=Can anybody help me? How to use gets?
:=
:=Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514723
Steve H.
Guest







Re: pic to pc communication
PostPosted: Sat May 24, 2003 11:20 am     Reply with quote

You can see what I do for a data acq system at my homepage,

Steve H.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514726
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group