STC 设置端口电平并编写驱动-流水灯(1)

#include <reg32.h>

sbit led = P1^0;   //set the port bit.

void main(void)

{

    led = 1;     //or led=0; set the port voltage_level

}

+----------------------------------------------------------------------------------------------------------------------------------------+

We can text wen led = 1, the port p10 set at hight voltage_leval;

If we want to delay it, make it output like the push-pull type;

we shoule add the delay function, Layout delay_function onto main_function,and able to run.

+-------------------------------------------------------------------------------------------------------------------------------------------------------------+

#define uint unsigned int   //difinition the uint type  typedef unsigned char uint;

void delay(uint num)

{

 uint i,j;

 for(x=num; i>0; i--)

  for(y=110; j>0; j--)

}

#=========================================================================================#

This is a floating_light program to apply the stc_bits_set and push-pul_type_output

#include <reg.h>

#define uchar unsigned char

#define uint unsigned int

#define port P1    //definition port

void delay(uint num)

{

  uint x,y;

  for(x=num; x>0; x--)

  for(y=110; y>0; y++);

}

void main(void)

{

    uchar num2,mid_num;

    while(1)

    {

       port  = 0xfe;

delay(500);

       mid_num = 0xfe;

       for(num2=7; num2>0; num2--)

       {

mid_num = mid_num << 1 | 0x01;
PORT = mid_num;
delay(500);

}

    }

}

 

posted @ 2019-03-23 19:23  rollingball  阅读(481)  评论(0)    收藏  举报