Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

C language Operators and expressions

The main thing what microcontrollers does is operates with data. There are four main operations that microcontrollers does: adds, abstracts, multiplies and divides (+,-,*,/). division can be split in division “/” and modulus operation “%”. For instance i1/i2 is integer division. Other part of operators is Relation operators. They are used for boolean conditions and expressions. Expressions with these operators return true or false values. Zero is taken as false and non zero value as true. Operators may be as follows: <, <=, > >=, ==, !=. The priority of the first four operators is higher than that of the later two operators. These operators are used in relational expressions such as: 7 > 12 // false 20.1 < 20.2 // true ‘b’ < ‘c’ // true “abb” < “abc” // true Note that the equality operator is == and not =. ‘=’ is an assignment operator. If you want to compare a and b for equality then you should write a == b, not a = b because a = b means you are assigning the value of b to a, as shown in. Next part of operators are logical operators. With logical operators results may be combined to…

Continue reading

Constants in C language

Constant value is understandable as non changeable value like PI=3.141592… value in math. Usually you use constants in your programs, but don’t realize that they are constants. For instance: x=x+3; The number 3 is a constant which will be compiled directly in addition operation. Constants can be character or string. Like in function printf(“Hello World\n”); “Hello World” is a string constant which is placed in program memory and will never changes. It is usually recommended to declare constants by using identifier with reserved word const: const int No=44; By identifying the variable as constant will cause compiler to store this variable in program memory rather than in RAM, thus saving space in RAM. If special functions used, then constants can be also stored in EEPROM memory. Few words for the numeric constants. Numeric constants can be declared in many ways indicating their base. Decimal integer constants (base 10) consist of one or more digits, 0 through 9, where 0 cannot be used as the first digit. Binary constants (base 2) begin with a 0b or 0B prefix, followed by one or more binary digits (0, 1). Octal constants (base 8) consist of one or more digits 0 through 7, where…

Continue reading

The very basics of C

C language is function based programming language. C program itself is a function. Usually parameters to C function are passed as arguments. Function consists of a name followed by the parentheses enclosing arguments or an empty pair of parentheses if there are not arguments required. If there are several arguments, they are separated by commas. The mandatory part in C program is main function. This function must be included in every program because this is a first function which is run after execution of program. Lets take an example: #include <stdio.h> int main(void) { printf(“Hello world!\n”); return 0; } This is a very basic C program, but it contains all necessary elements of it. Lets examine a little bit what we have written here…

Continue reading