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

Why are some registers not defined in the devices.h?

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



Joined: 04 Oct 2004
Posts: 12
Location: Glasgow, Scotland

View user's profile Send private message

Why are some registers not defined in the devices.h?
PostPosted: Mon Oct 11, 2004 9:49 am     Reply with quote

e.g. OPTION_REG isn't in 16f877.h

Is there some reason why I shouldn't set bits in this register directly i.e. does the generated code keep a private copy of the #undefined registers that I would have to keep updated? I need to know this because I'm converting some Microchip-supplied code from Hitech C, and it obviously does allow direct manipulation of the bits in the regs.
Ttelmah
Guest







Re: Why are some registers not defined in the devices.h?
PostPosted: Mon Oct 11, 2004 10:30 am     Reply with quote

Ken Macfarlane wrote:
e.g. OPTION_REG isn't in 16f877.h

Is there some reason why I shouldn't set bits in this register directly i.e. does the generated code keep a private copy of the #undefined registers that I would have to keep updated? I need to know this because I'm converting some Microchip-supplied code from Hitech C, and it obviously does allow direct manipulation of the bits in the regs.

You can directly manipulate any register if you want to. The #byte directive, allows you to declare a variable, that sits at any register address required. However the CCS compiler, is really organised on the assumption that you will let _it_ handle such things for you . The features available in the option_reg for instance, are controlled by the EXT_INT_EDGE function, the PORT_B_PULLUPS function, the SET_TIMER0 function, with the RTCC_DIV, and WDT_XX prescaler controls.
The CCS approach, makes it easier to port to another chip latter (in many cases, you can for instance shift 16F87x code, that makes no direct access to the registers, straight in to a 18F45x chip, with little more than a header change. As such it has more in common with 'PC' compilers, than with many of the embedded offerings. The 'downside', is that this conversely, leads to people forgetting the limitations of the hardware that they are working on.

Best Wishes
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Oct 11, 2004 5:17 pm     Reply with quote

This is the header file I sometimes use with PIC16F877, it has almost all the bit/byte definitions (I think I created it from the Microchip file a long time ago). But be careful when using it, as Ttelmah said this will make porting your code to PIC18 family a bit more involved.

Code:

//Bits.h

 #nolist

//----- Register Files------------------------------------------------------

#byte INDF                         =0x00
#byte TMR0                         =0x01
#byte PCL                          =0x02
#byte STATUS                       =0x03
#byte FSR                          =0x04
#byte PORTA                        =0x05
#byte PORTB                        =0x06
#byte PORTC                        =0x07
#byte PORTD                        =0x08
#byte PORTE                        =0x09
#byte PCLATH                       =0x0A
#byte INTCON                       =0x0B
#byte PIR1                         =0x0C
#byte PIR2                         =0x0D
#byte TMR1L                        =0x0E
#byte TMR1H                        =0x0F
#byte T1CON                        =0x10
#byte TMR2                         =0x11
#byte T2CON                        =0x12
#byte SSPBUF                       =0x13
#byte SSPCON                       =0x14
#byte CCPR1L                       =0x15
#byte CCPR1H                       =0x16
#byte CCP1CON                      =0x17
#byte RCSTA                        =0x18
#byte TXREG                        =0x19
#byte RCREG                        =0x1A
#byte CCPR2L                       =0x1B
#byte CCPR2H                       =0x1C
#byte CCP2CON                      =0x1D
#byte ADRESH                       =0x1E
#byte ADCON0                       =0x1F

#byte OPTION_REG                   =0x81
#byte TRISA                        =0x85
#byte TRISB                        =0x86
#byte TRISC                        =0x87
#byte PIE1                         =0x8C
#byte PIE2                         =0x8D
#byte PCON                         =0x8E
#byte SSPCON2                      =0x91
#byte PR2                          =0x92
#byte SSPADD                       =0x93
#byte SSPSTAT                      =0x94
#byte TXSTA                        =0x98
#byte SPBRG                        =0x99
#byte ADRESL                       =0x9E
#byte ADCON1                       =0x9F

#byte EEDATA                       =0x10C
#byte EEADR                        =0x10D
#byte EEDATH                       =0x10E
#byte EEADRH                       =0x10F

#byte EECON1                       =0x18C
#byte EECON2                       =0x18D





//----- STATUS Bits --------------------------------------------------------

#bit IRP      =                         3.7
#bit RP1      =                         3.6
#bit RP0      =                         3.5
#bit NOT_TO   =                         3.4
#bit NOT_PD   =                         3.3
#bit Z        =                         3.2
#bit DC       =                         3.1
#bit C        =                         3.0

//----- INTCON Bits --------------------------------------------------------

#bit GIE      =                         0xB.7
#bit PEIE     =                         0xB.6
#bit T0IE     =                         0xB.5
#bit INTE     =                         0xB.4
#bit RBIE     =                         0xB.3
#bit T0IF     =                         0xB.2
#bit INTF     =                         0xB.1
#bit RBIF     =                         0xB.0

//----- PIR1 Bits ----------------------------------------------------------

#bit ADIF     =                         0xC.6
#bit RCIF     =                         0xC.5
#bit TXIF     =                         0xC.4
#bit SSPIF    =                         0xC.3
#bit CCP1IF   =                         0xC.2
#bit TMR2IF   =                         0xC.1
#bit TMR1IF   =                         0xC.0

//----- PIR2 Bits ----------------------------------------------------------

#bit EEIF     =                         0xD.4
#bit BCLIF    =                         0xD.3
#bit CCP2IF   =                         0xD.0

//----- T1CON Bits ---------------------------------------------------------

#bit T1CKPS1  =                         0x10.5
#bit T1CKPS0  =                         0x10.4
#bit T1OSCEN  =                         0x10.3
#bit NOT_T1SYNC  =                      0x10.2
#bit T1INSYNC =                         0x10.2    // Backward compatibility only
#bit T1SYNC   =                         0x10.2
#bit TMR1CS   =                         0x10.1
#bit TMR1ON   =                         0x10.0

//----- T2CON Bits ---------------------------------------------------------

#bit TOUTPS3  =                         0x12.6
#bit TOUTPS2  =                         0x12.5
#bit TOUTPS1  =                         0x12.4
#bit TOUTPS0  =                         0x12.3
#bit TMR2ON   =                         0x12.2
#bit T2CKPS1  =                         0x12.1
#bit T2CKPS0  =                         0x12.0

//----- SSPCON Bits --------------------------------------------------------

#bit WCOL     =                         0x14.7
#bit SSPOV    =                         0x14.6
#bit SSPEN    =                         0x14.5
#bit CKP      =                         0x14.4
#bit SSPM3    =                         0x14.3
#bit SSPM2    =                         0x14.2
#bit SSPM1    =                         0x14.1
#bit SSPM0    =                         0x14.0

//----- CCP1CON Bits -------------------------------------------------------

#bit CCP1X    =                         0x17.5
#bit CCP1Y    =                         0x17.4
#bit CCP1M3   =                         0x17.3
#bit CCP1M2   =                         0x17.2
#bit CCP1M1   =                         0x17.1
#bit CCP1M0   =                         0x17.0

//----- RCSTA Bits ---------------------------------------------------------

#bit SPEN     =                         0x18.7
#bit RX9      =                         0x18.6
#bit RC9      =                         0x18.6    // Backward compatibility only
#bit NOT_RC8  =                         0x18.6    // Backward compatibility only
#bit RC8_9    =                         0x18.6    // Backward compatibility only
#bit SREN     =                         0x18.5
#bit CREN     =                         0x18.4
#bit ADDEN    =                         0x18.3
#bit FERR     =                         0x18.2
#bit OERR     =                         0x18.1
#bit RX9D     =                         0x18.0
#bit RCD8     =                         0x18.0    // Backward compatibility only

//----- CCP2CON Bits -------------------------------------------------------

#bit CCP2X    =                         0x1D.5
#bit CCP2Y    =                         0x1D.4
#bit CCP2M3   =                         0x1D.3
#bit CCP2M2   =                         0x1D.2
#bit CCP2M1   =                         0x1D.1
#bit CCP2M0   =                         0x1D.0

//----- ADCON0 Bits --------------------------------------------------------

#bit ADCS1    =                         0x1F.7
#bit ADCS0    =                         0x1F.6
#bit CHS2     =                         0x1F.5
#bit CHS1     =                         0x1F.4
#bit CHS0     =                         0x1F.3
#bit GO       =                         0x1F.2
#bit NOT_DONE =                         0x1F.2
#bit GO_DONE  =                         0x1F.2
#bit ADON     =                         0x1F.0

//----- OPTION_REG Bits ----------------------------------------------------

#bit NOT_RBPU =                         0x81.7
#bit INTEDG   =                         0x81.6
#bit T0CS     =                         0x81.5
#bit T0SE     =                         0x81.4
#bit PSA      =                         0x81.3
#bit PS2      =                         0x81.2
#bit PS1      =                         0x81.1
#bit PS0      =                         0x81.0

//----- PIE1 Bits ----------------------------------------------------------

#bit ADIE     =                         0x8C.6
#bit RCIE     =                         0x8C.5
#bit TXIE     =                         0x8C.4
#bit SSPIE    =                         0x8C.3
#bit CCP1IE   =                         0x8C.2
#bit TMR2IE   =                         0x8C.1
#bit TMR1IE   =                         0x8C.0

//----- PIE2 Bits ----------------------------------------------------------

#bit EEIE     =                         0x8D.4
#bit BCLIE    =                         0x8D.3
#bit CCP2IE   =                         0x8D.0

//----- PCON Bits ----------------------------------------------------------

#bit NOT_POR  =                         0x8E.1
#bit NOT_BO   =                         0x8E.0
#bit NOT_BOR  =                         0x8E.0

//----- SSPCON2 Bits --------------------------------------------------------

#bit GCEN     =                         0x91.7
#bit ACKSTAT  =                         0x91.6
#bit ACKDT    =                         0x91.5
#bit ACKEN    =                         0x91.4
#bit RCEN     =                         0x91.3
#bit PEN      =                         0x91.2
#bit RSEN     =                         0x91.1
#bit SEN      =                         0x91.0

//----- SSPSTAT Bits -------------------------------------------------------

#bit SMP      =                         0x94.7
#bit CKE      =                         0x94.6
#bit D        =                         0x94.5
#bit I2C_DATA =                         0x94.5
#bit NOT_A    =                         0x94.5
#bit NOT_ADDRESS  =                     0x94.5
#bit D_A      =                         0x94.5
#bit DATA_ADDRESS =                     0x94.5
#bit P        =                         0x94.4
#bit I2C_STOP =                         0x94.4
#bit S        =                         0x94.3
#bit I2C_START=                         0x94.3
#bit R        =                         0x94.2
#bit I2C_READ =                         0x94.2
#bit NOT_W    =                         0x94.2
#bit NOT_WRITE=                         0x94.2
#bit R_W      =                         0x94.2
#bit READ_WRITE   =                     0x94.2
#bit UA       =                         0x94.1
#bit BF       =                         0x94.0

//----- TXSTA Bits ---------------------------------------------------------

#bit CSRC     =                         0x98.7
#bit TX9      =                         0x98.6
#bit NOT_TX8  =                         0x98.6    // Backward compatibility only
#bit TX8_9    =                         0x98.6    // Backward compatibility only
#bit TXEN     =                         0x98.5
#bit SYNC     =                         0x98.4
#bit BRGH     =                         0x98.2
#bit TRMT     =                         0x98.1
#bit TX9D     =                         0x98.0
#bit TXD8     =                         0x98.0    // Backward compatibility only

//----- ADCON1 Bits --------------------------------------------------------

#bit ADFM     =                         0x9F.7
#bit PCFG3    =                         0x9F.3
#bit PCFG2    =                         0x9F.2
#bit PCFG1    =                         0x9F.1
#bit PCFG0    =                         0x9F.0

//----- EECON1 Bits --------------------------------------------------------

#bit EEPGD    =                         0x18C.7
#bit WRERR    =                         0x18C.3
#bit WREN     =                         0x18C.2
#bit WR       =                         0x18C.1
#bit RD       =                         0x18C.0

#list
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 13, 2004 8:22 am     Reply with quote

What is #nolist and #list for?
_________________
Alex
SherpaDoug



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

View user's profile Send private message

PostPosted: Wed Oct 13, 2004 9:11 am     Reply with quote

alexz wrote:
What is #nolist and #list for?


It controls what gets printed to the listing file. Usually you don't want the header files printed. It saves trees.
_________________
The search for better is endless. Instead simply find very good and get the job done.
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 13, 2004 9:13 am     Reply with quote

SherpaDoug wrote:
alexz wrote:
What is #nolist and #list for?


It controls what gets printed to the listing file. Usually you don't want the header files printed. It saves trees.


thank you
_________________
Alex
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