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

Glitchless re-write of TRISD/PORTD/LATD ?

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







Glitchless re-write of TRISD/PORTD/LATD ?
PostPosted: Tue Jul 05, 2005 9:38 am     Reply with quote

I want to change TRISD from/to:

'0000 0011' -- initial trisd // 0x03
'1010 0011' -- desired new trisd // 0xA3

I want to preserve the lower nibble RD3:RD0 and leave its current pin states alone, while rewriting RD7:RD4.


1st method: using PORTD directly.

Code:

temp_portd = PORT_D;
[manipulate temp_portd with some logical | and & masks]
PORT_D = temp_portd;
set_tris_d(0xA3);



2nd method: using LATD:
Code:

temp_latd = LATD;
[manipulate temp_latd with some logical | and & masks]
LATD = temp_latd;
set_tris_d(0xA3);


What is the proper way to change it and get glitch-free operation? I've been using method #2 for several months, but i'm now suspicious since i think i'm getting glitches.
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 10:26 am     Reply with quote

I've played with the TRIS registers directly, in the same manner that you are suggesting, with no glitches.

I recently taught a PIC course where we read a DS18S20 one wire temperature sensor. This was connected to port C. If you're not familiar with the 1 wire protocol, it's pretty fussy. Lots of changes in pin direction, and the timing is very critical for success.

Anyway, once we could read the temperature of the sensor, we expanded on what we did, and got the PIC to send the temperature to a host PC using the USART on pins C6 and C7. No glitches at all.

What I did was:

Code:
#byte TRISC = 0xf94

// if I need to change C2 from an output to an input, I'd:
TRISC = TRISC | 0x04;

// if I need to change C2 into an output, I'd:
TRISC = TRISC & 0xfb;


This was all happening concurrently with the USART spitting out and receiving data. No glitches. Hope this helps.
valemike
Guest







PostPosted: Tue Jul 05, 2005 11:01 am     Reply with quote

Thanks. Actually what i was asking was not whether i can play with TRISD directly, but rather, how would I pre-load the pins so that when i flipped the TRISD bits to outputs, the pins would immediately assume the logical outputs states that i want.

I'm thinking more and more now that my glitches are coming from the ECCP though. I seem to be getting a brief unwanted pulse. oh well.
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 11:21 pm     Reply with quote

Oh! Just write whatever you want to the latch. When you flip the TRIS to be output, the pins will be whatever you wrote into the latch.

Sorry! I didn't realize what you were asking the first time.
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