|
|
View previous topic :: View next topic |
Author |
Message |
Einly Guest
|
Communicating pic16f876 to sensor3 |
Posted: Mon Nov 18, 2002 8:06 am |
|
|
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
|
Re: Communicating pic16f876 to sensor3 |
Posted: Mon Nov 18, 2002 9:22 am |
|
|
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 |
Posted: Mon Nov 18, 2002 10:32 am |
|
|
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
|
Re: Communicating pic16f876 to sensor3 |
Posted: Mon Nov 18, 2002 6:35 pm |
|
|
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 |
|
|
|
|
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
|