Mplab C Compiler For Dspic Dscs Serial Number ##HOT##
Serializing devices in a production environment is simple and easy using the CCS C Compiler and the Prime8 Production Programmer. The CCS C Compiler allows for setting up serialization using the #serialize preprocessor directive. A serial number can be saved in binary or as a string, and can be stored in ROM or EEPROM if available.This example shows a simple way to store a 32-bit binary serial number (4 bytes) in either EEPROM or ROM. The target device has 256 bytes of EEPROM and 32Kbytes of flash program memory, where the serial number is stored in the last 4 bytes of either depending on the defined location. The #ORG in the ROM variant is to reserve the program memory containing the serial number from being used elsewhere by the compiler.Reading a binary serial number from memory is as simple as reading the raw data directly into a variable using a byte-pointer to that variable. In the example, a pointer is created to a 32-bit variable, which is used to index the raw data bytes. The result is the 32-bit number set by the programmer.The serialization settings, or "burntime" settings, are saved in the hex file on compilation and are loaded into the Prime8's internal memory when writing the hex file to it. The initial serial number can then be set or changed on the job configuration screen.Serial numbers are automatically incremented after each successful write, so each connected target will have a different serial number written to it.To change the current serial number on the Prime8, select the Config button for the current job. On the Config screen, the file can be selected by touching the "Name/Location" setting, choosing "Internal Memory", and selecting the memory slot the file was written to. This will then show the file name and location on the Config screen. Touch the down arrow until the "Serial Number" setting is visible. Touch this setting to open a keypad where a new serial number can be entered. Once the number is entered, Press the Enter button to save the setting. Now when the program is written to the targets, the serial number that was entered will be the first serial number written (in this case, 65536), and each successive target will have an incremented serial number (65537, 65538, ...). The number can always be changed or reset by changing the setting again under the job configuration screen.Prime8 Production Programmer, visit: _info.php?products_id=P8_gangCCS C Compilers, visit: =compilersLike us on Facebook. Follow us on Twitter.About CCS: CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC MCU and dsPIC DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit PIC MCU, MPLAB IDE, MPLAB ICD2, MPLAB ICD3 and dsPIC are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.
Mplab C Compiler For Dspic Dscs Serial Number
SQTP (Serial Quick Turn Programming) is used to program a unique serial number into each device. This number can be used as an entry code, password, or ID number. To view and change the settings of SQTP, you first need to login to the Advanced Mode. After logging in successfully to the Advanced Mode, from the dialog, click on SQTP on the left to display the available settings. See figure below:
Add Flow Control and Buffering to Serial RoutinesA feature of the compiler is the powerful #use rs232() library that has added transmit buffering, receive buffering, and flow control. While the API for the serial library remains unchanged ( getc(), putc(), printf() ), existing code using this API allows for buffering and flow control by simply modifying the #use rs232() parameters. A user may specify:* size of transmit buffer* size of receive buffer* interrupt usage or no interrupt usage* pin for CTS and pin for RTSClick through to: to review a usage example of the #use rs232() and additional details on each new usage. Additional configurations and control options are also available.Notifications From the Serial Library on Data ReceptionThe compiler provides an extremely flexibly serial library; it has the ability to use the hardware peripheral or bit bang the pins, to control and monitor flow control, to specify parity, to use a one wire bus, and more. One feature it has is the ability to specify a receive buffer, and the library will automatically use the receive interrupt to buffer incoming characters. Here is an example of creating a stream called STREAM_UART1 on the UART1 hardware peripheral with a 16 byte receive buffer:#use rs232(UART1, baud=9600, receive_buffer=16, stream=STREAM_UART1)Essentially the stream works like a file handle that can be used with C standard I/O functions like fputc, fgetc, etc. Using the stream created above, here is a simple loop that echoes data received on the UART back to the UART:while (kbhit(STREAM_UART1))fputc(fgetc(STREAM_UART1), STREAM_UART1);This example shows the flexibility of the #use rs232() library provided by CCS. The 'receive_buffer' option creates an interrupt on the UART receive to buffer incoming characters and kbhit() and fgetc() accesses that buffer, but if the 'receive_buffer' was removed from the #use rs232(), then kbhit() and fgetc() would instead check for any received data being held by the UART.The 'receive_buffer' example as shown above has no way of notifying the users software that data is available, except by polling the receive buffer status with kbhit(). The 5.095 version of the CCS C Compiler adds a new option called 'callback' that allows the user to specify a function to be called when the receive buffer goes from empty to not empty. This could be used to mark a semaphore or enable a routine to start parsing data in the receive buffer. Here is an example of adding this new option:#use rs232(UART1, baud=9600, receive_buffer=16, stream=STREAM_UART1, \callback=Uart1OnRx)As stated earlier, this example will call the 'Uart1OnRx' function whenever the receive buffer goes from empty to not empty. Here is how the earlier echo example can be changed to use an RTOS with a semaphore to mark when the receive buffer is ready:#use rtos(timer=0)int uart_sem = 0;static void Uart1OnRx(void) rtos_signal(uart_sem);#task(rate=10ms)static void Uart1Task(void) for(;;) rtos_wait(uart_sem);while(kbhit(STREAM_UART1)) fputc(fgetc(STREAM_UART1), STREAM_UART1);Alternatively, a function for parsing data in the receive buffer can be queued for execution with the timeouts library:#include void Uart1OnxTimeout(void* pArgs) while(kbhit(STREAM_UART1)) putc(getc(STREAM_UART1), STREAM_UART1);static void Uart1OnRx(void) TimeoutsAdd(Uart1OnxTimeout, NULL, 0);How can I use two or more ports on one PIC?The #USE RS232 (and I2C for that matter) is in effect for GETC, PUTC, PRINTF and KBHIT functions encountered until another #USE RS232 is found.The #USE RS232 is not an executable line. It works much like a #DEFINE. The following is an example program to read from one port (A) and echo the data to both the first port (A) and a second port (B).#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1)void put_to_a( char c ) put(c);char get_from_a( ) return(getc());#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)void put_to_b( char b ) putc(c);main() char c;put_to_a("Online\n\r");put_to_b("Online\n\r");while(TRUE) c=get_from_a();put_to_b(c);put_to_a(c);The following will do the same thing but is more readable and is the recommended method:#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1, STREAM=COM_A)#USE RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B3, STREAM=COM_B)main() char c;fprintf(COM_A,"Online\n\r");fprintf(COM_B,"Online\n\r");while(TRUE) c = fgetc(COM_A);fputc(c, COM_A);fputc(c, COM_B);
Many newer Microchip PIC microcontrollers have re-programmable peripheral pins (RP). These pins allow the user to dynamically allocate peripherals to these pins, such as external interrupts, input capture, PWM, serial, timers and more. This offers the designer great flexibility when designing a product since the functionality of these pins can be changed at run-time. The data sheet for a device will list he pin assignments and these pins are denoted as either RPxx or RPIxx, where xx is the RP pin number. Pins that are RPIxx can only be programmed as an input (timer input, serial input, interrupt input, etc), whereas RPxx pins can be programmed either as an input or output (PWM output, serial output, etc).Static Assignments in CThe static method for assigning I/O pins to a peripheral is the #pin_select directive. The #pin_select directive is a preprocessor directive for assigning I/O pins to peripherals and is executed before main() starts. The syntax for this command is as follows:#pin_select function=pinA list of functions and pins that can be used with the #pin_select directive is located in the device's header file near the top of the file, opening the device's header file (like 18F25K42.h) and searching for #pin_select is the quickest way to find them. The following is an example of how to assign pins to the UART1 RX and TX pins:#pin_select U1TX=PIN_C6#pin_select U1RX=PIN_C7When using RP pins with a peripheral library, such as #use rs232(), the #pin_select must come before the #use directive, for example:#pin_select U1TX=PIN_C6#pin_select U1RX=PIN_C7#use rs232(UART1, baud=9600, stream=U1)There is a special method for assigning the peripheral pins is inside the #use pwm and #use capture directives. Future compiler release may allow this in other #use directives as well. Here is an example:#use pwm(CCP1, output=PIN_B0)The above will make the assignment of PIN_B0 as the CCP1 output pin.Dynamic Pin assignmentsIn addition to #pin_select the CCS C Compiler also provides the pin_select() function for assigning pins to a peripheral. The pin_select() function can be used to assign, reassign and unassign pins to/from a peripheral at run-time. This allows the flexibility of using the same pin for multiple peripherals or using pins as both peripheral pins and I/O pins. The basic pin_select() function uses the following syntax: pin_select("function", pin);. The functions and pins are the same as what is used with the #pin_select directive, the only difference being that the function is passed as a constant string. The following is an example of how to assign pins to the UART1 peripheral:pin_select("U1TX", PIN_C6);pin_select("U1RX", PIN_C7);To unassign a pin from a peripheral depends on whether it an input peripheral or an output peripheral.To unassign a pin from an output peripheral is done as follows:pin_select("NULL", PIN_C6); //unassign PIN_C6 from output peripheral.To unassign a pin from an input peripheral is done as follows:pin_select("U1RX", FALSE); //unassign pin from U1RX input peripheral.Because of how output peripherals are assigned to RP pins it is possible to assign multiple pins to the same output peripheral when using the pin_select() directive. For example the following will assign multiple pins to the CCP1 peripheral:pin_select("CCP1OUT", PIN_B0);pin_select("CCP1OUT", PIN_B1);This method of tying several pins to the same output can only be performed with the pin_select() function, #pin_select cannot be used to do this.A more advanced form of the pin_select() directive is as follows:pin_select("function", pin, unlock, lock);In order to change the pin assignments at run time the pins must be first specifically unlocked to prevent run away code from changing a pin assignment. The optional unlock and lock are used to specify whether to do or not to do the unlock and lock procedures, TRUE does the procedure and FALSE doesn't to the procedure. When the lock/unlock parameters are not specified in the function both are performed by default. These optional parameters are most useful when using the pin_select() function to assign multiple peripheral pins sequentially. For example the following is an example of how to assign the UART1 TX and RX pins at run time:pin_select("U1TX", PIN_C6, TRUE, FALSE);pin_select("U1RX", PIN_C7, FALSE, TRUE);Alternate pin assignmentsBefore the RP pins came out some chips allowed select peripherals to have multiple (usually just two) pins that can be assigned. This is done either by a fuse (like CCP2B3 and CCP2C1) or using an internal register.In the case the selection is by fuse the #fuse directive must be inserted in the code and then the compiler will treat that pin as a peripheral. For example:#fuses CCP2C1In the case that the register assignments are made by register the built in functions will have an option for the assignment. See the header file for the device. The UART assignments are made with the #use rs232 by specifying one of the alternate pins.Like us on Facebook. Follow us on Twitter.About CCS: CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC MCU and dsPIC DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit PIC MCU, MPLAB IDE, MPLAB ICD2, MPLAB ICD3 and dsPIC are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.