Digital Systems Design lab Report
h2o// Sound.c, // This module contains the SysTick ISR that plays sound // Runs on LM4F120 or TM4C123 // Program written by: put your names here // Date Created: 8/25/2013 // Last Modified: 10/9/2013 // Lab number: 4 // Hardware connections #include "tm4c123gh6pm.h" #include "dac.h" #define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010)) #define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014)) #define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018)) int notes [64] = {0x10,0x11,0x13,0x14,0x15,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1e, 0x1f,0x1f,0x1f,0x1f,0x1f,0x1e,0x1e,0x1d,0x1c,0x1b,0x1a,0x19,0x18,0x17,0x15,0x14,0x13,0x11, 0x10,0xe,0xc,0xb,0xa,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x1,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x2, 0x3,0x4,0x5,0x6,0x7,0x8,0xa,0xb,0xc,0xe}; int i=0; // put code definitions for the software (actual C code) // this file explains how the module works // **************Sound_Init********************* // Initialize Systick periodic interrupts // Input: Initial interrupt period // Units to be determined by YOU // Maximum to be determined by YOU // Minimum to be determined by YOU // Output: none void Sound_Init(unsigned long period){ DAC_Init(); NVIC_ST_CTRL_R = 0x0; NVIC_ST_RELOAD_R = period-1; NVIC_ST_CURRENT_R = 0x0; NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF) | 0x40000000; //priority 2 NVIC_ST_CTRL_R = 0x00000007; //enable with core clock and interrupts } // **************Sound_Play********************* // Start sound output, and set Systick interrupt period // Input: interrupt period // Units to be determined by YOU // Maximum to be determined by YOU // Minimum to be determined by YOU // input of zero disables sound output // Output: none void Sound_Play(unsigned long period){ //Frequency = 440 Hz --> A Note if(period==440){ // NVIC_ST_CTRL_R = 0x0; NVIC_ST_RELOAD_R = 0X237; //567.8 count NVIC_ST_CURRENT_R = 0x0;} //Frequency = 494 Hz --> B Note else if(period==494){ // NVIC_ST_CTRL_R = 0x0; NVIC_ST_RELOAD_R = 0x1F9; //505 count NVIC_ST_CURRENT_R = 0x0;} //Frequency = 262 Hz --> C Note else if(period==262){ // NVIC_ST_CTRL_R = 0x0; NVIC_ST_RELOAD_R = 0x3B9; //953 count NVIC_ST_CURRENT_R = 0x0;} //Frequency = 294 Hz --> D Note else if(period==294){ // NVIC_ST_CTRL_R = 0x0; NVIC_ST_RELOAD_R = 0x351; //849 count NVIC_ST_CURRENT_R = 0x0; } else NVIC_ST_RELOAD_R =0; } // Interrupt service routine // Executed periodically, the actual period // determined by the current Reload. void SysTick_Handler(void){ DAC_Out (notes[i]); i=(i+1)%64; }