#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "dma.h"
#define SEND_BUF_SIZE 1 //·¢ËÍÊý¾Ý³¤¶È,×îºÃµÈÓÚsizeof(TEXT_TO_SEND)+2µÄÕûÊý±¶.
u8 SendBuff[SEND_BUF_SIZE]; //·¢ËÍÊý¾Ý»º³åÇø
const u8 TEXT_TO_SEND[]={"ALIENTEK WarShip
STM32F1 DMA ´®¿ÚʵÑé"};
int main(void)
{
u16 i;
u8 len=0,t=0;
u8 j,mask=0;
u8 *data={0};
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÉèÖÃÖжÏÓÅÏȼ¶·Ö×éΪ×é2£º2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶
uart_init(115200); //´®¿Ú³õʼ»¯Îª115200
LCD_Init(); //³õʼ»¯LCD
MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR,(u32)SendBuff,SEND_BUF_SIZE);//DMA1ͨµÀ4,ÍâÉèΪ´®¿Ú1,´æ´¢Æ÷ΪSendBuff,³¤¶ÈSEND_BUF_SIZE.
POINT_COLOR=RED;//ÉèÖÃ×ÖÌåΪºìÉ«
j=sizeof(TEXT_TO_SEND);
for(i=0;i<SEND_BUF_SIZE;i++)//Ìî³äÊý¾Ýµ½SendBuff
{
if(t>=j)//¼ÓÈë»»Ðзû
{
if(mask)
{
SendBuff[i]=0x0a;
t=0;
}
else
{
SendBuff[i]=0x0d;
mask++;
}
}
else//¸´ÖÆTEXT_TO_SENDÓï¾ä
{
mask=0;
SendBuff[i]=TEXT_TO_SEND[t];
t++;
}
}
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); //ʹÄÜ´®¿Ú1µÄDMA·¢ËÍ
MYDMA_Enable(DMA1_Channel4);//¿ªÊ¼Ò»´ÎDMA´«Ê䣡
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC4)!=RESET) //ÅжÏͨµÀ4´«ÊäÍê³É
{
DMA_ClearFlag(DMA1_FLAG_TC4);//Çå³ýͨµÀ4´«ÊäÍê³É±êÖ¾
break;
}
}
while(1);
if(USART_RX_STA&0X8000)
{
len=USART_RX_STA&0x3fff;//µÃµ½´Ë´Î½ÓÊÕµ½µÄÊý¾Ý³¤¶È
for(t=0;t<len;t++)
{
USART_SendData(USART1, USART_RX_BUF[t]);//½ÓÊÕµ½µÄÊý¾Ý·¢µ½´®¿Ú1
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
}
data[t]=USART_RX_BUF[len];
USART_RX_STA=0;
LCD_ShowString(30,30,210,30,30,data);
}
}
一周热门 更多>