C programming language developed by Dennis Ritchie at Bell Labs. It is generally used for develop a software applications, operating system, device drivers etc. now a days this programming language also used for develop a plc program. B&R plc support ANSI C language for develop a plc program. ANSI C is standardized version of the C programming language developed by the American National Standards Institute (ANSI).It is also known as C89 or ISO C. latest version of ANSI C is C11.ANSI C allows users to call function blocks and access variables from other IEC languages. This standardized version of C language support function prototypes, void pointers, and library functions, string and memory allocation. C language have low-level memory manipulation capabilities and ability to interface with hardware. C language, including variable declarations, function definitions, and library functions.
Add C language program in B&R automation Project
open your B&R automation studio and Create A New Project if you don’t have physical plc than is a pc based simulation for making a program during a project setup select pc based simulation. to making a program in c for a plc in a B&R automation studio, In A Menu Bar Select Insert Than Add Object Or Right Click on logical view Than Add Object.
a add object dialog select program than select new program or existing program click next
enter name of program and local data type name and add a description of your program click next
enter the initialization part of the program, select Language as ANSI C in program from drop down menu click to next
select an option if you want to assign object to cpu than click finish
new program add in a logical view it have following file
Cyclic code : A cyclic object is executed in a cycle time.
initialization code : program that execute during start up
local data type : declarations of Custom data types.
local variable: declarations of local Variable
B&R automation C program layout
open your inserted c program, below is the cyclic program of B&R automation, in B&R automation C program have predefined layout which start with a file header section of c program, after file header section main program section is start
file header section C program
in this section contain information of source code file like copyright, module name, file name, author of program, date of file creation, description of source code file and file history. all part of this section only for information, file header section not executed during program execution because it is commented statement. you also add or modify any details like revision, your company name, author name, date, company website or developer email etc.
main program section of c program
this is main program which executed statement of program. ansi c program start with Preprocessor directives after preprocessor directives main program function start. Preprocessor directive in C begin with a "#" symbol and are used to include header files or define macros. we discuss more about preprocessor directive in C with example? some another article.
B&R automation studio c Programing example
above is the c programming example in a b&r automation studio, in this program we find entered value is even or odd, this is a very simple program. % sign is modulo operator. if the number is even than remainder is zero so value is even. if the value1 is not equal to zero than entered value is odd.enter_value is integer data type while even and odd values are bool data type.
B&R automation studio timer program in c
above is the program of timer program, this program we use a on delay timer, we know on delay timer delay the out of timer. so first declare instance of timer you can declare instance on a program or in variable file in this example on delay timer instance declared in a variable file. declare variable start_timer and timer_output as bool data type. in a program set all input parameter of timer like preset time. preset and elapsed time of timer defined in time data type. download program in controller or simulator and than set the preset time of timer and set 1 in start_timer timer
variable.