#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 //·¢Ëíêy¾Y3¤¶è,×îoÃμèóúsizeof(TEXT_TO_SEND)+2μÄÕûêy±¶.
u8 SendBuff[SEND_BUF_SIZE]; //·¢Ëíêy¾Y»o3åÇø
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);//éèÖÃÖD¶ÏóÅÏ輶·Ö×éÎa×é2£o2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
uart_init(115200); //′®¿ú3õê¼»ˉÎa115200
LCD_Init(); //3õê¼»ˉLCD
MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR,(u32)SendBuff,SEND_BUF_SIZE);//DMA1í¨μà4,íaéèÎa′®¿ú1,′æ′¢Æ÷ÎaSendBuff,3¤¶èSEND_BUF_SIZE.
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
j=sizeof(TEXT_TO_SEND);
for(i=0;i<SEND_BUF_SIZE;i++)//ìî3äêy¾Yμ½SendBuff
{
if(t>=j)//¼óèë»»DD·û
{
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Äü′®¿ú1μÄDMA·¢Ëí
MYDMA_Enable(DMA1_Channel4);//¿aê¼ò»′ÎDMA′«ê䣡
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC4)!=RESET) //ÅD¶Ïí¨μà4′«êäíê3é
{
DMA_ClearFlag(DMA1_FLAG_TC4);//Çå3yí¨μà4′«êäíê3é±êÖ¾
break;
}
}
while(1);
if(USART_RX_STA&0X8000)
{
len=USART_RX_STA&0x3fff;//μÃμ½′Ë′νóêÕμ½μÄêy¾Y3¤¶è
for(t=0;t<len;t++)
{
USART_SendData(USART1, USART_RX_BUF[t]);//½óêÕμ½μÄêy¾Y·¢μ½′®¿ú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);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>