Lab 6, Shape the World

En el Lab6 nos piden prender el Led Azul desde la configuración del PORTF. Dentro del main debemos chequear el estado del Sw1, si esta presionado, el Led Azul debe flashear, si no esta presionado el Led debe quedarse encendido.

Configuracion del PORTF
void PORTF_Init (void){ volatile unsigned long delay;
 
 SYSCTL_RCGC2_R |= 0x20;          //Enable PORTF clock
 delay = SYSCTL_RCGC2_R;    
 GPIO_PORTF_AMSEL_R &= (~0x14);   //Clear PF4 and PF2 on AMSEL
 GPIO_PORTF_PCTL_R &= (~0x14);    //Clear PF4 and PF2 on PCTL
 GPIO_PORTF_DIR_R &= (~0x10);     //Set PF4 as input, PF2 as output
 GPIO_PORTF_DIR_R |= 0x04;     
 GPIO_PORTF_AFSEL_R &= (~0x14);   //Clear PF4 and PF2 on AFSEL
 GPIO_PORTF_DEN_R |= 0x14;        //Set PF4 and PF2 on DEN
 GPIO_PORTF_PUR_R |= 0x14;        //Set PF4 and PF2 on PUR
 GPIO_PORTF_DATA_R |= 0x04;       //Set PF2 in DATA so the LED is initially ON
}

Solución al Lab6 del curso Shape the World de T.I.

// BranchingFunctionsDelays.c Lab 6
// Runs on LM4F120/TM4C123
// Use simple programming structures in C to 
// toggle an LED while a button is pressed and 
// turn the LED on when the button is released.  
// This lab will use the hardware already built into the LaunchPad.
// Daniel Valvano, Jonathan Valvano
// January 8, 2014

// built-in connection: PF0 connected to negative logic momentary switch, SW2
// built-in connection: PF1 connected to red LED
// built-in connection: PF2 connected to blue LED
// built-in connection: PF3 connected to green LED
// built-in connection: PF4 connected to negative logic momentary switch, SW1

#include "TExaS.h"

#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_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF      0x00000020  // port F Clock Gating Control

#define PF2           (*((volatile unsigned long *)0x40025010))

// basic functions defined at end of startup.s
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void);  // Enable interrupts

unsigned long In;

void PORTF_Init (void);
void Delay100ms(unsigned long time);

int main(void){ unsigned long volatile delay;
  TExaS_Init(SW_PIN_PF4, LED_PIN_PF2);  // activate grader and set system clock to 80 MHz
  // initialization goes here
 PORTF_Init();

  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    // body goes here
  Delay100ms(1);
  In = GPIO_PORTF_DATA_R&0x10;   // read PF4 into Sw1
         
   if (In == 0){
    GPIO_PORTF_DATA_R ^= 0x04;
   } else {
    GPIO_PORTF_DATA_R |= 0x04;
   }
  }
}

void PORTF_Init (void){ volatile unsigned long delay;
 
 SYSCTL_RCGC2_R |= 0x20;          //Enable PORTF clock
 delay = SYSCTL_RCGC2_R;    
 GPIO_PORTF_AMSEL_R &= (~0x14);   //Clear PF4 and PF2 on AMSEL
 GPIO_PORTF_PCTL_R &= (~0x14);    //Clear PF4 and PF2 on PCTL
 GPIO_PORTF_DIR_R &= (~0x10);     //Set PF4 as input, PF2 as output
 GPIO_PORTF_DIR_R |= 0x04;     
 GPIO_PORTF_AFSEL_R &= (~0x14);   //Clear PF4 and PF2 on AFSEL
 GPIO_PORTF_DEN_R |= 0x14;        //Set PF4 and PF2 on DEN
 GPIO_PORTF_PUR_R |= 0x14;        //Set PF4 and PF2 on PUR
 GPIO_PORTF_DATA_R |= 0x04;       //Set PF2 in DATA so the LED is initially ON
}

void Delay100ms(unsigned long time){
 unsigned long i;
 while(time > 0){
  i=1333333;
   while(i > 0){
    i = i - 1;
   }
  time = time - 1;
 }
}


No tengo la board para checarlo en hardware, en el osciloscopio del debugger funciono muy bien.

Comentarios

Entradas más populares de este blog

PSoC Creator Tools

sprintf en PSoC Creator 3.0 y 3.1