最近在做函数信号发生器,利用dac输出一个正弦波,欢迎大家批评指正!
单片机源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart1.h"
- #include "usart2.h"
- #include "usart3.h"
- #include "dac1.h"
-
- int main()
- {
- u64 xitong_haomiao_printf_old;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
- delay_init();
-
- USART1_Init(115200);
- USART2_Init(115200);
- USART3_Init(115200);
-
- printf("串口1用printf,sys.c 设置...\r\n");
- USART2_printf("USART1 OK...\r\n");
- USART2_printf("USART2 OK...\r\n");
- USART3_printf("USART3 OK...\r\n");
-
- Dac1_Test();
-
- while(1)
- {
- if(USART1_RX_STA&0x8000)
- {
- USART1_Send_Array(USART1_RX_BUF,(USART1_RX_STA&0x3fff));
- USART1_printf("\r\n");
- USART1_RX_STA=0;
- }
- if(USART2_RX_STA&0x8000)
- {
- USART2_Send_Array(USART2_RX_BUF,(USART2_RX_STA&0x3fff));
- USART2_printf("\r\n");
- USART2_RX_STA=0;
- }
- if(USART3_RX_STA&0x8000)
- {
- USART3_Send_Array(USART3_RX_BUF,(USART3_RX_STA&0x3fff));
- USART3_printf("\r\n");
- USART3_RX_STA=0;
- }
- if(xitong_haomiao-xitong_haomiao_printf_old>=1000)
- {
- xitong_haomiao_printf_old=xitong_haomiao;
- printf("xitong_haomiao=%llu\r\n",xitong_haomiao);
- USART2_printf("xitong_haomiao=%llu\r\n",xitong_haomiao);
- }
- }
- }
复制代码
所有资料51hei提供下载:
dma dac 正弦波.7z
(185.98 KB, 下载次数: 39)
|