Книга: Advanced PIC Microcontroller Projects in C

3.1.20 Mixing mikroC with Assembly Language Statements

3.1.20 Mixing mikroC with Assembly Language Statements

It sometimes becomes necessary to mix PIC microcontroller assembly language statements with the mikroC language. For example, very accurate program delays can be generated by using assembly language statements. The topic of assembly language is beyond the scope of this book, but techniques for including assembly language instructions in mikroC programs are discussed in this section for readers who are familiar with the PIC microcontroller assembly languages.

Assembly language instructions can be included in a mikroC program by using the keyword asm (or _asm, or __asm). A group of assembly instructions or a single such instruction can be included within a pair of curly brackets. The syntax is:

asm {
 assembly instructions
}

Assembly language style comments (a line starting with a semicolon character) are not allowed, but mikroC does allow both types of C style comments to be used with assembly language programs:

asm {
 /* This assembly code introduces delay to the program*/
 MOVLW 6 // Load W with 6
 ................
 ................
}

User-declared C variables can be used in assembly language routines, but they must be declared and initialized before use. For example, C variable Temp can be initialized and then loaded to the W register as:

unsigned char Temp = 10;
asm {
 MOVLW Temp // W = Temp = 10
..................
..................
}

Global symbols such as predefined port names and register names can be used in assembly language routines without having to initialize them:

asm {
 MOVWF PORTB
 .....................
 .....................
}

Оглавление книги


Генерация: 0.056. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз