Purpose
System Requirements
In this lab you will build a switch interface that implements positive logic, and you will build an LED interface that implements positive logic. You will attach this switch and LED to your protoboard (the white piece with all the holes), and interface them to your TM4C123. Overall functionality of this system is similar to Lab 6, with five changes:
1) the pin to which we connect the switch is moved to PE0
2) you will have to remove the PUR initialization because pull up is no longer needed.
3) the pin to which we connect the LED is moved to PE1
4) the switch is changed from negative to positive logic
5) you should decrease the delay so it flashes about 5 Hz. To flash at 5 Hz means the LED comes on 5 times per second. If the switch is pressed we turn on the LED for 100 ms, turn off the LED for 100 ms, and repeat.
1) Make PE1 an output and make PE0 an input.
2) The system starts with the LED on (make PE1 =1).
3) Wait about 100 ms
4) If the switch is pressed (PE0 is 1), then toggle the LED once, else turn the LED on.
5) Steps 3 and 4 are repeated over and over.
Solved by Tolulope Ademilua:
/*Copyright 2016 by Jonathan W. Valvano, valvano@mail.utexas.eduYou 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.*/
#include "TExaS.h"
#include "tm4c123gh6pm.h"
volatile unsigned long PE0;
volatile unsigned long PE1;
void Delay100ms (unsigned long time);
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void Delay100ms (unsigned long time){
while(time > 0){
unsigned long counter;
counter = 1333333; //this means 100ms
while (counter > 0 ) {
--counter;
}
--time; //decrements every 100ms
}
}
int main(void) {
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) E clock
delay = SYSCTL_RCGC2_R;
//
*((volatile unsigned long*)0x40024400)= 0x02; // PE0 input, PE1 output
*((volatile unsigned long *)0x4002451C)= 0x03; // enable digital pins PE0-PE1; GPIO_PORTE_DEN_R = 0x03;
*((volatile unsigned long *)0x40024524)= 0x1F; // allow changes to PE; GPIO_PORTE_CR_R = 0x1F;
*((volatile unsigned long *)0x40024528)= 0x00; // disable analog function; GPIO_PORTE_AMSEL_R = 0x00;
*((volatile unsigned long *)0x40024510)= 0x00; // GPIO_PORTE_PUR_R = 0x00; 00 enable pullup resistors on PE0,PE1: no need because we use positive logic, external and our resistor uses 10kohms
*((volatile unsigned long *)0x4002452C)= 0x00000000; //GPIO_PORTE_PCTL_R = 0x00000000; GPIO clear bit PCTL
while (1){
PE0 = *((volatile unsigned long*)0x40024004)&0x01;
if(PE0){
*((volatile unsigned long *)0x40024008)= 0x02; // the base address of portE + the constant value PE1 =0x40024008, accessed PE1
Delay100ms(1);
*((volatile unsigned long*)0x40024008)= 0x00;
Delay100ms(1);
}else{
*((volatile unsigned long *)0x40024008)=0x02;
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.