示例代码 Code

延时

    void delay( unsigned int duration )
    {
        unsigned int i;
        unsigned char j;
        for( i = 0; i < duration; i++ )
        {
            for( j = 0; j < 200; j++ )
            {
                asm( "NOP" );
                asm( "NOP" );
                asm( "NOP" );
            }
        }
    }
                

    void delay( unsigned int duration )
    {
        unsigned int i, j;
        for( i = 0; i < duration; i++ )
            for( j = 0; j < 200; j++ );
    }
移位

    //定义:BV - bit move
    #define BV(n) (1<<(n))
    //使用:置1
    P0DIR |= BV( 0 );
    //使用:置0
    P0SEL &= ~BV( 0 );