/******************************* * name: * function: * return: ********************************/ #include "string.h" #include "global.h" #include "function.h" #include <stdio.h> #include <aduc7061.h>
unsigned char UartDataRecevice; unsigned char UartDataTransfer; unsigned char ucTxBufferEmpty = 0; unsigned char ucRxBufferFull = 0; volatile unsigned char bSendResultToUART = 0;
void UartSendData(unsigned char uchar); unsigned char UartReceviceData(void);
int main(void) { /********
使用到的变量 *********/ bSendResultToUART = 0; /******** 配置内部时钟10.24mhz *********/ POWKEY1 = 0x1; POWCON0 = 0x78; POWKEY2 = 0xF4; /******** 配置GPIO管脚输出模式 *********/ GP2CON = 0x00; GP2DAT = BIT24; /********
串口的初始化 *********/ GP1CON = BIT0 + BIT4; COMCON0 = BIT7; COMDIV0 = 0x21; COMDIV1 = 0x00; COMCON0 = BIT0 + BIT1 + BIT2; COMIEN0 = BIT0 + BIT1; //使能接收缓冲满中断和发送缓冲空中断 /*使能串口中断*/ IRQEN |= BIT11;
while (1) { if (bSendResultToUART == 1) { printf("Received Charachter was : %x\r\n\n",UartDataRecevice); bSendResultToUART = 0; //UartSendData(UartDataRecevice); 使用这程序卡死了,不知道为什么 } } }
/***************************************** * IRQ_Handler ******************************************/ void IRQ_Handler(void) __irq { unsigned long IRQSTATUS = 0; unsigned char ucCOMIID0 = 0; IRQSTATUS = IRQSTA; if ((IRQSTATUS&BIT11) == BIT11) //UART中断源 { ucCOMIID0 = COMIID0; if ((ucCOMIID0&BIT2) == BIT2) // 接收缓冲区满中断 { UartDataRecevice = COMRX; // 读数据 bSendResultToUART = 1; //置位 } if ((ucCOMIID0&BIT1) == BIT1) { ucTxBufferEmpty = 1; } } }
void UartSendData(unsigned char ucTxChar) { COMTX = ucTxChar; while ((COMSTA0&0x40) == 0x00) { } }
今天自己测试的中断方式串口通讯,欢迎正在使用ADuC706x或使用过的朋友一起交流学习!
|