t3_ledio.c

来自「intel 196nt 例程」· C语言 代码 · 共 55 行

C
55
字号
/*
** t3_ledio.c
*/

#include        <stdio.h>
#include        <stdlib.h>
#include        _SFR_H_

/* IMPORT functions */
extern void     wait_ms( int );

/* LOCAL functions */
static  void            enable_led( void );
static  void            set_led( unsigned char );

/* LOCAL data */
static const unsigned char      patterns[] =
{
        /* OK kid, pick me up at the frontdoor. */
        0x01, 0x03, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xC0,
        0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0x0E, 0x07, 0x03
};

void main(void)
{
    unsigned int        i;
    int                 j;

    set_led( 0 );               /* Clear the LEDs before enabling. */
    enable_led();

    while ( 1 )
    for ( j = 0; j < sizeof( patterns); j++ )
    {
        set_led( patterns[j] );
        wait_ms( 100 );
    }
}

/* LED I/O is connect to Port 1 */
static void enable_led( void )
{
    /* Set all pins of port1 to open-drain output (external pull-up). */
    asm stb     0,p1_dir;
}

static void set_led( register unsigned char b )
{
    /* Each bit is a LED in the LED array. */
    /* Note that there are ten LEDs,
       one is unused,
       one is for power-on indication. */
    asm stb     b,p1_reg;
}

⌨️ 快捷键说明

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