Skip to content

Commit

Permalink
Finally finished lab13
Browse files Browse the repository at this point in the history
  • Loading branch information
rosterloh committed Apr 13, 2014
1 parent 7aa3aa7 commit a0bd3a9
Show file tree
Hide file tree
Showing 6 changed files with 2,734 additions and 35 deletions.
19 changes: 10 additions & 9 deletions DAC/DAC.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
// Input: none
// Output: none
void DAC_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x02; // 1) activate Port B
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
// 2) no need to unlock
GPIO_PORTB_AMSEL_R &= ~0x0F; // 3) disable analog functionality on PB3-0
GPIO_PORTB_PCTL_R &= ~0x0000FFFF;// 4) configure PB3-0 as GPIO
GPIO_PORTB_DIR_R |= 0x0F; // 5) make PB3-0 out
GPIO_PORTB_AFSEL_R &= ~0x0F; // 6) disable alt funct on PB3-0
GPIO_PORTB_DEN_R |= 0x0F; // 7) enable digital I/O on PB3-0
SYSCTL_RCGC2_R |= 0x02; // activate Port B
delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
// no need to unlock
GPIO_PORTB_AMSEL_R &= ~0x0F; // disable analog functionality on PB3-0
GPIO_PORTB_PCTL_R &= ~0x0000FFFF; // configure PB3-0 as GPIO
GPIO_PORTB_DIR_R |= 0x0F; // make PB3-0 out
GPIO_PORTB_DR8R_R |= 0x0F; // enable 8 mA drive on PB3-0
GPIO_PORTB_AFSEL_R &= ~0x0F; // disable alt funct on PB3-0
GPIO_PORTB_DEN_R |= 0x0F; // enable digital I/O on PB3-0
}


Expand All @@ -30,5 +31,5 @@ void DAC_Init(void){ volatile unsigned long delay;
// Input: 4-bit data, 0 to 15
// Output: none
void DAC_Out(unsigned long data){
GPIO_PORTB_DATA_R = data;
GPIO_PORTB_DATA_R = (GPIO_PORTB_DATA_R & ~0x0f) | (data & 0x0f);
}
39 changes: 35 additions & 4 deletions DAC/Lab13.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,49 @@ void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void delay(unsigned long msec);
int main(void){ // Real Lab13
unsigned long current;
//unsigned long previous;
// for the real board grader to work
// you must connect PD3 to your DAC output
TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz
// PortE used for piano keys, PortB used for DAC
Sound_Init(); // initialize SysTick timer and DAC
Piano_Init();
EnableInterrupts(); // enable after all initialization are done
//previous = Piano_In();
while(1){
// input from keys to select tone

}

// input from keys to select tone
current = Piano_In();
if (0x01==current) {
#if defined SIN_32
Sound_Tone(C32);
#else
Sound_Tone(C16);
#endif
} else if (0x02==current) {
#if defined SIN_32
Sound_Tone(D32);
#else
Sound_Tone(D16);
#endif
} else if (0x04==current) {
#if defined SIN_32
Sound_Tone(E32);
#else
Sound_Tone(E16);
#endif
} else if (0x08==current) {
#if defined SIN_32
Sound_Tone(G32);
#else
Sound_Tone(G16);
#endif
} else {
Sound_Off();
}
//previous = current;
delay(10);
}
}

// Inputs: Number of msec to delay
Expand Down
Loading

0 comments on commit a0bd3a9

Please sign in to comment.