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
}
}



















TIVA C GREEN LED TOGGLE

(TIVA C TM4C123GH6PMI) 


Dr. C. A. Hernandez-Gutierrez
--------------------------------------------------------------------------------------------------------------------------
This code simply initiates the F port and turns the green LED  on and off. Where the LED is connected to terminal 3 of port F or PF3.
Any question let me know.
If you want help with a project, a course or consultancy please contact me.
--------------------------------------------------------------------------------------------------------------------------

#define GPIO_PORTF_DATA_R       (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R        (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R      (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R        (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *)0x40025520))
#define GPIO_PORTF_CR_R         (*((volatile unsigned long *)0x40025524))
#define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))


void PortF_Init(void);


int main()

{
PortF_Init();

while(1)
{
GPIO_PORTF_DATA_R |= 0x08;
GPIO_PORTF_DATA_R &= ~0x08;
}
}


void PortF_Init(void){ 

volatile unsigned long delay;
  SYSCTL_RCGC2_R |= 0x00000020;     // 1) F clock
  delay = SYSCTL_RCGC2_R;           // delay   
  GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock PortF PF0  
  GPIO_PORTF_CR_R |= 0x1F;           // allow changes to PF4-0       
  GPIO_PORTF_AMSEL_R &= 0x00;        // 3) disable analog function
  GPIO_PORTF_PCTL_R &= 0x00000000;   // 4) GPIO clear bit PCTL  
  GPIO_PORTF_DIR_R &= ~0x11;          // 5.1) PF4,PF0 input, 
  GPIO_PORTF_DIR_R |= 0x08;          // 5.2) PF3 output  
  GPIO_PORTF_AFSEL_R &= 0x00;        // 6) no alternate function
  GPIO_PORTF_PUR_R |= 0x11;          // enable pullup resistors on PF4,PF0       
  GPIO_PORTF_DEN_R |= 0x1F;          // 7) enable digital pins PF4-PF0        
}




martes, 19 de diciembre de 2017


ARM Cortex M4 TIVAC 

Port initialization F 


--------------------------------------------------------------------------------------------------------------------------
In this post, we share the Code to initialize the F port of the ARM Cortex M4 TivaC123GH6PMI.

The first part is the define block which shows the address of each register such as GIPO-DATA.
The second one shows the function of initialization of the F port. Where the Switc1 and Switch 2 of the card are inputs, and the PF3 bit is an output connected to the green LED of the card.
Any questions you can ask on this blog.
For more information here we share a reference [1].
--------------------------------------------------------------------------------------------------------------------------

#define GPIO_PORTF_DATA_R   (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R        (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R      (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R        (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *)0x40025520))
#define GPIO_PORTF_CR_R         (*((volatile unsigned long *)0x40025524))
#define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))


void PortF_Init(void){ volatile unsigned long delay;

  SYSCTL_RCGC2_R |= 0x00000020;    // 1) F clock
  delay = SYSCTL_RCGC2_R;          // delay   
  GPIO_PORTF_LOCK_R = 0x4C4F434B;  // 2) unlock PortF PF0  
  GPIO_PORTF_CR_R |= 0x1F;          // allow changes to PF4-0       
  GPIO_PORTF_AMSEL_R &= 0x00;       // 3) disable analog function
  GPIO_PORTF_PCTL_R &= 0x00000000;  // 4) GPIO clear bit PCTL  
  GPIO_PORTF_DIR_R &= ~0x11;        // 5.1) PF4,PF0 input, 
  GPIO_PORTF_DIR_R |= 0x08;         // 5.2) PF3 output  
  GPIO_PORTF_AFSEL_R &= 0x00;       // 6) no alternate function
  GPIO_PORTF_PUR_R |= 0x11; //enable pullup resistors on PF4,PF0       
  GPIO_PORTF_DEN_R |= 0x1F;  // 7) enable digital pins PF4-PF0       
}



[1] Jonathan ValvanoEmbedded Systems: Introduction to ARM Cortex-M Microcontrollers



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...