Ibrahim Dogan - Advanced PIC Microcontroller Projects in C

Здесь есть возможность читать онлайн «Ibrahim Dogan - Advanced PIC Microcontroller Projects in C» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Burlington, Год выпуска: 2008, ISBN: 2008, Издательство: Elsevier Ltd, Жанр: Программирование, Компьютерное железо, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Advanced PIC Microcontroller Projects in C: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Advanced PIC Microcontroller Projects in C»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

• The only project book on the PIC 18 series using the C programming language
• Features 20 complete, tried and test projects
• Includes a CD-ROM of all the programs, hex listings, diagrams, and data sheets

Advanced PIC Microcontroller Projects in C — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Advanced PIC Microcontroller Projects in C», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Sum count sum100 counter i1 UserName

_myName

Some names are reserved for the compiler itself and cannot be used as variable names in a program. Table 3.1 gives a list of these reserved names.

Table 3.1: mikroC reserved names

asm enum signed
auto extern sizeof
break float static
case for struct
char goto switch
const if typedef
continue int union
default long unsigned
do register void
double return volatile
else short while

3.1.7 Variable Types

The mikroC language supports the variable types shown in Table 3.2. Examples of variables are given in this section.

Table 3.2: mikroC variable types

Type Size (bits) Range
unsigned char 8 0 to 255
unsigned short int 8 0 to 255
unsigned int 16 0 to 65535
unsigned long int 32 0 to 4294967295
signed char 8 –128 to 127
signed short int 8 –128 to 127
signed int 16 –32768 to 32767
signed long int 32 –2147483648 to 2147483647
float 32 ±1.17549435082E-38 to ±6.80564774407E38
double 32 ±1.17549435082E-38 to ±6.80564774407E38
long double 32 ±1.17549435082E-38 to ±6.80564774407E38
(unsigned) char or unsigned short (int)

The variables (unsigned) char , or unsigned short (int) , are 8-bit unsigned variables with a range of 0 to 255. In the following example two 8-bit variables named total and sum are created, and sum is assigned decimal value 150:

unsigned char total, sum;

sum = 150;

or

char total, sum;

sum = 150;

Variables can be assigned values during their declaration. Thus, the above statements can also be written as:

char total, sum = 150;

signed char or (signed) short (int)

The variables signed char , or (signed) short (int) , are 8-bit signed character variables with a range of –128 to +127. In the following example a signed 8-bit variable named counter is created with a value of –50:

signed char counter = -50;

or

short counter = -50;

or

short int counter = -50;

(signed) int

Variables called (signed) int are 16-bit variables with a range –32768 to +32767. In the following example a signed integer named Big is created:

int Big;

unsigned (int)

Variables called (unsigned) int are 16-bit unsigned variables with a range 0 to 65535. In the following example an unsigned 16-bit variable named count is created and is assigned value 12000:

unsigned int count = 12000;

(signed) long (int)

Variables called (signed) long (int) are 32 bits long with a range –2147483648 to +2147483647. An example is:

signed long LargeNumber;

unsigned long (int)

Variables called (unsigned) long (int) are 32-bit unsigned variables having the range 0 to 4294967295. An example is:

unsigned long VeryLargeNumber;

float or double or long double

The variables called float or double or long double , are floating point variables implemented in mikroC using the Microchip AN575 32-bit format, which is IEEE 754 compliant. Floating point numbers range from ±1.17549435082E-38 to ±6.80564774407E38. In the following example, a floating point variable named area is created and assigned the value 12.235:

float area;

area = 12.235;

To avoid confusion during program development, specifying the sign of the variable (signed or unsigned) as well as the type of variable is recommended. For example, use unsigned char instead of char only, and unsigned int instead of unsigned only.

In this book we are using the following mikroC data types, which are easy to remember and also compatible with most other C compilers:

unsigned char 0 to 255
signed char –128 to 127
unsigned int 0 to 65535
signed int –32768 to 32767
unsigned long 0 to 4294967295
signed long –2147483648 to 2147483647
float ±1.17549435082E-38 to ±6.80564774407E38

3.1.8 Constants

Constants represent fixed values (numeric or character) in programs that cannot be changed. Constants are stored in the flash program memory of the PIC microcontroller, thus not wasting valuable and limited RAM memory. In mikroC, constants can be integers, floating points, characters, strings, or enumerated types.

Integer Constants

Integer constants can be decimal, hexadecimal, octal, or binary. The data type of a constant is derived by the compiler from its value. But suffixes can be used to change the type of a constant.

In Table 3.2 we saw that decimal constants can have values from –2147483648 to +4294967295. For example, constant number 210 is stored as an unsigned char (or unsigned short int ). Similarly, constant number –200 is stored as a signed int .

Using the suffix u or U forces the constant to be unsigned . Using the suffix L or l forces the constant to be long . Using both U (or u) and L (or l) forces the constant to be unsigned long .

Constants are declared using the keyword const and are stored in the flash program memory of the PIC microcontroller, thus not wasting valuable RAM space. In the following example, constant MAX is declared as 100 and is stored in the flash program memory of the PIC microcontroller:

const MAX = 100;

Hexadecimal constants start with characters 0x or 0X and may contain numeric data 0 to 9 and hexadecimal characters A to F. In the following example, constant TOTAL is given the hexadecimal value FF:

const TOTAL = 0xFF;

Octal constants have a zero at the beginning of the number and may contain numeric data 0 to 7. In the following example, constant CNT is given octal value 17:

const CNT = 017;

Binary constant numbers start with 0b or 0B and may contain only 0 or 1. In the following example a constant named Min is declared as having the binary value 11110000:

const Min = 0b11110000

Floating Point Constants

Floating point constant numbers have integer parts, a dot, a fractional part, and an optional e or E followed by a signed integer exponent. In the following example, a constant named TEMP is declared as having the fractional value 37.50:

const TEMP = 37.50

or

const TEMP = 3.750E1

Character Constants

A character constant is a character enclosed within single quote marks. In the following example, a constant named First_Alpha is declared as having the character value “A”:

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Advanced PIC Microcontroller Projects in C»

Представляем Вашему вниманию похожие книги на «Advanced PIC Microcontroller Projects in C» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Advanced PIC Microcontroller Projects in C»

Обсуждение, отзывы о книге «Advanced PIC Microcontroller Projects in C» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x