选用P1口作为输出口,接8只发光二极管,编程实现使8个发光二极管每隔200ms循环依次左移点亮.

2024-11-14 12:18:53
推荐回答(1个)
回答1:

#include
#define LED P1 //宏定义,使用LED代替P1口(相当于LED=P1)
#define uchar unsigned char //用uchar代替unsigned char方便操作
#define uint unsigned int
/*------------------time ms延时函数-----------------*/
void delay_ms(uint time)
{
uchar tres;
for(;time>0;time--)
{
tres=;
while(tres--);

}
void in()
{
uchar t;
LED=0X01;//P1=B
while(1)//ˀѭ»·,²»ͣµĵぁº͏¨ðLED
{
for(t=0;t