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

Setting 2 pins high or low simultaneously

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



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

Setting 2 pins high or low simultaneously
PostPosted: Tue Dec 15, 2009 2:39 pm     Reply with quote

Hi forum,

I'm using the PIC10F222 and would like to set 2 pins high in the same instruction and also set the same 2 pins low in the same instruction.

I guess I need to read the GPIO register and then use the bitwise AND and OR operators and then write the modified values back to the GPIO register.
The problem is that I have completely forgotten how to use bitwise operators.

I got this code:

Code:

GPIO |= 0b00000110; // Set pins GP1 and GP2 high

GPIO &= 0b11111001; // Set pins GP1 and GP2 low


But I'm not sure this is correct. As the comments suggest, I'm trying to set GP1 and GP2 high at the same time (in the same instruction) and also set them low in the same instruction.

Please advise.

Thanks.
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Tue Dec 15, 2009 4:24 pm     Reply with quote

Hi,

I found the possibility to test the above code, and it seems to work, but still, I'm not sure the outputs change simultaneously, I don't have the equipment to check.

Anyone?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 11:15 am     Reply with quote

Yes, that should work. But the easy way to find out without a scope is to look at the assembly code in the .lst file.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:20 pm     Reply with quote

SherpaDoug wrote:
But the easy way to find out without a scope is to look at the assembly code in the .lst file.

I haven't learned the assembly language, so that's not "easy" for me, but I did it anyway, and it seemed to only use 2 instructions:

Code:
....................             GPIO |= 0b00000110;  // Set pins GP1 and GP2 high
0107:  MOVLW  06
0108:  IORWF  06,F
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:36 pm     Reply with quote

if you output a byte to a port

all pins in that port will set simultaneously...ethier low or high or combinations.

set port B = 0xFF , all pins go high,

set port B = 0x00 , all pins go low...

set port B = 0x0F , higher half goes low, lower half goes high

and so on...

(this is not actual code... im sure you get what i mean)

hope i helped...if you still needed help at this point...(alot of smart people around here)

gabriel
_________________
CCS PCM 5.078 & CCS PCH 5.093
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:37 pm     Reply with quote

With logical OR or AND you are "masking" the port so if you turn it all on or all off it will be simultaneously for whole port. Or in your case for two I/O pins.

Those two instructions in your case d the following thing. First one loads 06 (or 0b00000110) to the W register and the second one executes logical OR on register at location 06 (that is GPIO) and result is saved to the register it self.

Hope the explanation helps.
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:38 pm     Reply with quote

Thanks for your replies, but I got it working OK now Cool

bungee, I thought it worked that way, you confirmed it for me, thanks.
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