APPLICATION NOTE 740 Family Programming Guidelines Preface This application note is written for the Renesas 740 family 8-bit single-chip microcomputers. It explains the basics of C language programming and how to put your program into ROM using the M3T–ICC740 C compiler. For details about hardware and development support tools available for each type of microcomputer in the740 family, please refer to the appropriate hardware manuals, user's manuals and instruction manuals.
740 Family Programming Guidelines Table of Contents Chapter 1 Introduction to C Language _____________________________ 4 1.1 Programming in C ······································································································5 1.1.1 Assembly Language and C............................................................................................. 5 1.1.2 Program Development Procedure ................................................................................. 6 1.1.
740 Family Programming Guidelines 1.9.3 Macro Definition .......................................................................................................... 65 1.9.4 Conditional Compile .................................................................................................... 67 Chapter 2 Downloading a Program into the ROM ___________________ 69 2.1 Memory Allocation ··································································································70 2.1.
APPLICATION NOTE Chapter 1 Introduction to C Language 1.1 Programming in C Language 1.2 Data Types 1.3 Operators 1.4 Control Statements 1.5 Functions 1.6 Storage Classes 1.7 Arrays and Pointers 1.8 Struct and Union 1.9 Preprocess Commands This chapter explains for those who learn the C language for the first time the basics of the C language that are required when creating a built-in program. REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide 1.1 Programming in C Language 1.1.1 Assembly Language and C Language The following explains the main features of the C language and describes how to write a program in "C". Features of the C Language (1) An easily traceable program can be written. The basics of structured programming, i.e., "sequential processing", "branch processing", and "repeat processing", can all be written in a control statement.
740 Family Programming Guide 1.1.2 Program Development Procedure The operation of translating a source program written in "C" into machine language is referred to as "compiling". The software provided for performing this operation is called a "compiler". This section explains the procedure for developing a program by using M3T-ICC740, the C compiler for the 740 family of Renesas 8-bit single-chip microcomputers.
40 Family Programming Guide Creating Machine Language File from Source File Creation of a machine language file requires the conversion of start-up programs written in Assembly language and C language source files. The following shows the tool chain necessary to create a machine language file from a C language source file. C language source file Startup program cstartup.
740 Family Programming Guide 1.1.3 Easily Understandable Program Since there is no specific format for C language programs, they can be written in any desired way only providing that some rules stipulated for the C language are followed. However, a program must be easily readable and must be easy to maintain. Therefore, a program must be written in such a way that everyone, not just the one who developed the program, can understand it.
740 Family Programming Guide Programming Style To improve program maintainability, programming conversions should be agreed upon by the programming team. Creating a template is a good way for the developers to establish a common programming style that will facilitate program development, debug and maintenance. The following shows an example of a programming style. (1) Create separate functions for various tasks of a program.
740 Family Programming Guide Method for Writing Comments Comments are an important aspect of a well written program. Program flow can be clarified, for example, through a file and function headers. Example of file header /* ""FILE COMMENT"" ************************************************************************ * System Name : Test program * File Name : TEST.C * Version : 1.
740 Family Programming Guide Column Reserved Words of ICC740 The words listed in the following are reserved for ICC740. Therefore, these words cannot be used in variable or function names.
740 Family Programming Guide 1.2 Data Types 1.2.1 "Constants" in C Language Four types of constants can be handled in the C language: "integer", "real", "single character" and "character string". This section explains the method of description and the precautions to be noted when using each of these constants. Integer Constants Integer constants can be written using one of three methods of numeric representation: decimal, hexadecimal, and octal.
740 Family Programming Guide Character String Constants A row of alphanumeric characters or control codes enclosed with double quotations (") can be handled as a character string constant. Character string constants have the null character "\0" automatically added at the end of data to denote the end of the character string.
740 Family Programming Guide 1.2.2 Variables Before a variable can be used in a C language program, its "data type" must first be declared in the program. The data type of a variable is determined based on the memory size allocated for the variable and the range of values handled. This section explains the data types of variables that can be handled by ICC740 and how to declare the data types. Basic Data Types of ICC740 The following lists the data types that can be handled in ICC740.
740 Family Programming Guide Declaration of Variables Variables are declared using a format that consists of a "data type variable name;". Example: To declare a variable a as char type char a; By writing "data type variable name = initial value;", a variable can have its initial value set simultaneously when it is declared.
740 Family Programming Guide 1.2.3 Data Characteristics When declaring a variable or constant, ICC740 allows its data characteristic to be written along with the data type. The specifier used for this purpose is called the "type qualifier". This section explains the data characteristics handled by ICC740 and how to specify a data characteristic.
740 Family Programming Guide Inhibiting Optimization by Compiler (volatile Qualifier) ICC740 optimizes the instructions that do not have any effect in program processing, thus preventing unnecessary instruction code from being generated. However, there are some data that are changed by an interrupt or input from a port irrespective of program processing. Write the type qualifier "volatile" when declaring such data.
740 Family Programming Guide 1.3 Operators 1.3.1 Operators of ICC740 ICC740 has various operators available for writing a program. This section describes how to use these operators for each specific purpose of use (not including address and pointer operators) and the precautions to be noted when using them. ICC740 Operators The following lists the operators that can be used in ICC740.
740 Family Programming Guide 1.3.2 Operators for Numeric Calculations The primary operators used for numeric calculations consist of the "arithmetic operators" to perform calculations and the "assignment operators" to store the results in memory. This section explains these arithmetic and assignment operators. Monadic Arithmetic Operators Monadic arithmetic operators return one answer for one variable.
740 Family Programming Guide Assignment Operators The operation of "expression 1 = expression 2" assigns the value of expression 2 for expression 1. The assignment operator '=' can be used in combination with arithmetic operators described above or bitwise or shift operators that will be described later. (This is called a compound assignment operator.) In this case, the assignment operator '=' must always be written on the right side of the equation.
740 Family Programming Guide 1.3.3 Operators for Processing Data The operators frequently used to process data are "bitwise operators" and "shift operators". This section explains these bitwise and shift operators. Bitwise Operators Use of bitwise operators makes it possible to mask data and perform active conversion.
740 Family Programming Guide Comparison between Arithmetic and Logical Shifts When executing "shift right", note that the shift operation varies depending on whether the data to be operated on is singed or unsigned. • When unsigned → Logical shift: A logic 0 is inserted into the most significant bit. • When signed → Arithmetic shift: Shift operation is performed so as to retain the sign.
740 Family Programming Guide 1.3.4 Operators for Examining Condition Used to examine a condition in a control statement are "relational operators" and "logical operators". Either operator returns a logic 1 when a condition is met and a logic 0 when a condition is not met. This section explains these relational and logical operators. Relational operators These operators examine two expressions to see which is larger or smaller than the other.
740 Family Programming Guide 1.3.5 Other Operators This section explains four types of operators which are unique in the C language. Conditional Operator This operator executes expression 1 if a condition expression is true or expression 2 if the condition expression is false. If this operator is used when the condition expression and expressions 1 and 2 both are short in processing description, coding of conditional branches can be simplified.
740 Family Programming Guide Cast Operator When operation is performed on data whose types differ from each other, the data used in that operation are implicitly converted into the data type that is largest in the expression. However, since this could cause an unexpected fault, a cast operator is used to perform type conversions explicitly. Operator () Description format (new data type) variable Content Converts the data type of the variable to the new data type.
740 Family Programming Guide 1.3.6 Priorities of Operators The operators used in the C language are subject to "priority resolution" and "rules of combination" as are the operators used in mathematics.
740 Family Programming Guide 1.3.7 Examples for Easily Mistaken Use of Operators The program may not operate as expected if the "implicit conversion" or "precedence" of operators are incorrectly interpreted. This section shows examples for easily mistaken use of operators and how to correct.
740 Family Programming Guide Incorrectly Interpreted "Precedence" of Operators and How to Correct When one expression includes multiple operators, the "precedence" and "associativity" of operators need to be interpreted correctly. Also, to ensure that the program will operate as expected, use expressional "().
740 Family Programming Guide 1.4 Control Statements 1.4.1 Structuring of Program The C language allows "sequential processing", "branch processing" and "repeat processing"-- the basics of structured programming--to be written using control statements. Consequently, all programs written in the C language are structured. This is why the processing flow in C language programs are easy to understand. This section describes how to write these control statements and shows some examples of usage.
740 Family Programming Guide 1.4.2 Branching Processing Depending on Condition (Branch Processing) Control statements used to write branch processing include "if-else", "else-if", and "switch-case" statements. This section explains how to write these control statements and shows some examples of usage. if-else Statement This statement executes the next block if the given condition is true or the "else" block if the condition is false. Specification of an "else" block can be omitted.
740 Family Programming Guide else-if Statement Use this statement when it is necessary to divide program flow into three or more flows of processing depending on multiple conditions. Write the processing that must be executed when each condition is true in the immediately following block. Write the processing that must be executed when none of conditions holds true in the last "else" block.
740 Family Programming Guide switch-case Statement This statement causes program flow to branch to one of multiple processing depending on the result of a given expression. Since the result of an expression is handled as a constant when making decision, no relational operators, etc. can be used in this statement.
740 Family Programming Guide Column switch-case Statement without Break A switch-case statement normally has a break statement entered at the end of each of its execution statements. If a block that is not accompanied by a break statement is encountered, the program executes the next block after terminating that block. In this way, blocks are executed sequentially from above. Therefore, this allows the start position of processing to be changed depending on the value of an expression.
740 Family Programming Guide 1.4.3 Repetition of Same Processing (Repeat Processing) Control statements used to write repeat processing include "while", "for" and "do-while" statements. This section explains how to write these control statements and shows some examples of usage. while Statement This statement executes processing in a block repeatedly as long as the given condition expression is met.
740 Family Programming Guide for Statement The repeat processing that is performed by using a counter always requires operations to "initialize" and "change" the counter content, in addition to determining the given condition. A for statement makes it possible to write these operations along with a condition expression. Initialization (expression 1), condition expression (expression 2), and processing (expression 3) each can be omitted.
740 Family Programming Guide do-while Statement Unlike the for and while statements, this statement determines whether a condition is true or false after executing processing (post-execution determination). Although there could be some processing in the for or while statements that is never once executed, all processing in a do-while statement is executed at least once.
740 Family Programming Guide 1.4.4 Suspending Processing There are control statements (auxiliary control statements) such as break, continue, and goto statements that make it possible to suspend processing and quit. This section explains how to write these control statements and shows some examples of usage. break Statement Use this statement in repeat processing or in a switch-case statement. When "break;" is executed, the program suspends processing and exits only one block.
740 Family Programming Guide goto Statement When a goto statement is executed, the program unconditionally branches to the label written after the goto statement. Unlike break and continue statements, this statement makes it possible to exit multiple blocks collectively and branch to any desired location in the function. However, since this operation is contrary to structured programming, it is recommended that a goto statement be used in only exceptional cases as in error processing.
740 Family Programming Guide 1.5 Functions 1.5.1 Functions and Subroutines As subroutines are the basic units of program in the assembly language, so are the "functions" in the C language. This section explains how to write functions in ICC740. Arguments and Return Values Data exchanges between functions are accomplished by using "arguments", equivalent to input variables in a subroutine, and "return values", equivalent to output variables in a subroutine.
740 Family Programming Guide 1.5.2 Creating Functions Three procedures are required before a function can be used. These are "function declaration" (prototype declaration), "function definition", and "function call". This section explains how to write these procedures. Function Declaration (Prototype Declaration) Before a function can be used in the C language, function declaration (prototype declaration) must be entered first.
740 Family Programming Guide Example for a Function In this example, we will write three functions that are interrelated as shown below. No argument int type No return value Main function main int type char type int type No return value Function 1 func 1 Function 2 func 2 /* Prototype declaration void main(void); int func1(int); void func2(int, char); */ /* Main function */ void main() { int a = 40,b = 29; int ans; char c = 0xFF; Calls function 1 ("func1") using a as argument.
740 Family Programming Guide 1.5.3 Exchanging Data between Functions In the C language, exchanges of arguments and return values between functions are accomplished by copying the value of each variable as it is passed to the receiver ("Call by Value"). Consequently, the name of the argument used when calling a function and the name of the argument (dummy argument) received by the called function do not need to coincide.
740 Family Programming Guide 1.6 Storage Classes 1.6.1 Effective Range of Variables and Functions Variables and functions have different effective ranges depending on their nature, e.g., whether they are used in the entire program or in only one function. These effective ranges of variables and functions are called "storage classes (or scope)". This section explains the types of storage classes of variables and functions and how to specify them.
740 Family Programming Guide 1.6.2 Storage Classes of Variables The storage class of a variable is specified when writing type declaration. There are following two points in this: (1) External and internal variables (→location where type declaration is entered) (2) Storage class specifier (→specifier is added to type declaration) This section explains how to specify storage classes for variables.
740 Family Programming Guide Storage Classes of External Variable If no storage class specifier is added for an external variable when declaring it, the variable is assumed to be a global variable that is effective in the entire program. On the other hand, if an external variable is specified of its storage class by writing "static" when declaring it, the variable is assumed to be a local variable that is effective in only the file where it is declared.
740 Family Programming Guide 1.6.3 Storage Classes of Functions The storage class of a function is specified on both function defining and function calling sides. The storage class specifiers that can be used here are static and extern. This section explains how to specify the storage class of a function.
740 Family Programming Guide Summary of Storage Classes Storage classes of variables and storage classes of functions are summarized below. Storage Classes of Variables Storage class Storage class specifiers omitted External variable Global variables that can also be referenced from other source files. [Allocated in segment N_UDATA and N_IDATA] [Maintain data] auto static Local variables that cannot be referenced from other source files.
740 Family Programming Guide 1.7 Arrays and Pointers 1.7.1 Arrays Arrays and pointers are the characteristic features of the C language. This section describes how to use arrays and explains pointers that provide an important means of handling the array. What is an Array? The following explains the functionality of an array by using a program to find the total age of family members as an example.
740 Family Programming Guide 1.7.2 Creating an Array There are two types of arrays handled in the C language: "one-dimensional array" and "two-dimensional array". This section describes how to create and reference each type of array. One-dimensional Array A one-dimensional array has a one-dimensional (linear) expanse. The following shows the declaration format of a one-dimensional array.
740 Family Programming Guide Two-dimensional Array A two-dimensional array has a planar expanse comprised of "columns" and "rows". Or it can be considered to be an array of one-dimensional arrays. The following shows the declaration format of a two-dimensional array. Data type array name [number of rows] [number of columns]; To reference a two-dimensional array, add "row numbers" and "column numbers" to the array name as subscript.
740 Family Programming Guide 1.7.3 Pointers A pointer is a variable that points to data; i.e., it indicates an address. A "pointer variable" which will be described here handles the "address" at which data is stored as a variable. This is equivalent to what is referred to as "indirect addressing" in assembly language. This section explains how to declare and reference a pointer variable. Declaring a Pointer Variable The format show below is used to declare a pointer variable.
740 Family Programming Guide Relationship between Pointer Variables and Variables The following explains the relationship between pointer variables and variables by using a method for substituting constant '5' by using pointer variable 'p' for variable of int type 'a' as an example. void { main(void) int int int a=0; b; *p ; p = &a ; *p = 5 ; b=a; Address modifier ↓ This "&a" indicates the address of variable 'a'. This "*p" indicates the content of variable 'a'.
740 Family Programming Guide 1.7.4 Using Pointers This section shows some examples for effectively using a pointer. Pointer Variables and One-dimensional Array When an array is declared by using subscripts to indicate its element numbers, it is encoded as "index addressing". In this case, therefore, address calculations to determine each address "as reckoned from the start address" are required whenever accessing the array.
740 Family Programming Guide Passing Addresses between Functions The basic method of passing data to and from C language functions is referred to as "Call by Value". With this method, however, arrays and character strings cannot be passed between functions as arguments or returned values. Used to solve this problem is a method, known as "Call by Reference", which uses a pointer variable.
740 Family Programming Guide 1.7.5 Placing Pointers into an Array This section explains a "pointer array" where pointer variables are arranged in an array. Pointer Array Declaration The following shows how to declare a pointer array.
740 Family Programming Guide Pointer Array and Two-dimensional Array The following explains the difference between a pointer array and a two-dimensional array. When multiple character strings each consisting of a different number of characters are declared in a two-dimensional array, the free spaces are filled with null code "\0". If the same is declared in a pointer array, there is no free space in memory.
740 Family Programming Guide 1.7.6 Table Jump Using Function Pointer In assembly language programs, "table jump" is used when switching processing load increases depending on the contents of some data. The same effect as this can be obtained in C language programs also by using the pointer array described above. This section explains how to write a table jump using a "function pointer".
740 Family Programming Guide 1.8 Struct and Union 1.8.1 Struct and Union The data types discussed hereto (e.g., char, signed int, and unsigned int types) are called the "basic data types" stipulated in compiler specifications. The C language allows the user to create new data types based on these basic data types. These are "struct" and "union". The following explains how to declare and reference structs and unions.
740 Family Programming Guide 1.8.2 Creating New Data Types The elements that constitute a new data type are called "members". To create a new data type, define the members that constitute it. This definition makes it possible to declare a data type to allocate a memory area and reference it as necessary in the same way as the variables described earlier. This section describes how to define and reference structs and unions, respectively.
740 Family Programming Guide Referencing Struct To refer to each member of a struct, use a period '.' that is a struct member operator. struct variable name.member name struct person{ char *name; long number; char section[5]; int work_year; }; void { a main(void) struct person a; a.name = "SATOH"; a.number = 10025; a.section = "T511"; a.work_year = 25; b name a.name number a.number section[0] section[1] section[2] section[3] section[4] a.section[0] to a.section[4] work_year a.
740 Family Programming Guide Example for Referencing Members Using a Pointer To refer to each member of a struct using a pointer, use an arrow '->'. Pointer->member name #define LYEAR 20 struct person{ char *name; long number; char section[5]; int work_year; }; Addres of "SATOH" &a A or *p struct person a = { "SATOH", 10025, "T511", 25 }; void { main(void) p struct person *p; p = &a; if( p->wprk_year > LYEAR){ REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide Unions Unions are characteristic in that an allocated memory area is shared by all members. Therefore, it is possible to save on memory usage by using unions for multiple entries of such data that will never exist simultaneously. Unions also will prove convenient when they are used for data that needs to be handled in different units of data size, e.g., 16 bits or 8 units, depending on situation. To define a union, write "union".
740 Family Programming Guide 1.9 Preprocess Commands 1.9.1 Preprocess Commands of ICC740 The C language supports file inclusion, macro function, conditional compile, and some other functions as "preprocess commands". The following explains the main preprocess commands available with ICC740. Preprocess Command List of ICC740 Preprocess commands each consist of a character string that begins with the symbol '#' to discriminate them from other execution statements.
740 Family Programming Guide 1.9.2 Including a File Use the command "#include" to take in another file. ICC740 requires different methods of description depending on the directory to be searched. This section explains how to write the command "#include" for each purpose of use. Searching for Standard Directory #include This statement takes in a file from the directory specified with the startup option '–I.
740 Family Programming Guide 1.9.3 Macro Definition Use the "#define identifier" for character string replacement and macro definition. Normally use uppercase letters for this identifier to discriminate it from variables and functions. This section explains how to define a macro and cancel a macro definition. Defining a Constant A constant can be assigned a name.
740 Family Programming Guide Defining a Macro Function The command "#define" can also be used to define a macro function. This macro function allows arguments and return values to be exchanged in the same way as with ordinary functions. Furthermore, since this function does not have the entry and exit processing that exists in ordinary functions, it is executed at higher speed. What's more, a macro function does not require declaring the argument's data type.
740 Family Programming Guide 1.9.4 Conditional Compile ICC740 allows you to control compilation under three conditions. Use this facility when, for example, controlling function switchover between specifications or controlling incorporation of debug functions. This section explains types of conditional compilation and how to write such statements. Various Conditional Compilation The following lists the types of conditional compilation that can be used in ICC740.
740 Family Programming Guide Example for Conditional Compile Description The following shows an example for using conditional compilation to control incorporation of debug functions. #define void { DEBUG It defines an identifier "DEBUG". (Set to debug mode.) main(void) #ifdef DEBUG check_output(); #else output(); #endif When in debug mode, it calls "debug function;" otherwise, it calls "ordinary output function". In this case, it calls "debug function".
APPLICATION NOTE Chapter 2 Downloading a Program into the ROM 2.1 Memory Allocation 2.2 Initialization Setup Files 2.3 Extended Functions for Putting into the ROM 2.4 Linkage with Assembly Language 2.5 Interrupt Handling This chapter describes the precautions to be taken when creating a built-in program centering round the extended functions of the ICC740. REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide 2.1 Memory Allocation 2.1.1 Types of Codes and Data The codes and data that comprise a program come in various types, including those that can or cannot be rewritten and those that have or do not have initial values. All codes and data must be located in the ROM, RAM or stack areas according to their properties. This section describes the types of codes and data that are generated by the ICC740.
740 Family Programming Guide 2.1.2 Segments Managed by the ICC740 The ICC740 manages the areas in which data or codes have been located as “segments.” This section describes the types of segments generated and managed by the ICC740 and how they are managed. Segment configuration The ICC740 classifies data by types as it manages segments. The configuration of segments managed by the ICC740 is shown below.
740 Family Programming Guide 2.1.3 Controlling Memory Allocation The ICC740 allows segments to be located in memory efficiently in a manner suitable for the user system. Segment locations in memory The following shows how segments will be located in memory depending on data types.
740 Family Programming Guide Adding segment names (“lnk740.xcl”) The segments generated by the ICC740 have the order specified in the link command file “lnk740.xcl” in which they are to be located. The newly created segments must each have a segment name added in the link command file “lnk740.xcl.” -! - lnk740.xcl XLINK 4.44, or higher, command file to be used with the 740 C-compiler V1.
0 Family Programming Guide Column Changing segment names (#pragma codeseg) #pragma codeseg (segment name to be changed) Change the name of a program segment generated by the ICC740. void func1( void ) { • • RSEG CODE func1: • • • Expansion image } #pragma codeseg ( NEW_CODE ) RSEG NEW_CODE func2: void func2( void ) { • • • • • • • } func1 is expanded with the default segment name, whereas func2 is expanded with a changed segment name.
740 Family Programming Guide 2.2 Initialization Setup Files 2.2.1 Roles of the Initialization Setup Files The ICC740 has two initialization setup files, namely the startup program “cstartup.s31” and the link command file “lnk740.xcl.” This section describes the roles and structures of the initialization setup files.
740 Family Programming Guide 2.2.2 Startup Program For a built-in type program to be run normally, it is necessary to initialize the microcomputer and set up the stack area before the program can be processed. Normally, these types of processing cannot be written in C language. Therefore, a program for initial setup is written in assembly language, separately from the C language source program. This is the “startup program.” The startup program “cstartup.
740 Family Programming Guide Setting up the stack page (“cstartup.s31”) Set up the stack page. Make sure the value of each bit in the CPU mode register is set to suit the operating environment. Where and how to write is shown below. Set up the stack page. By default, it is set in ;---------------------------------------------------------------; page 1.
740 Family Programming Guide Registering the reset vector (“cstartup.s31”) Set the reset vector (module name to be started after a reset). ?CSTARTUP_RESETVEC: WORD init_C REJ05B0468-0100Z /Rev.1.00 Start running from init_C after a reset.
740 Family Programming Guide 2.2.3 Link Command File The link command file is used to set up details about the memory map. The following describes the link command file “lnk740.xcl.” Modifying the link command file Change the following parts of the link command file to make it suitable for the user program to be created. lnk740.
740 Family Programming Guide Segment location and beginning/ending address settings (“lnk740.xcl”) Set the locations in memory and the beginning/ending addresses of the segments generated by the ICC740. Segments with no beginning addresses specified are located at contiguous memory addresses following the previously defined segment. Segments separated by a comma are allocated to memory addresses in the order they are written.
740 Family Programming Guide Setting the stack size (“lnk740.xcl”) Those that use a stack include a temporary area used in complicated calculations and a return address. In the ICC740, stacks are classified as shown below, for the purpose of efficient memory usage. CSTACK EXPR_STACK INT_EXPR_STACK RF_STACK Stack. Holds a hardware stack. Expression stack. Temporarily holds a result while an expression is being evaluated in normal processing. Interrupt expression stack.
740 Family Programming Guide Setting the beginning/ending addresses of the interrupt vector (“lnk740.xcl”) Set the beginning/ending addresses of the interrupt vector. An example of how to set is shown below. -! Setup the "INTVEC" interrupt segment.
740 Family Programming Guide Specifying a library (“lnk740.xcl”) Specify a library. An example of how to specify is shown below. -! This example files selects the default library which is tiny memory model and a 740 with MUL/DIV. This corresponds to option -mt and -v0 to the compiler. If you want to use another library, you can do it by removing the comments around it and adding comments around the default library. -! Specify a library.
740 Family Programming Guide 2.3 Extended Functions for Putting into the ROM 2.3.1 Variable Location The accessible memory space of the 740 family microcomputers is 64 Kbytes at maximum. The ICC740 manages this memory space by dividing it into the “Z page area” at the addresses 0000h–00FFh and the “N page area” at the addresses 0100h–FFFFh for management purposes. This section describes how to locate variables and functions in these areas and how to access.
740 Family Programming Guide Pointer variables A pointer variable itself and its reference address both are located in the default area (N page area). Also, it is possible to specify the default area (N page area) for the pointer variable itself and the Z page area for the reference address.
740 Family Programming Guide 2.3.2 Handling of Bits The ICC740 allows data to be handled in bit units. This is accomplished by using a bit variable in two ways: one using extended feature, and the other using a union. This section describes each method. Bit variables The following shows how to handle bits in the ICC740. (1) When using the single bit variable “bit” of the extended language feature The bit variable represents one bit in a Z page sfr variable.
740 Family Programming Guide Column About the location of bit-fields If it is desired to change the order in which bit-fields are stored, use the #pragma directive. Because the order in which bit-fields are stored depends on the compiler, this method helps to avoid the portability problems.
740 Family Programming Guide 2.3.3 Control of the I/O Interface To control I/O interfaces in an embedded system, specify absolute addresses for variables. There are two methods to specify absolute addresses in the ICC740: one by defining the SFR area, and one by using a pointer. This section describes each method. Defining the SFR area Use the sfr variable of the extended language feature to set the SFR area.
740 Family Programming Guide 2.3.4 Alternative Way when Unable to Write in C Language Hardware related processing when “the processing time is insufficient” or “to control the C flag directly” cannot always be written in C language. In such a case, the ICC740 allows assembly language to be written directly into the C language source program (known as the “inline assemble feature). The inline assemble feature can be accomplished using the “inline function” or the “asm function.
740 Family Programming Guide 2.4 Linkage with Assembly Language 2.4.1 Interfacing between Functions Assembly language subroutines can be called from a C language program. Use this interface to call assembly language from C language. This section describes interfacing between functions in the ICC740.
740 Family Programming Guide Rules for passing arguments The ICC740 uses different places in which to store arguments depending on the data types of arguments. The following shows how arguments are passed to a function. Type of argument char type Other types Passed via Accumulator * C_ARGN or C_ARGZ * For the first argument only Rules for passing return values The ICC740 uses different places in which to store return values depending on the data types of return values.
740 Family Programming Guide Interface keywords To declare the functions in an assembly language program to be called from a C language program, use the assembler interface keyword “DEFFN.” For the functions in an assembly language program to be referenced from a C language program, you need to declare the names of those functions with “PUBLIC.” Then, in the C language program, declare those functions names as “EXTERN.
740 Family Programming Guide 2.4.2 Calling Assembly Language from C Language This section describes how to write a program to call assembly language subroutines as C language functions. Calling assembly language subroutines To call assembly language subroutines (assembly language functions) from a C language program, follow the rules described below. (1) Write the subroutine in a separate file from the C language program. (2) For the subroutine name, follow the symbol conversion rules.
740 Family Programming Guide Example for calling a subroutine The following shows a sample program that indicates the result of a count-up operation on LEDs. Create the LED display part in assembly language and the count-up part in C language, and then link.
740 Family Programming Guide 2.5 Interrupt Handling The ICC740 allows interrupt handling to be written as C language functions. The procedure consists of the following four steps: (1) Writing the interrupt handling function (2) Setting the interrupt disable flag (I flag) Do this by using an inline function. (3) Registering to the interrupt vector area (4) Setting up the interrupt vector segment REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide 2.5.1 Example for Writing Interrupt Handling Functions This section shows an example for writing a program that clears the content of the “counter” to 0 each time an INT0 interrupt (rising edge) occurs in the 3803 group and counts up the content of the “counter” each time an INT2 interrupt (falling edge) occurs. Example for writing interrupt handling functions An example of how to write the source file is shown below. #include #include "io3803.
740 Family Programming Guide 2.5.2 Writing Interrupt Handling Functions The ICC740 allows interrupt handling functions to be written in C or assembly language. This section describes the basic method for writing interrupt handling functions in C language. Basic method for writing interrupt handling functions (C language) Use the extended keyword interrupt to define interrupt handling functions. An example of how to write and an expanded image are shown below. interrupt void intr( void ) { ...
740 Family Programming Guide 2.5.3 Setting the Interrupt Disable Flag (I Flag) Setting the interrupt disable flag (I flag) For interrupts to be generated, the interrupt disable flag (I flag) must be cleared to 0 (enabled). The ICC740 allows the I flag to be set by an inline function. To use inline functions, make sure “intr740.h” is included. #include
740 Family Programming Guide 2.5.4 Registering to the Interrupt Vector Area For interrupts to be used, it is necessary to write interrupt handling functions, as well as register the written interrupt handling functions in the interrupt vector area. This section describes how to register the interrupt handling functions. Registering interrupt handling functions By altering the content of the INTVEC segment in the cstartup.
740 Family Programming Guide 2.5.5 Setting Up the Interrupt Vector Segment Setting up the interrupt vector segment To set up the interrupt vector segment, set the addresses given below in the interrupt vector segment “INTVEC” of the link command file “lnk740.xcl.” Beginning and ending addresses of the interrupt vector area -Z(CODE)INTVEC=FFDC-FFFD * Make sure the beginning and ending addresses of the interrupt vector area you set here suit the microcomputer used. REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide 740 family Programming Guide Application Note REVISION HISTORY Rev. Date 1.00 Sep 15, 2004 Description Summary Page REJ05B0468-0100Z /Rev.1.
740 Family Programming Guide Keep safety first in your circuit designs! 1. Renesas Technology Corporation puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage.