Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.c for HW6a, EE319K
- // Runs on LM4F120/TM4C123
- // In this lab we are learning functional debugging by dumping
- // recorded I/O data into a buffer
- // Daniel Valvano, Jonathan Valvano and Ramesh Yerraballi
- // October 4, 2017
- //***make sure edXLab9.dll is in Keil\ARM\bin ****
- /* This example accompanies the books
- "Embedded Systems: Introduction to ARM Cortex M Microcontrollers",
- ISBN: 978-1469998749, Jonathan Valvano, copyright (c) 2017
- "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers",
- ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2017
- Copyright 2017 by Jonathan W. Valvano, valvano@mail.utexas.edu
- You may use, edit, run or distribute this file
- as long as the above copyright notice remains
- THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
- OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
- VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
- OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
- For more information about my classes, my research, and my books, see
- http://users.ece.utexas.edu/~valvano/
- */
- /* If either the PF4 or the PF0 switch is not pressed, the PF1 output does not change.
- If both PF4 and PF0 switches are pressed, the red LED toggles at 10 Hz (±1%).
- Information collected in the Data array matches the I/O on PortF.
- 50 data points are collected only on a change in input or a change in output.
- */
- #include "TExaS.h"
- // LaunchPad built-in hardware
- // SW1 left switch is negative logic PF4 on the Launchpad
- // SW2 right switch is negative logic PF0 on the Launchpad
- // red LED connected to PF1 on the Launchpad
- // blue LED connected to PF2 on the Launchpad
- // green LED connected to PF3 on the Launchpad
- void EnableInterrupts(void);
- void DebugDump(void);
- #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 GPIO_LOCK_KEY 0x4C4F434B // Unlocks the GPIO_CR register
- #define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
- #define PF1 (*((volatile unsigned long *)0x40025008))
- #define SW (*((volatile unsigned long *)0x40025044))
- int i = 0;
- int j = 0;
- void PortF_Init(void){ volatile unsigned long delay;
- SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
- delay = SYSCTL_RCGC2_R; // allow time for clock to start
- GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F
- GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0
- // only PF0 needs to be unlocked, other bits can't be locked
- GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF
- GPIO_PORTF_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0
- GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 in, PF3-1 out
- GPIO_PORTF_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0
- GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4
- GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital I/O on PF4-0
- }
- unsigned long Led;
- void Delay(void){unsigned long volatile time;
- time = 80382; // 0.05sec, empirically calculated
- while(time){
- time--;
- }
- }
- unsigned long Data[50];
- // you must leave the Data array defined exactly as it is
- void DebugDump(void){
- if(((GPIO_PORTF_DATA_R & 0x13) != 0x13) && (i==0)){
- Data[i] = GPIO_PORTF_DATA_R & 0x13;
- i++;
- }
- else if(((GPIO_PORTF_DATA_R & 0x13) != 0x13) && ((GPIO_PORTF_DATA_R & 0x13) != Data[i-1]) && (i<50)){
- Data[i] = GPIO_PORTF_DATA_R & 0x13;
- i++;
- }
- }
- int main(void){
- TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and leave system clock at 16 MHz
- PortF_Init(); // initialize PF1 to output, PF4,0 to input
- //--UUU-- add your initialization here
- for(j = 0; j <50; j++){
- Data[j] = 0xFFFFFFFF;
- }
- // end of your dump initialization
- EnableInterrupts(); // enable interrupts for the grader
- while(1){
- if(SW == 0x11){
- PF1 = 0;
- }else{
- PF1 ^= 0x02;
- }
- // --UUU-- add a debugging dump here
- // store in Data buffer if Port F bits 4,1 or 0 are different
- DebugDump();
- // end of your dump
- Delay();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement