source: Documentation/Tutorials/XPS_Intro/code/UserIO_Demo_v1.c

Last change on this file was 1591, checked in by sgupta, 14 years ago

fixed bug in tutorial code

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#include "xgpio.h"
2#include "warp_userio_v1.h"
3#include "xparameters.h"
4
5//Shortcuts for constants in xparameters.h
6#define USERIO_DEVICE_ID    XPAR_USER_IO_DEVICE_ID
7
8//Instances of the GPIO and Intc drivers
9static XGpio GPIO_UserIO;
10
11//Global variable for tracking active LED outputs
12static unsigned int LED_Outputs = 0;
13
14//Function prototypes
15unsigned char sevenSegmentMap(unsigned char x);
16
17int main(void)
18{
19    XStatus Status;
20    unsigned char ledDisp = 0;
21   
22    //Initialize the UserIO GPIO core
23    Status = XGpio_Initialize(&GPIO_UserIO, USERIO_DEVICE_ID);
24
25    //We use both channels in the GPIO core- one for inputs, one for outputs
26    XGpio_SetDataDirection(&GPIO_UserIO, USERIO_CHAN_INPUTS, USERIO_MASK_INPUTS);
27    XGpio_SetDataDirection(&GPIO_UserIO, USERIO_CHAN_OUTPUTS, 0);
28
29    //Make sure the LEDs are all off by default
30    XGpio_DiscreteClear(&GPIO_UserIO, USERIO_CHAN_OUTPUTS, USERIO_MASK_OUTPUTS);
31
32    while(1)
33    {
34        xil_printf("Displaying: %x\r\n", ledDisp);
35
36        //Update the global variable we use to track which LED/segments are currently lit
37        // The xps_gpio core doesn't allow outputs to be read from code, so we have to track this internally
38        LED_Outputs = (USERIO_MAP_LEDS(ledDisp) | USERIO_MAP_DISPR(ledDisp) | USERIO_MAP_DISPL(ledDisp));
39       
40        //Set the LEDs & hex displays
41        XGpio_DiscreteSet(&GPIO_UserIO, USERIO_CHAN_OUTPUTS, LED_Outputs);
42
43        usleep(600000);
44
45        //Cycle the displays through [0x0,0xF]
46        if(ledDisp == 15)
47            ledDisp = 0;
48        else
49            ledDisp++;
50    }
51   
52    return 0;
53
54}
55
56unsigned char sevenSegmentMap(unsigned char x)
57{
58    switch(x)
59    {
60        case(0x0) : return 0x007E;
61        case(0x1) : return 0x0030;
62        case(0x2) : return 0x006D;
63        case(0x3) : return 0x0079;
64        case(0x4) : return 0x0033;
65        case(0x5) : return 0x005B;
66        case(0x6) : return 0x005F;
67        case(0x7) : return 0x0070;
68        case(0x8) : return 0x007F;
69        case(0x9) : return 0x007B;
70
71        case(0xA) : return 0x0077;
72        case(0xB) : return 0x007F;
73        case(0xC) : return 0x004E;
74        case(0xD) : return 0x007E;
75        case(0xE) : return 0x004F;
76        case(0xF) : return 0x0047;
77        default : return 0x0000;
78    }
79}
Note: See TracBrowser for help on using the repository browser.