|
- #include "inc/hw_ints.h"
- #include "inc/hw_memmap.h"
- #include "inc/hw_types.h"
- #include "driverlib/gpio.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/timer.h"
- #include "driverlib/uart.h"
- unsigned char str_receive[10];
- unsigned char pr=0,flag_valid_data=0,flag_complete_data=0;
- void
- UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
- {
- //
- // Loop while there are more characters to send.
- //
- while(ulCount--)
- {
- //
- // Write the next character to the UART.
- //
- UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
- }
- }
- void
- UARTIntHandler(void)
- {
- unsigned long ulStatus;
-
- //
- // Get the interrrupt status.
- //
- ulStatus = UARTIntStatus(UART0_BASE, true);
- //
- // Clear the asserted interrupts.
- //
- UARTIntClear(UART0_BASE, ulStatus);
- //
- // Loop while there are characters in the receive FIFO.
- //
- str_receive[pr]=UARTCharGetNonBlocking(UART0_BASE);
- if((str_receive[pr]==0xcf)&&(flag_valid_data==0))
- {
- flag_valid_data=1;
- }
- if(flag_valid_data)
- {
- if(str_receive[pr]==0xfc)
- {
- pr=0;flag_complete_data=1;flag_valid_data=0;
- }
- else pr++;
- }
- else pr=0;
- if(flag_complete_data==1)
- {
- UARTSend(str_receive,3);
- flag_complete_data=0;
- }
- /* if(str_receive[0]=='a')
- {
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
- }
- else if(str_receive[0]=='b')
- {
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
- } */
- }
- void
- Timer0IntHandler(void)
- {
- TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- IntMasterDisable();
- UARTSend((unsigned char *)"This is Time interrup!\n",sizeof("This is Time interrup!\n"));
- IntMasterEnable();
- }
-
- int
- main(void)
- {
- //
- // Set the clocking to run directly from the crystal.
- //
- SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
- SYSCTL_XTAL_8MHZ);
- //
- // Enable the peripherals used by this example.
- //
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- //
- // Enable processor interrupts.
- //
-
- GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
- //
- // Set GPIO A0 and A1 as UART pins.
- //
- GPIOPinConfigure(GPIO_PA0_U0RX);
- GPIOPinConfigure(GPIO_PA1_U0TX);
- GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
- //
- // Configure the UART for 115,200, 8-N-1 operation.
- //
- UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
- (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
- UART_CONFIG_PAR_NONE));
- //
- // Enable the UART interrupt.
- //
- IntEnable(INT_UART0);
- UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
- TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
- TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
- IntEnable(INT_TIMER0A);
- TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- TimerEnable(TIMER0_BASE, TIMER_A);
- IntMasterEnable();
- //
- // Prompt for text to be entered.
- //
- UARTSend((unsigned char *)"It is start!\n", sizeof("It is start!\n"));
- //
- // Loop forever echoing data through the UART.
- //
- while(1)
- {
- }
- }
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|