miércoles, 20 de diciembre de 2017





PORTA PA2 LED TOGGLE

(TIVA C TM4C123GH6PMI) 

--------------------------------------------------------------------

This program shows how to configure port A to handle an LED connected to terminal PA2.

Any question let me know.

If you want help with a project, a course or consultancy please contact me.

--------------------------------------------------------------------


#include "TM4C123.h"                    // Device header

#define SYSCTL_RCGC2_R   (*((volatile unsigned long *)0x400FE108))

#define GPIO_PORTA_PCTL_R (*((volatile unsigned long *)0x4000452C))
#define GPIO_PORTA_AMSEL_R (*((volatile unsigned long *)0x40004528))
#define GPIO_PORTA_DIR_R (*((volatile unsigned long *)0x40004400))
#define GPIO_PORTA_AFSEL_R (*((volatile unsigned long *)0x40004420))
#define GPIO_PORTA_DEN_R (*((volatile unsigned long *)0x4000451C))
#define GPIO_PORTA_DATA_R (*((volatile unsigned long *)0x400043FC))

void LED_Init(void){ 

  volatile unsigned long delay;
  SYSCTL_RCGC2_R |= 0x01;           // 1) activate clock for Port A
  delay = SYSCTL_RCGC2_R;           // allow time for clock to start
                                    // 2) no need to unlock PA2
  GPIO_PORTA_PCTL_R &= ~0x00000F00; // 3) regular GPIO
  GPIO_PORTA_AMSEL_R &= ~0x04;  // 4) disable analog function on PA2
  GPIO_PORTA_DIR_R |= 0x04;         // 5) set direction to output
  GPIO_PORTA_AFSEL_R &= ~0x04;      // 6) regular port function
  GPIO_PORTA_DEN_R |= 0x04;         // 7) enable digital port
}

int main()

{
LED_Init();

while(1)
{
GPIO_PORTA_DATA_R |= 0x04;    // PORT A2 ON
GPIO_PORTA_DATA_R &= ~0x04; // PORT A2 OFF
}
}

















No hay comentarios.:

Publicar un comentario

BTFSS INSTRUCTION  IN ASSEMBLER FOR PIC18F In this sample, we show that how to use a switch input to make an action. Remember that I...