Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.32 KB | None | 0 0
  1. /*
  2.  *
  3.  * Toggles led on pin 1 on port N
  4.  *
  5.  * Already set build options (no need to change anything):
  6.  * Stack size set to 1024 byte
  7.  * Heap size disabled - No malloc()
  8.  * No code optimization
  9.  * Strict floating point interrupt behaviour
  10.  * Hardware floating point unit activated
  11.  *
  12.  */
  13.  
  14. #include <stdbool.h> /*driverlib header requires stdbool.h to be included a first header file before any driverlib header*/
  15. #include <stdint.h>
  16. #include <driverlib/gpio.h>
  17. #include <driverlib/pin_map.h>/*supplies GPIO_PIN_x*/
  18. #include <driverlib/sysctl.h>
  19. #include <inc/hw_memmap.h>/*supplies GPIO_PORTx_BASE*/
  20.  
  21. /*Controller is initially clocked with 16MHz*/
  22. /* !! Changing this define does not change clock speed !! */
  23. #define F_CPU 16000000
  24.  
  25. void main (void) {
  26.  
  27.     uint32_t ui32Strength;
  28.     uint32_t ui32PinType;
  29.     uint8_t ui8val = 0;
  30.     uint32_t ui32Loop = 0;
  31.  
  32.  
  33.     /*activate gpio port n for d1 - d2*/
  34.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
  35.     /* activate gpio port f for d3 - d4 */
  36.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  37.     /* activate gpio port j for button */
  38.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
  39.  
  40.     /*configure GPIO_PIN_1 on port N as std pin D1*/
  41.     GPIOPadConfigGet(GPIO_PORTN_BASE, GPIO_PIN_1, &ui32Strength, &ui32PinType);
  42.     GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_1,ui32Strength,GPIO_PIN_TYPE_STD);
  43.  
  44.     /*configure GPIO_PIN_1 on port N as std pin D2*/
  45.     GPIOPadConfigGet(GPIO_PORTN_BASE, GPIO_PIN_0, &ui32Strength, &ui32PinType);
  46.     GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_0,ui32Strength,GPIO_PIN_TYPE_STD);
  47.  
  48.     /*configure GPIO_PIN_1 on port N as std pin D3*/
  49.     GPIOPadConfigGet(GPIO_PORTF_AHB_BASE, GPIO_PIN_4, &ui32Strength, &ui32PinType);
  50.     GPIOPadConfigSet(GPIO_PORTF_AHB_BASE, GPIO_PIN_4,ui32Strength,GPIO_PIN_TYPE_STD);
  51.  
  52.  
  53.     /*configure GPIO_PIN_1 on port N as std pin D4*/
  54.     GPIOPadConfigGet(GPIO_PORTF_AHB_BASE, GPIO_PIN_0, &ui32Strength, &ui32PinType);
  55.     GPIOPadConfigSet(GPIO_PORTF_AHB_BASE, GPIO_PIN_0,ui32Strength,GPIO_PIN_TYPE_STD);
  56.  
  57.     /* configure GPIO_PIN_0 on port J as button */
  58.     GPIOPadConfigGet(GPIO_PORTJ_BASE, GPIO_PIN_0, &ui32Strength, &ui32PinType);
  59.     GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0,ui32Strength,GPIO_PIN_TYPE_STD_WPU);
  60.  
  61.     /*set pin 1 of gpio port n to output*/
  62.     //GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE,GPIO_PIN_0);
  63.     GPIOPinWrite (GPIO_PORTJ_BASE, GPIO_PIN_0, 0x00000000);
  64.  
  65.     /* set pin 0 of gpio port j because button */
  66.     //GPIOPinTypeGPIOOutput(GPIO_PORTJ_AHB_BASE,GPIO_PIN_0);
  67.  
  68.     for(;;) {
  69.         if(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_0) == 1) {
  70.                 GPIOPinTypeGPIOOutput(GPIO_PORTF_AHB_BASE,GPIO_PIN_4);
  71.                 GPIOPinWrite(GPIO_PORTF_AHB_BASE, GPIO_PIN_4, 0x00000010);
  72.         }
  73.         //for(ui32Loop = 0; ui32Loop < 400000; ui32Loop++){}
  74.     }
  75.  
  76.     //GPIO_PORTF_AHB_BASE = GPIO_PORTJ_AHB_BASE;
  77.  
  78.     //Digital Enable for PortJ USR Switch1
  79.         //GPIO_PORTJ_AHB_DEN_R = 0x01;
  80.  
  81.         //Enable Pull Up for PortJ USR Switch1
  82.         //GPIO_PORTJ_AHB_PUR_R = 0x01;
  83.  
  84.     //for(;;) {
  85.       //  ui8val = ui8val ^ 2;/*toggle bit 1 in variable val*/
  86.         /*write value of val to pin 1 of port n*/
  87.         //GPIOPinWrite (GPIO_PORTF_AHB_BASE, GPIO_PIN_0, ui8val);
  88.         // for(ui32Loop = 0; ui32Loop < 400000; ui32Loop++){}
  89.        // SysCtlDelay(F_CPU/6);  //approx 0,5 s
  90.  
  91.     //}
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement