?? pascal.c
字號:
/****************************************************************
*
* ARM Strategic Support Group
*
****************************************************************/
/****************************************************************
*
* Module : pascal.c
* Description : Writes out a Pascal's triangle using
* semi-hosting and non-embedded libraries.
* This program is used as a basic confidence
* test for the board.
* Platform : Evaluator7T
* Tool Chain : ARM Developer Suite 1.0
* Status : Complete
* History :
*
* 980504 Andrew N. Sloss
* - create for AEB-1
*
* 990422 Andrew N. Sloss
* - ported to Evaluator7T
*
* Notes :
*
* Limited to a depth of 6, since the
* output routines only work with single
* digit numbers...
*
****************************************************************/
/****************************************************************
* IMPORT
****************************************************************/
#include <stdio.h>
#include "led.h"
/****************************************************************
* MACROS
****************************************************************/
// none...
/****************************************************************
* DATATYPES
****************************************************************/
// none...
/****************************************************************
* ROUTINES
****************************************************************/
/* -- pascal_generator ------------------------------------------
*
* Description : Generates the PASCAL triangle numbers
* Tool Chain : ADS 1.0
* Parameters : int n - level
* int i - row
* Return : int - calculated PASCAL triangle number...
* Notes : A recursive function. Note recursive functions
* are dangerous in embedded systems, which
* require deterministic stack...
*
*/
int pascal_generator (int n, int i)
{
LED_2_OFF;
LED_2_ON;
if (i == 1 || i == n) return 1;
return pascal_generator(n-1,i-1) + pascal_generator(n-1,i);
}
/* -- pascal_triangle ------------------------------------------
*
* Descriptions : Builds the complete PASCAL's triangle.
*
* Parameters : int d - depth
* Return : none...
* Notes :
*
*/
void pascal_triangle (int depth)
{
int i,j,s;
LED_3_OFF;
for (j = 1; j < depth; j++) {
printf("\n\t\t");
for ( s = depth-j; s > 0; s-- ) {
putchar (' ');
}
for (i = 1; i <= j; i++) {
printf("%d ", pascal_generator(j, i));
}
}
putchar ('\n');
LED_3_ON;
}
/* -- pascal_init ----------------------------------------------
*
* Description : initialize the LED on the Evaluator7T board
*
* Parameters : none...
* Return : none...
* Notes : none...
*
*/
void pascal_init (void)
{
LED_1_OFF;
LED_2_ON;
LED_3_ON;
LED_4_ON;
}
/* -- main -----------------------------------------------------
*
* Description : entry point
*
* Parameters : none...
* Return : int
* Notes : none...
*
*/
int main (void)
{
printf( "hello, liming! " );
//return 1;
// pascal_init();
// LED_4_OFF;
// printf ("\n\t*** Pascal's Triangle *** \n\n");
// pascal_triangle (6);
LED_4_ON;
// printf ("\n");
// printf ("**************************************************\n");
// printf ("** NOTE: Reset the Board and Close the Debugger **\n");
// printf ("**************************************************\n");
return 1;
}
/****************************************************************
* End of Pascal.c
****************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -