/* Including used modules for compilling procedure */ #include "Cpu.h" #include "Events.h" #include "AS1.h" /* Include shared modules, which are used for whole project */ #include "PE_Types.h" #include "PE_Error.h" #include "PE_Const.h" #include "IO_Map.h"
void main(void) {
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/
/* Write your code here */ AS1_SendChar('H'); while(AS1_GetTxComplete()==0){}; AS1_SendChar('e'); while(AS1_GetTxComplete()==0){}; AS1_SendChar('l'); while(AS1_GetTxComplete()==0){}; AS1_SendChar('l'); while(AS1_GetTxComplete()==0){}; AS1_SendChar('o'); while(AS1_GetTxComplete()==0){}; AS1_SendChar('\r'); while(AS1_GetTxComplete()==0){}; AS1_SendChar(''); while(AS1_GetTxComplete()==0){}; for(;;) { } }
以上程序是主程序,以下程序中断程序
/** ################################################################### ** Filename : Events.C ** Project : serial ** Processor : 56F801FA80 ** Beantype : Events ** Version : Driver 01.02 ** Compiler : Metrowerks DSP C Compiler ** Date/Time : 2005-12-10, 15:12 ** Abstract : ** This is user's event module. ** Put your event handler code here. ** Settings : ** Contents : ** AS1_OnRxChar - void AS1_OnRxChar(void); ** ** (c) Copyright UNIS, spol. s r.o. 1997-2004 ** UNIS, spol. s r.o. ** Jundrovska 33 ** 624 00 Brno ** Czech Republic ** http : www.processorexpert.com ** mail : info@processorexpert.com ** ###################################################################*/ /* MODULE Events */
#include "Cpu.h" #include "Events.h"
/* ** =================================================================== ** Event : AS1_OnRxChar (module Events) ** ** From bean : AS1 [AsynchroSerial] ** Description : ** This event is called after a correct character is ** received. ** DMA mode: ** If DMA controller is available on the selected CPU and ** the receiver is configured to use DMA controller then ** this event is disabled. Only OnFullRxBuf method can be ** used in DMA mode. ** Parameters : None ** Returns : Nothing ** =================================================================== */ #pragma interrupt called /* Comment this line if the appropriate 'Interrupt preserve registers' property */ /* is set to 'yes' (#pragma interrupt saveall is generated before the ISR) */ unsigned char *order; void AS1_OnRxChar(void) { /* Write your code here ... */ if(!AS1_RecvChar(order)) if(*order == 'a' || *order =='A') { AS1_SendChar('H');while(AS1_GetTxComplete()==0){}; AS1_SendChar('e');while(AS1_GetTxComplete()==0){}; AS1_SendChar('l');while(AS1_GetTxComplete()==0){}; AS1_SendChar('l');while(AS1_GetTxComplete()==0){}; AS1_SendChar('o');while(AS1_GetTxComplete()==0){}; AS1_SendChar('\r');while(AS1_GetTxComplete()==0){}; AS1_SendChar('\n');while(AS1_GetTxComplete()==0){}; } else { AS1_SendChar('e');while(AS1_GetTxComplete()==0){}; AS1_SendChar('r');while(AS1_GetTxComplete()==0){}; AS1_SendChar('r');while(AS1_GetTxComplete()==0){}; AS1_SendChar('o');while(AS1_GetTxComplete()==0){}; AS1_SendChar('r');while(AS1_GetTxComplete()==0){}; AS1_SendChar('\r');while(AS1_GetTxComplete()==0){}; AS1_SendChar('\n');while(AS1_GetTxComplete()==0){}; } }
/* END Events */
运行结果看图。
当输入a或A时,总是显示H;当输入其他字符时总是显示e.
我原意是当输入a或A时显示Hello;当输入其他字符时显示error.
|