Siva ram
/
TEST
test
main.cpp@0:81825898e19f, 2015-03-21 (annotated)
- Committer:
- Piasiv1206
- Date:
- Sat Mar 21 09:09:12 2015 +0000
- Revision:
- 0:81825898e19f
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Piasiv1206 | 0:81825898e19f | 1 | #include "mbed.h" |
Piasiv1206 | 0:81825898e19f | 2 | |
Piasiv1206 | 0:81825898e19f | 3 | DigitalOut gpo(D0); |
Piasiv1206 | 0:81825898e19f | 4 | DigitalOut led(LED_RED); |
Piasiv1206 | 0:81825898e19f | 5 | |
Piasiv1206 | 0:81825898e19f | 6 | int main() |
Piasiv1206 | 0:81825898e19f | 7 | { |
Piasiv1206 | 0:81825898e19f | 8 | while (true) { |
Piasiv1206 | 0:81825898e19f | 9 | gpo = !gpo; // toggle pin |
Piasiv1206 | 0:81825898e19f | 10 | led = !led; // toggle led |
Piasiv1206 | 0:81825898e19f | 11 | wait(0.2f); |
Piasiv1206 | 0:81825898e19f | 12 | } |
Piasiv1206 | 0:81825898e19f | 13 | } |
Piasiv1206 | 0:81825898e19f | 14 | |
Piasiv1206 | 0:81825898e19f | 15 | |
Piasiv1206 | 0:81825898e19f | 16 | #include <stdint.h> |
Piasiv1206 | 0:81825898e19f | 17 | #include <stdbool.h> |
Piasiv1206 | 0:81825898e19f | 18 | #include <string.h> |
Piasiv1206 | 0:81825898e19f | 19 | #include "driverlib/debug.h" |
Piasiv1206 | 0:81825898e19f | 20 | #include "driverlib/gpio.h" |
Piasiv1206 | 0:81825898e19f | 21 | #include "driverlib/pin_map.h" |
Piasiv1206 | 0:81825898e19f | 22 | #include "driverlib/rom.h" |
Piasiv1206 | 0:81825898e19f | 23 | #include "driverlib/sysctl.h" |
Piasiv1206 | 0:81825898e19f | 24 | #include "driverlib/fpu.h" |
Piasiv1206 | 0:81825898e19f | 25 | #include "driverlib/uart.h" |
Piasiv1206 | 0:81825898e19f | 26 | #include "utils/uartstdio.h" |
Piasiv1206 | 0:81825898e19f | 27 | #include "driverlib/timer.h" |
Piasiv1206 | 0:81825898e19f | 28 | #include "driverlib/adc.h" |
Piasiv1206 | 0:81825898e19f | 29 | #include "driverlib/interrupt.h" |
Piasiv1206 | 0:81825898e19f | 30 | #include "inc/hw_memmap.h" |
Piasiv1206 | 0:81825898e19f | 31 | #include "inc/hw_types.h" |
Piasiv1206 | 0:81825898e19f | 32 | #include "inc/tm4c123gh6pm.h" |
Piasiv1206 | 0:81825898e19f | 33 | |
Piasiv1206 | 0:81825898e19f | 34 | |
Piasiv1206 | 0:81825898e19f | 35 | void Timer(void) |
Piasiv1206 | 0:81825898e19f | 36 | { |
Piasiv1206 | 0:81825898e19f | 37 | |
Piasiv1206 | 0:81825898e19f | 38 | volatile uint32_t ui32Loop; |
Piasiv1206 | 0:81825898e19f | 39 | |
Piasiv1206 | 0:81825898e19f | 40 | |
Piasiv1206 | 0:81825898e19f | 41 | TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT); |
Piasiv1206 | 0:81825898e19f | 42 | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); |
Piasiv1206 | 0:81825898e19f | 43 | GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 44 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1); |
Piasiv1206 | 0:81825898e19f | 45 | SysCtlDelay(SysCtlClockGet()); |
Piasiv1206 | 0:81825898e19f | 46 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x0); |
Piasiv1206 | 0:81825898e19f | 47 | SysCtlDelay(SysCtlClockGet()); |
Piasiv1206 | 0:81825898e19f | 48 | //UARTprintf("PRIYA \n"); |
Piasiv1206 | 0:81825898e19f | 49 | } |
Piasiv1206 | 0:81825898e19f | 50 | |
Piasiv1206 | 0:81825898e19f | 51 | void UARTIntHandler(void) |
Piasiv1206 | 0:81825898e19f | 52 | |
Piasiv1206 | 0:81825898e19f | 53 | { |
Piasiv1206 | 0:81825898e19f | 54 | |
Piasiv1206 | 0:81825898e19f | 55 | //unsigned int i=0; |
Piasiv1206 | 0:81825898e19f | 56 | char LED; |
Piasiv1206 | 0:81825898e19f | 57 | //char LED; |
Piasiv1206 | 0:81825898e19f | 58 | //char LEDR[10] = 'L','E','D','R'; |
Piasiv1206 | 0:81825898e19f | 59 | // LEDB[10] = "L","E","D","B" ; |
Piasiv1206 | 0:81825898e19f | 60 | uint32_t ui32Status; |
Piasiv1206 | 0:81825898e19f | 61 | |
Piasiv1206 | 0:81825898e19f | 62 | // |
Piasiv1206 | 0:81825898e19f | 63 | // Get the interrrupt status. |
Piasiv1206 | 0:81825898e19f | 64 | // |
Piasiv1206 | 0:81825898e19f | 65 | ui32Status = UARTIntStatus(UART0_BASE, true); |
Piasiv1206 | 0:81825898e19f | 66 | |
Piasiv1206 | 0:81825898e19f | 67 | // |
Piasiv1206 | 0:81825898e19f | 68 | // Clear the asserted interrupts. |
Piasiv1206 | 0:81825898e19f | 69 | // |
Piasiv1206 | 0:81825898e19f | 70 | UARTIntClear(UART0_BASE, ui32Status); |
Piasiv1206 | 0:81825898e19f | 71 | |
Piasiv1206 | 0:81825898e19f | 72 | //while(UARTCharsAvail(UART0_BASE)) |
Piasiv1206 | 0:81825898e19f | 73 | |
Piasiv1206 | 0:81825898e19f | 74 | //{ |
Piasiv1206 | 0:81825898e19f | 75 | LED = UARTCharGetNonBlocking(UART0_BASE); |
Piasiv1206 | 0:81825898e19f | 76 | //i++; |
Piasiv1206 | 0:81825898e19f | 77 | //} |
Piasiv1206 | 0:81825898e19f | 78 | |
Piasiv1206 | 0:81825898e19f | 79 | if(LED=='R') |
Piasiv1206 | 0:81825898e19f | 80 | { |
Piasiv1206 | 0:81825898e19f | 81 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1); |
Piasiv1206 | 0:81825898e19f | 82 | } |
Piasiv1206 | 0:81825898e19f | 83 | |
Piasiv1206 | 0:81825898e19f | 84 | else if (LED=='B') |
Piasiv1206 | 0:81825898e19f | 85 | { |
Piasiv1206 | 0:81825898e19f | 86 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2 ,GPIO_PIN_2); |
Piasiv1206 | 0:81825898e19f | 87 | } |
Piasiv1206 | 0:81825898e19f | 88 | |
Piasiv1206 | 0:81825898e19f | 89 | else if (LED== 'O') |
Piasiv1206 | 0:81825898e19f | 90 | { |
Piasiv1206 | 0:81825898e19f | 91 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2 ,0); |
Piasiv1206 | 0:81825898e19f | 92 | } |
Piasiv1206 | 0:81825898e19f | 93 | |
Piasiv1206 | 0:81825898e19f | 94 | else if (LED== 'H') |
Piasiv1206 | 0:81825898e19f | 95 | { |
Piasiv1206 | 0:81825898e19f | 96 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,0); |
Piasiv1206 | 0:81825898e19f | 97 | } |
Piasiv1206 | 0:81825898e19f | 98 | else if (LED=='Q') |
Piasiv1206 | 0:81825898e19f | 99 | { |
Piasiv1206 | 0:81825898e19f | 100 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3 ,0); |
Piasiv1206 | 0:81825898e19f | 101 | } |
Piasiv1206 | 0:81825898e19f | 102 | else if (LED=='G') |
Piasiv1206 | 0:81825898e19f | 103 | { |
Piasiv1206 | 0:81825898e19f | 104 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3 ,GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 105 | } |
Piasiv1206 | 0:81825898e19f | 106 | else |
Piasiv1206 | 0:81825898e19f | 107 | { |
Piasiv1206 | 0:81825898e19f | 108 | UARTprintf("Invalid Input/n"); |
Piasiv1206 | 0:81825898e19f | 109 | } |
Piasiv1206 | 0:81825898e19f | 110 | |
Piasiv1206 | 0:81825898e19f | 111 | |
Piasiv1206 | 0:81825898e19f | 112 | |
Piasiv1206 | 0:81825898e19f | 113 | |
Piasiv1206 | 0:81825898e19f | 114 | |
Piasiv1206 | 0:81825898e19f | 115 | |
Piasiv1206 | 0:81825898e19f | 116 | |
Piasiv1206 | 0:81825898e19f | 117 | //UARTprintf("priya\n"); |
Piasiv1206 | 0:81825898e19f | 118 | UARTprintf("%c \n",LED); |
Piasiv1206 | 0:81825898e19f | 119 | } |
Piasiv1206 | 0:81825898e19f | 120 | |
Piasiv1206 | 0:81825898e19f | 121 | /* |
Piasiv1206 | 0:81825898e19f | 122 | void |
Piasiv1206 | 0:81825898e19f | 123 | UARTIntHandler(void) |
Piasiv1206 | 0:81825898e19f | 124 | { |
Piasiv1206 | 0:81825898e19f | 125 | uint32_t ui32Status; |
Piasiv1206 | 0:81825898e19f | 126 | |
Piasiv1206 | 0:81825898e19f | 127 | // |
Piasiv1206 | 0:81825898e19f | 128 | // Get the interrrupt status. |
Piasiv1206 | 0:81825898e19f | 129 | // |
Piasiv1206 | 0:81825898e19f | 130 | ui32Status = ROM_UARTIntStatus(UART0_BASE, true); |
Piasiv1206 | 0:81825898e19f | 131 | |
Piasiv1206 | 0:81825898e19f | 132 | // |
Piasiv1206 | 0:81825898e19f | 133 | // Clear the asserted interrupts. |
Piasiv1206 | 0:81825898e19f | 134 | // |
Piasiv1206 | 0:81825898e19f | 135 | ROM_UARTIntClear(UART0_BASE, ui32Status); |
Piasiv1206 | 0:81825898e19f | 136 | |
Piasiv1206 | 0:81825898e19f | 137 | // |
Piasiv1206 | 0:81825898e19f | 138 | // Loop while there are characters in the receive FIFO. |
Piasiv1206 | 0:81825898e19f | 139 | // |
Piasiv1206 | 0:81825898e19f | 140 | while(ROM_UARTCharsAvail(UART0_BASE)) |
Piasiv1206 | 0:81825898e19f | 141 | { |
Piasiv1206 | 0:81825898e19f | 142 | // |
Piasiv1206 | 0:81825898e19f | 143 | // Read the next character from the UART and write it back to the UART. |
Piasiv1206 | 0:81825898e19f | 144 | // |
Piasiv1206 | 0:81825898e19f | 145 | ROM_UARTCharPutNonBlocking(UART0_BASE, |
Piasiv1206 | 0:81825898e19f | 146 | ROM_UARTCharGetNonBlocking(UART0_BASE)); |
Piasiv1206 | 0:81825898e19f | 147 | |
Piasiv1206 | 0:81825898e19f | 148 | // |
Piasiv1206 | 0:81825898e19f | 149 | // Blink the LED to show a character transfer is occuring. |
Piasiv1206 | 0:81825898e19f | 150 | // |
Piasiv1206 | 0:81825898e19f | 151 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); |
Piasiv1206 | 0:81825898e19f | 152 | |
Piasiv1206 | 0:81825898e19f | 153 | // |
Piasiv1206 | 0:81825898e19f | 154 | // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. |
Piasiv1206 | 0:81825898e19f | 155 | // |
Piasiv1206 | 0:81825898e19f | 156 | SysCtlDelay(SysCtlClockGet() / (1000 * 3)); |
Piasiv1206 | 0:81825898e19f | 157 | |
Piasiv1206 | 0:81825898e19f | 158 | // |
Piasiv1206 | 0:81825898e19f | 159 | // Turn off the LED |
Piasiv1206 | 0:81825898e19f | 160 | // |
Piasiv1206 | 0:81825898e19f | 161 | GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); |
Piasiv1206 | 0:81825898e19f | 162 | |
Piasiv1206 | 0:81825898e19f | 163 | } |
Piasiv1206 | 0:81825898e19f | 164 | } |
Piasiv1206 | 0:81825898e19f | 165 | */ |
Piasiv1206 | 0:81825898e19f | 166 | |
Piasiv1206 | 0:81825898e19f | 167 | |
Piasiv1206 | 0:81825898e19f | 168 | void |
Piasiv1206 | 0:81825898e19f | 169 | ConfigureUART(void) |
Piasiv1206 | 0:81825898e19f | 170 | { |
Piasiv1206 | 0:81825898e19f | 171 | // |
Piasiv1206 | 0:81825898e19f | 172 | // Enable the GPIO Peripheral used by the UART. |
Piasiv1206 | 0:81825898e19f | 173 | // |
Piasiv1206 | 0:81825898e19f | 174 | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); |
Piasiv1206 | 0:81825898e19f | 175 | |
Piasiv1206 | 0:81825898e19f | 176 | // |
Piasiv1206 | 0:81825898e19f | 177 | // Enable UART0 |
Piasiv1206 | 0:81825898e19f | 178 | // |
Piasiv1206 | 0:81825898e19f | 179 | SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); |
Piasiv1206 | 0:81825898e19f | 180 | |
Piasiv1206 | 0:81825898e19f | 181 | // |
Piasiv1206 | 0:81825898e19f | 182 | // Configure GPIO Pins for UART mode. |
Piasiv1206 | 0:81825898e19f | 183 | // |
Piasiv1206 | 0:81825898e19f | 184 | GPIOPinConfigure(GPIO_PA0_U0RX); |
Piasiv1206 | 0:81825898e19f | 185 | GPIOPinConfigure(GPIO_PA1_U0TX); |
Piasiv1206 | 0:81825898e19f | 186 | GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); |
Piasiv1206 | 0:81825898e19f | 187 | |
Piasiv1206 | 0:81825898e19f | 188 | // |
Piasiv1206 | 0:81825898e19f | 189 | // Use the internal 16MHz oscillator as the UART clock source. |
Piasiv1206 | 0:81825898e19f | 190 | // |
Piasiv1206 | 0:81825898e19f | 191 | UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); |
Piasiv1206 | 0:81825898e19f | 192 | |
Piasiv1206 | 0:81825898e19f | 193 | // |
Piasiv1206 | 0:81825898e19f | 194 | // Initialize the UART for console I/O. |
Piasiv1206 | 0:81825898e19f | 195 | // |
Piasiv1206 | 0:81825898e19f | 196 | UARTStdioConfig(0, 115200, 16000000); |
Piasiv1206 | 0:81825898e19f | 197 | } |
Piasiv1206 | 0:81825898e19f | 198 | |
Piasiv1206 | 0:81825898e19f | 199 | |
Piasiv1206 | 0:81825898e19f | 200 | void main(){ |
Piasiv1206 | 0:81825898e19f | 201 | volatile uint32_t ui32Loop; |
Piasiv1206 | 0:81825898e19f | 202 | //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); |
Piasiv1206 | 0:81825898e19f | 203 | //GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 204 | //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1); |
Piasiv1206 | 0:81825898e19f | 205 | SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | |
Piasiv1206 | 0:81825898e19f | 206 | SYSCTL_XTAL_16MHZ); |
Piasiv1206 | 0:81825898e19f | 207 | FPULazyStackingEnable(); |
Piasiv1206 | 0:81825898e19f | 208 | FPUEnable(); |
Piasiv1206 | 0:81825898e19f | 209 | int x,p,z; |
Piasiv1206 | 0:81825898e19f | 210 | float volt,s; |
Piasiv1206 | 0:81825898e19f | 211 | |
Piasiv1206 | 0:81825898e19f | 212 | IntMasterEnable(); |
Piasiv1206 | 0:81825898e19f | 213 | |
Piasiv1206 | 0:81825898e19f | 214 | IntPrioritySet(INT_UART0, 0x00); |
Piasiv1206 | 0:81825898e19f | 215 | IntPrioritySet(INT_TIMER0A, 0x40); |
Piasiv1206 | 0:81825898e19f | 216 | |
Piasiv1206 | 0:81825898e19f | 217 | |
Piasiv1206 | 0:81825898e19f | 218 | SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); |
Piasiv1206 | 0:81825898e19f | 219 | TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); |
Piasiv1206 | 0:81825898e19f | 220 | TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()*60); |
Piasiv1206 | 0:81825898e19f | 221 | IntEnable(INT_TIMER0A); |
Piasiv1206 | 0:81825898e19f | 222 | TimerEnable(TIMER0_BASE, TIMER_A); |
Piasiv1206 | 0:81825898e19f | 223 | TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); |
Piasiv1206 | 0:81825898e19f | 224 | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); |
Piasiv1206 | 0:81825898e19f | 225 | GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 226 | SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); |
Piasiv1206 | 0:81825898e19f | 227 | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); |
Piasiv1206 | 0:81825898e19f | 228 | GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 229 | ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); |
Piasiv1206 | 0:81825898e19f | 230 | ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); |
Piasiv1206 | 0:81825898e19f | 231 | ADCSequenceEnable(ADC0_BASE, 3); |
Piasiv1206 | 0:81825898e19f | 232 | ADCIntClear(ADC0_BASE, 3); |
Piasiv1206 | 0:81825898e19f | 233 | |
Piasiv1206 | 0:81825898e19f | 234 | |
Piasiv1206 | 0:81825898e19f | 235 | |
Piasiv1206 | 0:81825898e19f | 236 | |
Piasiv1206 | 0:81825898e19f | 237 | |
Piasiv1206 | 0:81825898e19f | 238 | ConfigureUART(); |
Piasiv1206 | 0:81825898e19f | 239 | UARTFlowControlSet(UART0_BASE,UART_FLOWCONTROL_NONE); |
Piasiv1206 | 0:81825898e19f | 240 | IntEnable(INT_UART0); |
Piasiv1206 | 0:81825898e19f | 241 | UARTFIFODisable(UART0_BASE); |
Piasiv1206 | 0:81825898e19f | 242 | UARTIntEnable(UART0_BASE, UART_INT_RX ); |
Piasiv1206 | 0:81825898e19f | 243 | UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8); |
Piasiv1206 | 0:81825898e19f | 244 | while(1){ |
Piasiv1206 | 0:81825898e19f | 245 | //GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); |
Piasiv1206 | 0:81825898e19f | 246 | //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1); |
Piasiv1206 | 0:81825898e19f | 247 | //SysCtlDelay(200000); |
Piasiv1206 | 0:81825898e19f | 248 | //for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) |
Piasiv1206 | 0:81825898e19f | 249 | // { |
Piasiv1206 | 0:81825898e19f | 250 | // } |
Piasiv1206 | 0:81825898e19f | 251 | //GPIO_PORTF_DATA_R = 0x0; |
Piasiv1206 | 0:81825898e19f | 252 | //for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) |
Piasiv1206 | 0:81825898e19f | 253 | // { |
Piasiv1206 | 0:81825898e19f | 254 | // } |
Piasiv1206 | 0:81825898e19f | 255 | x=ADC0_SSFIFO3_R; |
Piasiv1206 | 0:81825898e19f | 256 | ADC0_PSSI_R = 1<<3; |
Piasiv1206 | 0:81825898e19f | 257 | volt = 0.0008058608*x; |
Piasiv1206 | 0:81825898e19f | 258 | p = volt; |
Piasiv1206 | 0:81825898e19f | 259 | p = p*1000; |
Piasiv1206 | 0:81825898e19f | 260 | volt = 0.0008058608*x*1000; |
Piasiv1206 | 0:81825898e19f | 261 | s = volt; |
Piasiv1206 | 0:81825898e19f | 262 | z = s-p; |
Piasiv1206 | 0:81825898e19f | 263 | p = p/1000; |
Piasiv1206 | 0:81825898e19f | 264 | |
Piasiv1206 | 0:81825898e19f | 265 | UARTprintf("Priya %d",x); |
Piasiv1206 | 0:81825898e19f | 266 | UARTprintf("volt: %d.%03d \n",p,z); |
Piasiv1206 | 0:81825898e19f | 267 | x = 0; |
Piasiv1206 | 0:81825898e19f | 268 | } |
Piasiv1206 | 0:81825898e19f | 269 | } |