📄 main.c
字号:
/**************** (c) 1998 SGS-Thomson Microelectronics **********************
PROJECT : ST72101
COMPILER : ST7 HICROSS C (HIWARE)
MODULE : main.c
VERSION : V 2.0
CREATION DATE : 03/07/98
AUTHOR : PPG 8-bit Micro Application team
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
DESCRIPTION : Main Routine
Example of how to use the HIWARE tool chain
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MODIFICATIONS :
******************************************************************************/
// Include files
#include "hidef.h" // Hiware library.
#include "map72101.h" // ST72101 memory and registers mapping
#include "lib_bits.h" // Predifined libraries working at bit level
#include "variable.h" // Define your global variables here
#include "init.h" // ST72101 initialization routine for the application
#include "function.h" // All functions used in the application can be defined
// here for a good project management.
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
void main(void)
{
char var; // Example of how to declare local variables
char i,j; // All variables are defined as char or unsigned
char ram_array[10]; // char for a Byte coding.
Init_Ports(); // Call to the Init_Ports subroutine declared in
// init.h file.
Gen_PWM(); // Call the routine which generates a PWM signal
// Subroutines declared in the function.c.
// The output signal can be visualized on PB1 pin.
while(1) // never ending loop. (<=> jra assembler instruction)
{
i=j=0;
var= addition(data1,data2); // var will be the result of the addition's subroutine
// declared in the function.h file
data3 = var; // store returned value in memory (ram).
if (!ValBit(data3,ZERO)) // example of how to use the lib_bits library.
{ // One test bit 0 of data3 and branch according to
// the if condition
ramloc3 = data2;
PADR = ONE;
}
else
{
ramloc2 = data2;
PADR = ZERO;
}
data1 = data1 + 1; // increment data1 value
while (i!=10) // Example of a while instruction
{
ram_array[i] = table[i];// copy of a rom array declared in variable.h file
// into a ram array. A direct indexed addressing mode
i = i+1; // is used.
}
for (j=0;j<10;j++) // you can also use the for condition. However, using
{ // ST7 decoder, you can see the assembler code generated
ram_array[j] = table[j];// an compare the two instructions.
} // In this case, the code generated is more optimized
// for the while loop.
asm // You can also insert assembler code in your C program.
{
nop // No instruction is performed but a machine cycle is lost.
} // in the main program.
} // while(1) loop
} // main loop
/*** (c) 1998 SGS-Thomson Microelectronics ****************** END OF FILE ***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -