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

High byte port manipulation in CCS for a dspic

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



Joined: 20 May 2015
Posts: 18

View user's profile Send private message

High byte port manipulation in CCS for a dspic
PostPosted: Wed May 20, 2015 7:03 am     Reply with quote

Hi all!

I'm all new to the CCS. Previously, I was on MikroC pro but because all of its bugs and errors that arise from nowhere, I decided to test another compiler. But CCS is is not a compiler as neat as Mikroc. Overall now I'm trying to deal with it.
The serious problem for me now, is that the function "output_x" just gives one byte of data but I/O ports are 16-bit and I couldn't find it out how can i change the high byte of the ports. I appreciate anyone who can help me on this.

Bests.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed May 20, 2015 7:14 am     Reply with quote

Output_x, outputs the whole _word_ on DSPIC's, not just a byte.

Remember though that you need to give it a word.

If you look at the manual:
Code:

Syntax:
 output_a (value)

output_b (value)

output_c (value)

output_d (value)

output_e (value)

output_f (value)

output_g (value)

output_h (value)

output_j (value)

output_k (value)

 
 
Parameters:
 value is a 16 bit int

 
 
Returns:
 undefined

 
 
Function:
 Output an entire word to a port. The direction register is changed in accordance with the last specified #USE *_IO directive.

 
 
Availability:
 All devices, however not all devices have all ports (A-E)

 
 
Requires:
 Nothing

 
 
Examples:
 OUTPUT_B(0xf0);


Cut and pasted from the current manual. Note the bit "value is a 16 bit int". The 'silly' thing is their example, outputs a byte, but:

OUTPUT_B(0xf0f0);

outputs a word.
AlPicCss73



Joined: 20 May 2015
Posts: 18

View user's profile Send private message

PostPosted: Wed May 20, 2015 7:47 am     Reply with quote

Thanks for your reply. Maybe I'm in a big mistake but in my CCS PCWHD 5.007 the output defining in the help comes as follow :
Quote:

output_x( )
Syntax:
output_a (value)

output_b (value)

output_c (value)

output_d (value)

output_e (value)

output_f (value)

output_g (value)

output_h (value)

output_j (value)

output_k (value)



Parameters:
value is a 8 bit int



Returns:
undefined



Function:
Output an entire byte to a port. The direction register is changed in accordance with the last specified #USE *_IO directive.



Availability:
All devices, however not all devices have all ports (A-E)



Requires:
Nothing



Examples:
OUTPUT_B(0xf0);



It's all 8 bit! and I defined the 16 bit variable and assigned it to the port but, nothing!. I've checked the ASM code and in that, the interpretation is wrong. Now, what I have to do??
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed May 20, 2015 8:05 am     Reply with quote

Get a later compiler....

5.007, was before V5, started working properly. It was still beta at that point.

However do be sure you are giving it a 16bit value. Be explicit, and use an int16 (don't assume the defaults are right on such an early version) Seriously, 'no wonder' you are having trouble.

However, that being said, just tested on 5.009, which was the oldest version I have kept, and:
Code:

00216:  MOV     #5555,W4
00218:  MOV     W4,802
.................... {
....................    int16 val=0x5555;
....................    output_b(val);
0021A:  CLR     2C6
0021C:  PUSH    802
0021E:  POP     2CA
....................    output_b(0xaaaa);
00220:  CLR     2C6
00222:  MOV     #AAAA,W4
00224:  MOV     W4,2CA


So the compiler is taking a 16bit value and doing a word output on the port, both from an int16 variable, and from an explicit int16 constant.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed May 20, 2015 8:15 am     Reply with quote

A quick comment. You are sure you are running PCD?.

If you have (for instance) PCWHD (the IDE plus all the compiler versions), and you 'wake up' in PCH, the PCH manual gets displayed. Even if you then switch to PCD, it'll keep on displaying the PCH manual, though you are now using PCD. You have to select the larger chip, save, exit the compiler, and load it again, and then the correct manual gets selected.

I suspect you are looking at the PCM/PCH manual, where the size for I/O is 8bit. Reason is that even the 4.112 PCD manual refers to 16bit for the I/O....

The PDF manual does not though.
AlPicCss73



Joined: 20 May 2015
Posts: 18

View user's profile Send private message

PostPosted: Thu May 21, 2015 3:15 am     Reply with quote

Yes! You were right. It was because of PCM instead of PCD, Thanks alot.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Thu May 21, 2015 3:40 am     Reply with quote

and (of course), using the wrong manual version, won't have helped you get going with CCS!....

The way that manual switching "doesn't occur", is a 'pet peeve' about the IDE. It is really annoying if you are working on several chips one after the other, to suddenly find you have the wrong manual for the chip you are using.... :(
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Thu May 21, 2015 6:38 am     Reply with quote

Moreover, at least with PCD, the online manual and the IDE manual do not always match (not typically conflicting info, but more so that one has functions/descriptions not found in the other).


Another tip is there are items in the IDE manual that are somewhat hidden (at least as of 5.044...haven't checked more recent). For example, #use pwm is an available directive but typing it in the index filter doesn't bring it up while doing a search for it does cause it to show up. There are other things like that that are found in search but not in the index, but that is the first one off the top of my head.

One of CCS's main weaknesses for me is the inconsistency in documentation (even the lack of detailed revision notes), but I will say I find the way it handles built in functions to be rather invaluable. My work likes to swap chips a lot, so cutting back development type on rewriting code for a new chip has been invaluable. Additionally, we have multiple coworkers who really aren't programmers (but are learning) who can dive right into some small projects because setup_timer1() is much easier to handle than trying to do all the corresponding bit/byte settings by hand.
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