#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
#include "xbasic_types.h"
#include "xstatus.h"
#include "xgpio.h"
//====================================================
#define LED_DELAY 1000000
#define LED_CHANNEL 1
#define LED_MAX_BLINK 0x1 /* Number of times the LED Blinks */
#define LED_8Bits_GPIO_d_out_pin 0x81400000
u16 style4[6]={0x81,0x42,0x24,0x18,0x24,0x42};
u16 style5[6]={0x81,0xc3,0xe7,0xff,0xe7,0xc3};
XStatus GpioOutputExample(Xuint16 DeviceId, Xuint32 GpioWidth)
{
volatile int Delay;
Xuint32 LedBit,LedLoop,mask;
XStatus Status;
XGpio GpioOutput;
Status = XGpio_Initialize(&GpioOutput, DeviceId);
if (Status != XST_SUCCESS)
{
return XST_FAILURE;
}
XGpio_SetDataDirection(&GpioOutput, LED_CHANNEL, 0x0);
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x0);
/***********方式一 依次闪烁 ********************/
/* for (LedBit = 0x0; LedBit < GpioWidth-1; LedBit++)
{
for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++)
{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 1 << LedBit);
for (Delay = 0; Delay < LED_DELAY; Delay++);
XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL, 1 << LedBit);
for (Delay = 0; Delay < LED_DELAY; Delay++);
}
}
for (LedBit = 0x0; LedBit < GpioWidth-1; LedBit++)
{
for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++)
{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x80 >> LedBit);
for (Delay = 0; Delay < LED_DELAY; Delay++);
XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL, 0x80 >> LedBit);
for (Delay = 0; Delay < LED_DELAY; Delay++);
}
}
/***********方式二 依次熄灭 然后点亮********************/
/*
mask=0x01;
for (LedBit = 0x0; LedBit < GpioWidth; LedBit++)
{
//for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++)
//{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, mask);
for (Delay = 0; Delay < LED_DELAY; Delay++);
// XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL, 0x80 >> LedBit);
for (Delay = 0; Delay < LED_DELAY; Delay++);
mask=(mask << 1)+0x01;
//}
}
mask=0xff;
for (LedBit = 0x0; LedBit < GpioWidth; LedBit++)
{
//for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop++)
//{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, mask);
for (Delay = 0; Delay < LED_DELAY; Delay++);
// XGpio_DiscreteClear(&GpioOutput, LED_CHANNEL, mask);
for (Delay = 0; Delay < LED_DELAY; Delay++);
mask=mask >> 1;
// }
}
*/
/***********方式三 交替闪烁********************/
/* XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0x55);
for (Delay = 0; Delay < 2*LED_DELAY; Delay++);
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, 0xaa);
for (Delay = 0; Delay < 2*LED_DELAY; Delay++);
*/
/***********方式四********************/
/* u16 i;
for(i=0;i<=5;i++)
{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, ~style4);
for (Delay = 0; Delay < 2*LED_DELAY; Delay++);
}
*/
/***********方式五********************/
u16 i;
for(i=0;i<=5;i++)
{
XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, ~style5);
for (Delay = 0; Delay < 2*LED_DELAY; Delay++);
}
return XST_SUCCESS;
}
int main (void) {
XStatus status;
while(1)
{
print("\r\nRunning GpioOutputExample() for LEDs_8Bit...\r\n");
status = GpioOutputExample(LED_8Bits_GPIO_d_out_pin,8);
if (status == 0) {
xil_printf("GpioOutputExample PASSED.\r\n");
}
else {
print("GpioOutputExample FAILED.\r\n");
}
}
return 0;
}
文章评论(0条评论)
登录后参与讨论