第 3.51 節

51 microcontroller (just need to understand it)

0瀏覽次數0訪問次數--跳出率--平均停留

Using the STC89C52 as an example

Turn on a light.

#include "reg51.h"

void main ()
{
        P2 = 0xFE;// 等同于  P2 = 0b   1111 1110;

        while (true)
        {

        }
}

Delay function definition

//固定延时函数
void Delay500ms()                //@12.000MHz
{
        unsigned char i, j, k;

        _nop_();
        i = 4;
        j = 205;
        k = 187;
        do
        {
                do
                {
                        while (--k);
                } while (--j);
        } while (--i);
}

Make the light blink.


#include "reg51.h"
void Delay500ms()                //@12.000MHz
{
        unsigned char i, j, k;

        _nop_();
        i = 4;
        j = 205;
        k = 187;
        do
        {
                do
                {
                        while (--k);
                } while (--j);
        } while (--i);
}

void main ()
{

        while (1)
        {
                P2 = 0xFE;
                Delay500ms();
                P2 = 0xFF;
                Delay500ms();
        }
}
音乐页