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 support@ccsinfo.com

amature need help from pros!

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







amature need help from pros!
PostPosted: Mon Jan 20, 2003 2:46 pm     Reply with quote

<font face="Courier New" size=-1>hi,
i neeed some help, i am writting some code to control a PIC processor using commands sent i2c, i have no problem getting the commands, my problem is... for example, a tris all io command looks like this:

PRE

case TRIS_ALLIO:
int16Temp=_i2c_readBuffer[2]; int16Temp<<=8; int16Temp|=_i2c_readBuffer[3];

for(i=0; i < NUMBEROF_IO; i++)
{
j=int16Temp&0x01;
switch(i){
case IO_0: IO0=0; _TRISC_BIT0=j; break;
case IO_1: IO1=0; _TRISC_BIT1=j; break;
case IO_2: IO2=0; _TRISC_BIT2=j; break;
case IO_3: IO3=0; _TRISC_BIT3=j; break;
case IO_4: IO4=0; _TRISC_BIT6=j; break;
case IO_5: IO5=0; _TRISC_BIT7=j; break;
case IO_6: IO6=0; _TRISB_BIT0=j; break;
case IO_7: IO7=0; _TRISB_BIT1=j; break;
case IO_8: IO8=0; _TRISB_BIT2=j; break;
case IO_9: IO9=0; _TRISB_BIT4=j; break;
case IO_A: IOA=0; _TRISB_BIT5=j; break;
case IO_B: IOB=0; _TRISA_BIT0=j; break;
case IO_C: IOC=0; _TRISA_BIT1=j; break;
case IO_D: IOD=0; _TRISA_BIT2=j; break;
case IO_E: IOE=0; _TRISA_BIT3=j; break;
case IO_F: IOF=0; _TRISA_BIT5=j; break;
default: break;
}

int16Temp>>=1;
}
break;

/PRE

*****IO_X are enums, IOX are #bit, _TRISX_X are #bit

i say that is pretty UGLY! and i have 7 other commands that look like this, to much CUT N PASTE, please help!</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10830
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: amature need help from pros!
PostPosted: Mon Jan 20, 2003 3:03 pm     Reply with quote

:=i neeed some help, i am writting some code to control a PIC processor using commands sent i2c, i have no problem getting the commands, my problem is...
-----------------------------------------------------------

It looks like you're trying to set the TRIS registers
for two ports on the PIC. You have the tris bits
in an array. Why not use the CCS functions to write
the entire TRIS register at once ? See the code below.


char i2c_readBuffer[4];

//===============================================
void main()
{

set_tris_b(i2c_readBuffer[2]);
set_tris_c(i2c_readBuffer[3]);

while(1);
}

For most of the common things that you would like to do,
CCS will have a function for it. Browse the manual and
you will usually find what you need.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10832
jetlang
Guest







Re: amature need help from pros!
PostPosted: Mon Jan 20, 2003 3:25 pm     Reply with quote

<font face="Courier New" size=-1>:=-----------------------------------------------------------
:=
:=It looks like you're trying to set the TRIS registers
:=for two ports on the PIC. You have the tris bits
:=in an array. Why not use the CCS functions to write
:=the entire TRIS register at once ? See the code below.
:=
:=
:=char i2c_readBuffer[4];
:=
:=//===============================================
:=void main()
:={
:=
:=set_tris_b(i2c_readBuffer[2]);
:=set_tris_c(i2c_readBuffer[3]);
:=
:=while(1);
:=}
:=
:=For most of the common things that you would like to do,
:=CCS will have a function for it. Browse the manual and
:=you will usually find what you need.

i am actually trying to set 3 tris port a,b,c but only particular bits on that port only, so those included functions i cant really use cause they'll overwrite other bits that are setup and used by other perherial on the device.

can i somehow acces all these 16bit as one varible?

-also the post is not showing up correctly :(
-its showing this:
for(i=0; ij=int16Temp&0x01;

instead of this:
for(i=0; i<NUMBEROF_IO; i++){ j=int16Temp&0x01;

WTH! it still wont show up correctly, wierd! ___________________________
This message was ported from CCS's old forum
Original Post ID: 10834
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: amature need help from pros!
PostPosted: Mon Jan 20, 2003 3:41 pm     Reply with quote

<font face="Courier New" size=-1>:=WTH! it still wont show up correctly, wierd!
------------------------------------------------

I have an answer for the formatting problem:

Surround your code with the html tags "PRE" and "/PRE".
(Use angle-brackets instead of the quotes).

Also, using "PRE" tends to remove blank lines. So you can
use "BR" (with angle-brackets) in-between lines of code
to restore the blank lines.

Depending on your screen resolution, and if you're using
"Large Fonts", the code may be displayed in a smaller font
than the rest of the page.



--</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10835
Tomi
Guest







Re: amature need help from pros!
PostPosted: Tue Jan 21, 2003 10:00 am     Reply with quote

It looks like you use a 16F87X or same PIC. In this case you can access the tris registers as others.
For example, to set pin_b2 to input:
bit_set(*0x86,2);
To set it to output:
bit_clear(*0x86,2);
To set the lower 4 bits to input:
*0x86 |= 0x0F;
To set the pins 0,2,4,6 to output:
*0x86 &= 0xAA;
Etc.....
___________________________
This message was ported from CCS's old forum
Original Post ID: 10853
jetlang
Guest







Re: amature need help from pros!
PostPosted: Tue Jan 21, 2003 10:01 am     Reply with quote

i still cant fix it but i do have another question, same subject.

i have:
#bit IO0=_PORTC.0
#bit IO1=_PORTC.1
#bit IO2=_PORTC.2
#bit IO3=_PORTC.5
#bit IO4=_PORTC.6
#bit IO5=_PORTC.7
#bit IO6=_PORTB.0
#bit IO7=_PORTB.1
#bit IO8=_PORTB.2
#bit IO9=_PORTB.4
#bit IOA=_PORTB.5
#bit IOB=_PORTA.0
#bit IOC=_PORTA.1
#bit IOD=_PORTA.2
#bit IOE=_PORTA.3
#bit IOF=_PORTA.5

is there anywy i can access those IOx as 1 int16? or put them an an array? thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 10854
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