main.c

来自「COP8 CPU的一个解释型BASIC源码」· C语言 代码 · 共 99 行

C
99
字号
////////////////////////////////////////////////////////////////
//
//                S C R I P T H E R M
//             A SCRIPTABLE THERMOMETER
// 
// entry of the National Semiconductor COP8FLASH Design Contest
//        submitted by Alberto Ricci Bitti (C) 2001
//              a.riccibitti@ra.nettuno.it
//
//--------------------------------------------------------------
//       FOR A BETTER VIEW SET TAB SIZE=4, INDENT SIZE=4
//--------------------------------------------------------------
// FILE   : main.c
// PURPOSE: the master module. Initializes the system
//          and runs the script interpreter. 
//          In case of errors, calls program() to 
//          invoke the editor
//
// IMPORTANT: use the linker file custom_LNK8LGL1.XCL
//
////////////////////////////////////////////////////////////////


#include <incop8.h> 
#include "types.h"
#include "lcd.h"
#include "timer_io_adc.h"
#include "serial.h"
#include "memory.h"
#include "edit.h"
#include "errors.h"
#include "tokenizer.h"
#include "variables.h"
#include "script.h"


jmp_buf  error_mark;
volatile flags_t  flags = {0,0,0,0,0};

// Invokes the editor. The program must be copied from FLASH to RAM
// prior to editor launch, and from RAM back to FLASH when the editor quits
// If the "debug" flag is set, the program is precompiled replacing 
// token strings with token codes
 
void program(void)
{	
    LCD_puts("\nPROGRAM ENDED");
    while (! flags.program)
    { /*loop intentionally void*/ };
    LCD_clear_text();  LCD_clear_graphics(); 

	if (flags.clear)   
	{   LCD_puts("Clearing...");      
	    clear_ram(); 
	    token_address = 0;
	} 
	else       
	{	LCD_puts("Loading...");
    	copy_flash_to_ram();
    };
	edit_program(token_address);
    LCD_clear_text();  LCD_puts("Saving...");
	copy_ram_to_flash();
	if (flags.debug)
	{   zip_tokens();
        LCD_puts("\nCompiling...");
        copy_ram_to_flash();
    };
   	prepare_to_run();
    LCD_clear_text();
}


__c_task main(void)
{
    
    com_initialize();
    LCD_initialize();
    LCD_locate(0,0);
    timer_io_adc_initialize();
    therm_initialize();
    __enable_interrupt();
	prepare_to_run();

    //setjmp entry point in case of errors

	if( error_occurred() ) flags.running = FALSE;

main_loop:

	if (! flags.running) program();
	if (flags.update_therm) therm_update();
	exec_command();
	goto main_loop;
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?