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

Accessing Big Endian registers

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



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Accessing Big Endian registers
PostPosted: Sat Aug 17, 2013 2:25 pm     Reply with quote

I just found out that some of the 16-bit registers in the PIC18F2331/2431/4331/4431 are Big Endian, specifically the power control PWM registers, PTPER and PDC0...PDC3. I have no idea why Microchip chose to violate their standard of Little Endian 16-bit registers, but now that they did, it seems I cannot use the 16-bit syntax in CCS C where the register is declared with a #word directive. Now I have to use the make8() macro to access one byte at a time. Am I missing something here?
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 5:00 pm     Reply with quote

Sadly 'standards' are made to be broken ,errr, 'updated'.

Rememeber 'legacy' devices like REAL comports, 25 pin printer ports....
'We'll NEVER lose them !!'

Sigh, it's just a sign of the dynamic times we're in.

I've yet to figure out why PIC ports don't defallt to digital I/O instead of any of the peripherals that are 'muxed' to them.

Just another of life's challeneges..after all wouldn't want to get 'set in your ways' would you ???

smile..it' gets worse the older you get ...
If tubes weren't so pricey, I'd go back to them.

Jay
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 6:53 pm     Reply with quote

temtronic wrote:

I've yet to figure out why PIC ports don't defallt to digital I/O instead of any of the peripherals that are 'muxed' to them.

Imagine a circuit that puts a mid-level voltage (2.5v) on a pin as soon as the PIC is powered up, because it is going to be configured as analog. If the PIC powered up assuming a digital input for this pin before it was configured as analog, the intermediate voltage could cause the PIC to draw a lot more current than it would if it were an analog pin. If the power supply is severely current limited it could even cause the device to drop below the brownout threshold and never come out of reset.
Quote:

smile..it' gets worse the older you get ...

I'm 65 now. You mean it gets even worse?
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 7:15 pm     Reply with quote

How about a little macro like this, to swap the bytes ?
Code:

#include<18F4431.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#word PTPER = getenv("SFR:PTPERH")

#define swap_bytes(value) make16(value, value >> 8)

//=======================================

void main()
{

PTPER = swap_bytes(0x1234);

while(1);
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 8:18 pm     Reply with quote

I like your swap_bytes macro. It generates exactly the same code as my explicit byte moves - very efficient!
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 1:58 am     Reply with quote

As a comment, CCS already provide functions to directly access these registers, with the bytes correctly ordered. set_power_pwmX_duty for example, sets the PDC registers directly:
Code:

....................    set_power_pwm2_duty(0x1234);
0024:  BSF    F6E.1
0026:  MOVLW  34
0028:  MOVWF  F77
002A:  MOVLW  12
002C:  MOVWF  F76
002E:  BCF    F6E.1


The only thing you have to 'remember' is that CCS use the logical output numbers, not the register numbers.

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 8:24 am     Reply with quote

Ttelmah wrote:
As a comment, CCS already provide functions to directly access these registers, with the bytes correctly ordered. set_power_pwmX_duty for example, sets the PDC registers directly:
Code:

....................    set_power_pwm2_duty(0x1234);
0024:  BSF    F6E.1
0026:  MOVLW  34
0028:  MOVWF  F77
002A:  MOVLW  12
002C:  MOVWF  F76
002E:  BCF    F6E.1


The only thing you have to 'remember' is that CCS use the logical output numbers, not the register numbers.

Best Wishes

I am really glad you posted that - not so much for the use of set_power_pwm2_duty as for the use of PWMCON1 bit 1. I hadn't realized the use of this bit in setting Duty Cycle. I did worry about the possibility that the working PDCx value would get updated inbetween my setting of the upper and lower bytes of PDCx, and thus use a totally wrong value of PDCx for one period. But after looking at the disassembly you posted I realized that this is exactly that PWMCON1 bit 1 was for.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 8:28 am     Reply with quote

Yes, that is one of those 'once you see it, makes perfect sense' things. Smile

Best Wishes
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