提问:帮我写一个Nuvoton M051的点灯程序。
GPT:
#include <stdio.h>
#include <NuvotonM051.h>
//定义端口
#define LED_PORT P2
//定义灯的状态
#define LED_ON 0
#define LED_OFF 1
//定义灯的状态
#define LED1 0
#define LED2 1
#define LED3 2
#define LED4 3
//定义灯的控制函数
void LED_Control(unsigned char led,unsigned char status)
{
switch(led)
{
case LED1:
if(status == LED_ON)
LED_PORT |= (1<<0);
else
LED_PORT &= ~(1<<0);
break;
case LED2:
if(status == LED_ON)
LED_PORT |= (1<<1);
else
LED_PORT &= ~(1<<1);
break;
case LED3:
if(status == LED_ON)
LED_PORT |= (1<<2);
else
LED_PORT &= ~(1<<2);
break;
case LED4:
if(status == LED_ON)
LED_PORT |= (1<<3);
else
LED_PORT &= ~(1<<3);
break;
default:
break;
}
}
//点灯程序
void LED_Blink(void)
{
unsigned char i;
while(1)
{
for(i=0;i<4;i++)
{
LED_Control(i,LED_ON);
delay(1000);
LED_Control(i,LED_OFF);
}
}
}
//主函数
int main(void)
{
LED_Blink();
return 0;
}
|