ABSTRACT

This chapter explains the basic software structure of the PIC16F1847-Based PLC. A PLC scan cycle includes the following: (1) obtain the inputs, (2) run the user program, (3) update the outputs. In addition, it is also necessary to define and initialize all variables used within a PLC. Necessary functions are all described as PIC Assembly macros to be used in the PIC16F1847-Based PLC. The source files of the PIC16F1847-Based PLC are as follows: “PICPLC_PIC16F1847_memory.inc” (the individual bits of 8-bit SRAM registers M0, M1, …, M127 are defined in this file), “PICPLC_PIC16F1847_main.asm” (processor-specific variable definitions, PICPLC definitions, the user program, and subroutines are included in the project by using this file), “PICPLC_PIC16F1847_user.inc” (this file contains two macros, namely “user_program_1” and “user_program_2”, in order to accommodate user programs), “PICPLC_PIC16F1847_subr.inc” (this file contains the “subroutines” macro and it is defined to obtain time delays at the expense of CPU clocks; the “subroutines” macro contains two time-delay-related subroutines, “pause_1ms” and “pause_10us”), and “PICPLC_PIC16F1847_macros.inc”. The file “PICPLC_PIC16F1847_macros.inc” contains the following macros: “initialize” (for PLC initialization), “ISR” (interrupt service routines), “get_inputs” (for handling the inputs), “lpf_progs” (low-pass digital filter macros for analog inputs), and “send_outputs” (for sending the outputs).