サンプルプログラム

(Mini-c マルチタスク化)

 SIOの”B”Chで受信したデータをLCDデスプレイで表示するのと、 I/Oポートからパルスが出力します。それらが、独立したタスクで実行し ています。

目次に戻る


#include	"aki80.h"
#include	"mt_sys.h"
#include	"mt_cont.h"
#include	"lcd_drv.h"
#include	"sio_drv.h"
#include	"stdio.h"
#include	"stdlib.h"


void task_init( )
{
    int  i;

    set_task_st(0,ACTIVE);
    set_task_st(1,ACTIVE);
    set_task_st(2,ACTIVE);
    set_task_st(3,ACTIVE);
    set_task_st(4,ACTIVE);
    set_task_st(5,ACTIVE);
    set_task_st(6,ACTIVE);
    set_task_st(7,ACTIVE);

    sio_b_init(SP_9600,DT_8,ST_1,PR_N);
    lcd_reset( 2 );
    lcd_clear( );
    display_on( );

    lcd_str_dsp("  ***  test_Vr1.00 ***");
    for( i=0; i<=6; i++){
	wait_05s( );
    }
    lcd_clear( );
    cursor_brnk_on( );
    out(IO_PPI_CT,0x0080);
    out(IO_PIO_AC,0x000f);
    out(IO_PIO_BC,0x000f);
}
void task_0( )
{
    int	a,b,c;

    while(1){
	a = sio_b_rx_check( );
	if(a == 1) {
	    b = sio_b_getchar( );
	    while(1){
		c = commu_write(0,b);
		if(c == 1) break;
	    }
	    while(1){
		c = sio_b_putchar(b);
		if(c == 1) break;
	    }
	}
    }
}

void task_1( )
{
    int	a;

    while(1){
	while(1){
	    a = commu_flag(0);
	    if(a == 1) break;
	}
	a = commu_read(0);
	put_lcd(a);
    }
}

void task_2( )
{
    int a,b,c;

    c = 0;
    a = task_cc_read( );
    out(IO_PPI_AD,0x0055);

    while(1){
	b = task_cc_read( );
	if(a != b) {
	    a = b;
	    if(c == 0){
		c = 1;
		out(IO_PPI_AD,0x00aa);
	    }
	    else {
		c = 0;
		out(IO_PPI_AD,0x0055);
	    }
	}
    }
}

void task_3( )
{
    int a,b,c;

    c = 0;
    a = task_cc_read( );
    out(IO_PPI_BD,0x0055);

    while(1){
	b = task_cc_read( );
	if(a != b) {
	    a = b;
	    if(c == 0){
		c = 1;
		out(IO_PPI_BD,0x00aa);
	    }
	    else {
		c = 0;
		out(IO_PPI_BD,0x0055);
	    }
	}
    }
}

void task_4( )
{
    int a,b,c;

    c = 0;
    a = task_cc_read( );
    out(IO_PPI_CD,0x0055);

    while(1){
	b = task_cc_read( );
	if(a != b) {
	    a = b;
	    if(c == 0){
		c = 1;
		out(IO_PPI_CD,0x00aa);
	    }
	    else {
		c = 0;
		out(IO_PPI_CD,0x0055);
	    }
	}
    }
}

void task_5( )
{

    out(IO_PIO_AD,0x0055);
    out(IO_PIO_AD,0x00aa);

}

void task_6( )
{
    int a,b,c;

    c = 0;
    a = task_cc_read( );
    out(IO_PIO_BD,0x0055);

    while(1){
	b = task_cc_read( );
	if(a != b) {
	    a = b;
	    if(c == 0){
		c = 1;
		out(IO_PIO_BD,0x00aa);
	    }
	    else {
		c = 0;
		out(IO_PIO_BD,0x0055);
	    }
	}
    }
}

void task_7( )
{
    int	a;

    a = 't';
    put_lcd(a);
    a = 'a';
    put_lcd(a);
    a = 's';
    put_lcd(a);
    a = 'k';
    put_lcd(a);
    a = '7';
    put_lcd(a);
}

#include	"mt_stak.h"




目次に戻る