Shouldn't this be valid in Hitec C?

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
Chasing more bugs in hitec c!
Please, someone confirm whether this is 'correct' or not, it is sending me mad!

I was hoping to use RD6, as a pin for sending an ultrasound signal down.
However, it appears that changing RD7 is changing RD6....
I have two chips set up with the same circuit, and the same is happening on both.
When One_Wire_RS() is called, both RD6 and RD7 are changed. I couldn't work out going through the code why RD6 was changing, so I am changing RD5 manually, and watching RD5, RD6 and RD7,
I am watching what is happening with a logic analyser.
When One_Wire_RS() is called, RD6 is set low, as well as RD7 (and also RD5, I was using this to trace exactly which call it was which did it).
(doing a find in files for D6 shows only the ultrasound calls, TRIS is set only for the whole port at the beginning of the program. The LCD routines were portD, but I have moved them for debugging purposes to the end of the while loop, and are wrapped in USTX=1)
WHY is RD6 changing?


Rich (BB code):
 #define TPIN TRISD7
 #define DPIN RD7
 bit prescence = 0; 
 
 void One_Wire_High(){
 DPIN=1;
 TPIN=1;
 }
 
 void One_Wire_Low(){
 TPIN=0;
 DPIN=0;
 }
 bit Get_One_Wire_Bit(){
 TPIN=0;
 char a=DPIN;
 TPIN=1;
 return a;
 }

 
 bit One_Wire_RS(void){   
 One_Wire_High(); 
 __delay_us(TG);             
   prescence = 0;                     
 One_Wire_Low();
   __delay_us(TH);              
 One_Wire_High();
 __delay_us(TI);           
 if (Get_One_Wire_Bit() == 0 ){
 prescence=1;
 };

#define USTX RD6
#define USTXTRIS TRISD6

void main(void){
//initialise everything
USTXTRIS=0;
USTX=1;
TPIN=0; //output for 1wire
DPIN=1; // 1wire should be constantly high unless data is being sent
while(1){
sleep();  //Is woken up by SQWE output on pin RB0
//other routines run, RD6 is still high
 
TRISD5=0;   
RD5=1;  //watching LA, RD6 is still high, RD5 goes high
 if(1 == One_Wire_RS()){   //I know something is there in this case anyway
TOK=1;
RD5=0;
USTXTRIS=0;
USTX=1;
 
}
}
}
 

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
It is the 16f877a, portD is listed as RD<N> / PSP<N>
Missing from the code that I posted, is that I am setting TRISE and TRISD to 0x00000000;
TRISE<4> is specified as being the enable bit for the Parallel port on port D, this is 0 on all resets, and obviously being set to 0 with the TRISE above as well.

All analog pins are on port A and E (and I am not implementing any at the moment, I will want to use one later)
I am setting ADCON1 to be 0x00000000
The only 'special' item that I am using as far as I am concerned, is INTCON
I am setting
INTCON = 0b00010000;
sleep();
INTCON = 0b00000000;

during part of the code. This sets up RB0 to be able to wake the PIC from sleep (SQWE input from a DS1307, wakes the PIC once per second). After the wake, the PIC performs an I2C read from the DS1307, which is OK, then, it runs the code I posted, which produces the fault. (timewise I can see that the LA shows the I2C completing, then I set RD5 high as my marker, then perform the 1-wire read on RD7, which initiates the erroneous low on RD6)
 
Last edited:
Top