test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut gpo(D0);
00004 DigitalOut led(LED_RED);
00005 
00006 int main()
00007 {
00008     while (true) {
00009         gpo = !gpo; // toggle pin
00010         led = !led; // toggle led
00011         wait(0.2f);
00012     }
00013 }
00014 
00015 
00016 #include <stdint.h>
00017 #include <stdbool.h>
00018 #include <string.h>
00019 #include "driverlib/debug.h"
00020 #include "driverlib/gpio.h"
00021 #include "driverlib/pin_map.h"
00022 #include "driverlib/rom.h"
00023 #include "driverlib/sysctl.h"
00024 #include "driverlib/fpu.h"
00025 #include "driverlib/uart.h"
00026 #include "utils/uartstdio.h"
00027 #include "driverlib/timer.h"
00028 #include "driverlib/adc.h"
00029 #include "driverlib/interrupt.h"
00030 #include "inc/hw_memmap.h"
00031 #include "inc/hw_types.h"
00032 #include "inc/tm4c123gh6pm.h"
00033 
00034 
00035 void Timer(void)
00036 {
00037 
00038     volatile uint32_t ui32Loop;
00039 
00040 
00041         TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
00042         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
00043         GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
00044         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1);
00045         SysCtlDelay(SysCtlClockGet());
00046         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0x0);
00047         SysCtlDelay(SysCtlClockGet());
00048         //UARTprintf("PRIYA \n");
00049 }
00050 
00051 void UARTIntHandler(void)
00052 
00053 {
00054 
00055     //unsigned int i=0;
00056     char LED;
00057     //char LED;
00058     //char LEDR[10] = 'L','E','D','R';
00059     // LEDB[10] = "L","E","D","B" ;
00060     uint32_t ui32Status;
00061 
00062         //
00063         // Get the interrrupt status.
00064         //
00065         ui32Status = UARTIntStatus(UART0_BASE, true);
00066 
00067         //
00068         // Clear the asserted interrupts.
00069         //
00070         UARTIntClear(UART0_BASE, ui32Status);
00071 
00072     //while(UARTCharsAvail(UART0_BASE))
00073 
00074     //{
00075     LED = UARTCharGetNonBlocking(UART0_BASE);
00076     //i++;
00077     //}
00078 
00079     if(LED=='R')
00080     {
00081         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1);
00082     }
00083 
00084     else if (LED=='B')
00085     {
00086         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2 ,GPIO_PIN_2);
00087     }
00088 
00089     else if (LED== 'O')
00090     {
00091         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2 ,0);
00092     }
00093 
00094     else if (LED== 'H')
00095     {
00096         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,0);
00097     }
00098     else if (LED=='Q')
00099         {
00100             GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3 ,0);
00101         }
00102     else if (LED=='G')
00103         {
00104             GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3 ,GPIO_PIN_3);
00105         }
00106     else
00107     {
00108        UARTprintf("Invalid Input/n");
00109     }
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117     //UARTprintf("priya\n");
00118     UARTprintf("%c \n",LED);
00119 }
00120 
00121 /*
00122 void
00123 UARTIntHandler(void)
00124 {
00125     uint32_t ui32Status;
00126 
00127     //
00128     // Get the interrrupt status.
00129     //
00130     ui32Status = ROM_UARTIntStatus(UART0_BASE, true);
00131 
00132     //
00133     // Clear the asserted interrupts.
00134     //
00135     ROM_UARTIntClear(UART0_BASE, ui32Status);
00136 
00137     //
00138     // Loop while there are characters in the receive FIFO.
00139     //
00140     while(ROM_UARTCharsAvail(UART0_BASE))
00141     {
00142         //
00143         // Read the next character from the UART and write it back to the UART.
00144         //
00145         ROM_UARTCharPutNonBlocking(UART0_BASE,
00146                                    ROM_UARTCharGetNonBlocking(UART0_BASE));
00147 
00148         //
00149         // Blink the LED to show a character transfer is occuring.
00150         //
00151         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
00152 
00153         //
00154         // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
00155         //
00156         SysCtlDelay(SysCtlClockGet() / (1000 * 3));
00157 
00158         //
00159         // Turn off the LED
00160         //
00161         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
00162 
00163     }
00164 }
00165 */
00166 
00167 
00168 void
00169 ConfigureUART(void)
00170 {
00171     //
00172     // Enable the GPIO Peripheral used by the UART.
00173     //
00174     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
00175 
00176     //
00177     // Enable UART0
00178     //
00179     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
00180 
00181     //
00182     // Configure GPIO Pins for UART mode.
00183     //
00184     GPIOPinConfigure(GPIO_PA0_U0RX);
00185     GPIOPinConfigure(GPIO_PA1_U0TX);
00186     GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
00187 
00188     //
00189     // Use the internal 16MHz oscillator as the UART clock source.
00190     //
00191     UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
00192 
00193     //
00194     // Initialize the UART for console I/O.
00195     //
00196     UARTStdioConfig(0, 115200, 16000000);
00197 }
00198 
00199 
00200 void main(){
00201     volatile uint32_t ui32Loop;
00202     //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
00203     //GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
00204     //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1);
00205     SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
00206                        SYSCTL_XTAL_16MHZ);
00207     FPULazyStackingEnable();
00208     FPUEnable();
00209     int x,p,z;
00210     float volt,s;
00211 
00212     IntMasterEnable();
00213 
00214     IntPrioritySet(INT_UART0, 0x00);
00215     IntPrioritySet(INT_TIMER0A, 0x40);
00216 
00217 
00218         SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
00219         TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
00220        TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()*60);
00221        IntEnable(INT_TIMER0A);
00222        TimerEnable(TIMER0_BASE, TIMER_A);
00223        TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
00224     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
00225     GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
00226     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
00227     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
00228     GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
00229     ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
00230     ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
00231     ADCSequenceEnable(ADC0_BASE, 3);
00232     ADCIntClear(ADC0_BASE, 3);
00233 
00234 
00235 
00236 
00237 
00238     ConfigureUART();
00239     UARTFlowControlSet(UART0_BASE,UART_FLOWCONTROL_NONE);
00240     IntEnable(INT_UART0);
00241     UARTFIFODisable(UART0_BASE);
00242     UARTIntEnable(UART0_BASE, UART_INT_RX );
00243     UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);
00244     while(1){
00245         //GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
00246                 //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 ,GPIO_PIN_1);
00247                 //SysCtlDelay(200000);
00248                 //for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
00249                      //   {
00250                       //  }
00251                 //GPIO_PORTF_DATA_R = 0x0;
00252                 //for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
00253                                   //      {
00254                                    //     }
00255         x=ADC0_SSFIFO3_R;
00256         ADC0_PSSI_R = 1<<3;
00257     volt = 0.0008058608*x;
00258     p = volt;
00259     p = p*1000;
00260     volt = 0.0008058608*x*1000;
00261     s = volt;
00262     z = s-p;
00263     p = p/1000;
00264 
00265     UARTprintf("Priya %d",x);
00266     UARTprintf("volt: %d.%03d \n",p,z);
00267     x = 0;
00268 }
00269 }