Commit 3ca637f2 by Víctor Elexpe

Merge branch 'master' of gitlab.pld.ttu.ee:vielex/bes_labs_2019

parents 65fba1fc f634a51d
// ***** 0. Documentation Section *****
// SwitchLEDInterface.c for Lab 8
// 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 requires external hardware
// to be wired to the LaunchPad using the prototyping board.
// January 15, 2016
// Jon Valvano and Ramesh Yerraballi
// ***** 1. Pre-processor Directives Section *****
#include "TExaS.h"
#include "tm4c123gh6pm.h"
#define GPIO_PORTE_DATA_R (*((volatile unsigned long *)0x400243FC))
#define GPIO_PORTE_DIR_R (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_PUR_R (*((volatile unsigned long *)0x40024510))
#define GPIO_PORTE_DEN_R (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_LOCK_R (*((volatile unsigned long *)0x40024520))
#define GPIO_PORTE_CR_R (*((volatile unsigned long *)0x40024524))
#define GPIO_PORTE_AMSEL_R (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R (*((volatile unsigned long *)0x4002452C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
// ***** 2. Global Declarations Section *****
unsigned long SW4;
unsigned long Out;
// FUNCTION PROTOTYPES: Each subroutine defined
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void PortE_init(void); // Init port PE0 PE1
void Delay1ms(unsigned long msec);
// ***** 3. Subroutines Section *****
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
int main(void) {
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
TExaS_Init(SW_PIN_PE0, LED_PIN_PE1, ScopeOn); // activate grader and set system clock to 80 MHz
PortE_init();
EnableInterrupts(); // enable interrupts for the grader
while(1){
SW4 = GPIO_PORTE_DATA_R&0x00;
if (SW4) {
GPIO_PORTE_DATA_R = 0x02;
}
Delay1ms(100);
}
}
void PortE_init() { volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) F clock
delay = SYSCTL_RCGC2_R; // delay to allow clock to stabilize
GPIO_PORTE_AMSEL_R &= 0x00; // 2) disable analog function
GPIO_PORTE_PCTL_R &= 0x00000000; // 3) GPIO clear bit PCTL
GPIO_PORTE_DIR_R &= ~0x00; // 4.1) PF0 input,
GPIO_PORTE_DIR_R |= 0x01; // 4.2) PF1 output
GPIO_PORTE_AFSEL_R &= 0x00; // 5) no alternate function
GPIO_PORTE_PUR_R |= 0x10; // 6) enable pullup resistor on PF4
GPIO_PORTE_DEN_R |= 0x11; // 7) enable digital pins PF1-PF0
}
void Delay1ms(unsigned long msec) {
unsigned long count;
while(msec > 0) {
count = 1600;
while(count > 0) {
count--;
}
ms--;
}
}
\ No newline at end of file
// ***** 0. Documentation Section *****
// SwitchLEDInterface.c for Lab 8
// 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 requires external hardware
// to be wired to the LaunchPad using the prototyping board.
// January 15, 2016
// Jon Valvano and Ramesh Yerraballi
// ***** 1. Pre-processor Directives Section *****
#include "TExaS.h"
#include "tm4c123gh6pm.h"
// ***** 2. Global Declarations Section *****
// FUNCTION PROTOTYPES: Each subroutine defined
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void PortE_Init(void);
void Delay100ms(unsigned long time);
//unsigned long arm,sensor;
//void delayms(unsigned long ms);
//void Delay(void);
//void EnableInterrupts(void);
// ***** 3. Subroutines Section *****
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
unsigned long In; // input from PF4
unsigned long Out; // output to PF2 (blue LED)
unsigned long SW;
int main(void){
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
TExaS_Init(SW_PIN_PE0, LED_PIN_PE1, ScopeOn); // activate grader and set system clock to 80 MHz
PortE_Init(); // make PF3-1 out (PF3-1 built-in LEDs)
while(1){
Delay100ms(1);
SW = GPIO_PORTE_DATA_R&0x01; // read PE0 into the switch
if(SW == 1){
GPIO_PORTE_DATA_R ^=0x02; // Toggle PE1
}else{
GPIO_PORTE_DATA_R |=0x02; // Set PE1, LED On
}
}
}
void PortE_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) activate clock for Port E
delay = SYSCTL_RCGC2_R; // allow time for clock to start
GPIO_PORTE_AMSEL_R = 0x00; // 3) disable analog on PF
GPIO_PORTE_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0
GPIO_PORTE_DIR_R = 0x02; // 5) PE1 OUTPUT, PE0 INPUT -- 0000 0010
GPIO_PORTE_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0 no alternate function
GPIO_PORTE_DEN_R = 0x03; // 7) enable digital I/O on PF4-0
GPIO_PORTE_DATA_R |=0x02; // Initialize led ON
}
void Delay100ms(unsigned long time){
unsigned long i;
while(time > 0){
i = 1333333; // 100ms
while(i > 0){
i = i - 1;
}
time = time - 1; // decrements every 100 ms
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment