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

Communicating pic16f876 to sensor3

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







Communicating pic16f876 to sensor3
PostPosted: Mon Nov 18, 2002 8:06 am     Reply with quote

Dear sir,

I've written a program as below to communicate pic16f876 to the sensor with reference to ur advice:

#include <16f876.h>
#use delay (clock=20000000)
#fuses noprotect, nowdt, hs, nolvp

#byte PORTA =5
#byte PORTB =6
#byte PORTC =7

#define READ_SSP() (SSPBUF)
#define WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
#define WRITE_SSP(x) SSPBUF=(x)
#define CLEAR_WCOL() SSPCON = SSPCON & 0x3f

void main()
{
set_tris_b(0);
set_tris_c(0x20);

byte garbage[1];
byte byte_returned;

do
{
CLEAR_WCOL();
WRITE_SSP(0x02);
WAIT_FOR_SSP();
garbage=READ_SSP();

TRISSDO=1;
WRITE_SSP(garbage);
WAIT_FOR_SSP();
byte_returned=READ_SSP();
TRISSDO=0;
}while(1);
}

However, error messages appear when I try to compile it. I think that I have misunderstood what you have taught me. Can you please modify the program for me?

Thanks a lot for your help.

Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 9053
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Communicating pic16f876 to sensor3
PostPosted: Mon Nov 18, 2002 9:22 am     Reply with quote

You haven't defined the following
SSPBUF
SSPSTAT
SSPCON
TRISSDO

Regards,
Mark

:=Dear sir,
:=
:=I've written a program as below to communicate pic16f876 to the sensor with reference to ur advice:
:=
:=#include <16f876.h>
:=#use delay (clock=20000000)
:=#fuses noprotect, nowdt, hs, nolvp
:=
:=#byte PORTA =5
:=#byte PORTB =6
:=#byte PORTC =7
:=
:=#define READ_SSP() (SSPBUF)
:=#define WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
:=#define WRITE_SSP(x) SSPBUF=(x)
:=#define CLEAR_WCOL() SSPCON = SSPCON & 0x3f
:=
:=void main()
:={
:= set_tris_b(0);
:= set_tris_c(0x20);
:=
:= byte garbage[1];
:= byte byte_returned;
:=
:= do
:= {
:= CLEAR_WCOL();
:= WRITE_SSP(0x02);
:= WAIT_FOR_SSP();
:= garbage=READ_SSP();
:=
:= TRISSDO=1;
:= WRITE_SSP(garbage);
:= WAIT_FOR_SSP();
:= byte_returned=READ_SSP();
:= TRISSDO=0;
:= }while(1);
:=}
:=
:=However, error messages appear when I try to compile it. I think that I have misunderstood what you have taught me. Can you please modify the program for me?
:=
:=Thanks a lot for your help.
:=
:=Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 9055
Einly
Guest







Re: Communicating pic16f876 to sensor3
PostPosted: Mon Nov 18, 2002 10:32 am     Reply with quote

Dear sir,

Thanks for ur reply:)

I'm sorry to say that I've a very poor understanding in using the chip as well as the command.

May I know how should I define them? As I know, they refer to registers in the chip used for synchronous serial port communication.

For your information, the sensor that I refer to is an optical sensor manufactured by Agilent Technologies, i.e. ADNS2051.

Thanks.

Einly

:=You haven't defined the following
:=SSPBUF
:=SSPSTAT
:=SSPCON
:=TRISSDO
:=
:=Regards,
:=Mark
:=
:=:=Dear sir,
:=:=
:=:=I've written a program as below to communicate pic16f876 to the sensor with reference to ur advice:
:=:=
:=:=#include <16f876.h>
:=:=#use delay (clock=20000000)
:=:=#fuses noprotect, nowdt, hs, nolvp
:=:=
:=:=#byte PORTA =5
:=:=#byte PORTB =6
:=:=#byte PORTC =7
:=:=
:=:=#define READ_SSP() (SSPBUF)
:=:=#define WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
:=:=#define WRITE_SSP(x) SSPBUF=(x)
:=:=#define CLEAR_WCOL() SSPCON = SSPCON & 0x3f
:=:=
:=:=void main()
:=:={
:=:= set_tris_b(0);
:=:= set_tris_c(0x20);
:=:=
:=:= byte garbage[1];
:=:= byte byte_returned;
:=:=
:=:= do
:=:= {
:=:= CLEAR_WCOL();
:=:= WRITE_SSP(0x02);
:=:= WAIT_FOR_SSP();
:=:= garbage=READ_SSP();
:=:=
:=:= TRISSDO=1;
:=:= WRITE_SSP(garbage);
:=:= WAIT_FOR_SSP();
:=:= byte_returned=READ_SSP();
:=:= TRISSDO=0;
:=:= }while(1);
:=:=}
:=:=
:=:=However, error messages appear when I try to compile it. I think that I have misunderstood what you have taught me. Can you please modify the program for me?
:=:=
:=:=Thanks a lot for your help.
:=:=
:=:=Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 9063
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Communicating pic16f876 to sensor3
PostPosted: Mon Nov 18, 2002 6:35 pm     Reply with quote

Not sure what TRISSDO is. The other are registers in the PIC. Look up there addresses in the datasheet and use the #byte command as you did for PORTA.

:=Dear sir,
:=
:=Thanks for ur reply<img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0">
:=
:=I'm sorry to say that I've a very poor understanding in using the chip as well as the command.
:=
:=May I know how should I define them? As I know, they refer to registers in the chip used for synchronous serial port communication.
:=
:=For your information, the sensor that I refer to is an optical sensor manufactured by Agilent Technologies, i.e. ADNS2051.
:=
:=Thanks.
:=
:=Einly
:=
:=:=You haven't defined the following
:=:=SSPBUF
:=:=SSPSTAT
:=:=SSPCON
:=:=TRISSDO
:=:=
:=:=Regards,
:=:=Mark
:=:=
:=:=:=Dear sir,
:=:=:=
:=:=:=I've written a program as below to communicate pic16f876 to the sensor with reference to ur advice:
:=:=:=
:=:=:=#include <16f876.h>
:=:=:=#use delay (clock=20000000)
:=:=:=#fuses noprotect, nowdt, hs, nolvp
:=:=:=
:=:=:=#byte PORTA =5
:=:=:=#byte PORTB =6
:=:=:=#byte PORTC =7
:=:=:=
:=:=:=#define READ_SSP() (SSPBUF)
:=:=:=#define WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
:=:=:=#define WRITE_SSP(x) SSPBUF=(x)
:=:=:=#define CLEAR_WCOL() SSPCON = SSPCON & 0x3f
:=:=:=
:=:=:=void main()
:=:=:={
:=:=:= set_tris_b(0);
:=:=:= set_tris_c(0x20);
:=:=:=
:=:=:= byte garbage[1];
:=:=:= byte byte_returned;
:=:=:=
:=:=:= do
:=:=:= {
:=:=:= CLEAR_WCOL();
:=:=:= WRITE_SSP(0x02);
:=:=:= WAIT_FOR_SSP();
:=:=:= garbage=READ_SSP();
:=:=:=
:=:=:= TRISSDO=1;
:=:=:= WRITE_SSP(garbage);
:=:=:= WAIT_FOR_SSP();
:=:=:= byte_returned=READ_SSP();
:=:=:= TRISSDO=0;
:=:=:= }while(1);
:=:=:=}
:=:=:=
:=:=:=However, error messages appear when I try to compile it. I think that I have misunderstood what you have taught me. Can you please modify the program for me?
:=:=:=
:=:=:=Thanks a lot for your help.
:=:=:=
:=:=:=Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 9077
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