#Ccs c compiler code
Although you can keep different copies of your code or comment and un-comment out parts of your code, this can be very inconvenient. Sometimes, you want to have different versions of your code. Later in the code, when we want to set the values, we can set it like any other variable: Look up the correct memory address in the datasheet (the 0x denotes hexadecimal notation): This prevents the data from changing or rolling over in the time between reading or writing the first and second registers.įor the CCS compiler, you can use the #byte preprocessor directive to tell it to place a variable at a specific memory address. The high byte is actually a buffer writing to the low byte will automatically load the high byte into the register, and reading from the low byte will automatically copy the current value into the high byte register, in a single operation. When reading from the 16-bit register, read the low byte first and the high byte second. Note: When writing to 16-bit SFRs with a high and low byte which may be changing (such as a timer register), it is important to write to the high byte first and write to the low byte second. However, we can look in the datasheet in the "Special Function Registers" section to find memory address of the SFR we want. h files, so we'll have to define them ourselves.Īs an example, the CCS library doesn't have a function that will write to PR5 (Timer5 period match register) for devices (such as the PIC18F4431) that have them. Unfortunately, the SFR names used in the datasheet are not defined in CCS's device. However, some functionality may be "lost in translation," or the documentation may be so vague that it's easier just to the write the correct bits directly to the SFRs. The CCS library attempts to make things easier by wrapping up the SFRs into function calls such as setup_adc, etc. When configuring the peripherals of the PIC, one usually checks the PIC's datasheet and manually writes the bits corresponding to the desired settings to the special function registers (SFRs). This will often cause problems when people try to read or reuse your code. For example, the keyword int may mean an 8-bit unsigned integer in one compiler and a 16-bit signed integer in another compiler. Implementation of datatypes like char, int, long, short, etc.