DAC输出爱心函数,示波器上可以显示爱心函数
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "dac.h"
- #include "adc.h"
- #include "usmart.h"
- #include "math.h"
- double Fx1,Fx2,Fx3,Fx4,x;
- int main(void)
- {
-
- u16 t=0;
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- KEY_Init(); //初始化按键程序
- LED_Init(); //LED端口初始化
- LCD_Init(); //LCD初始化
- usmart_dev.init(72); //初始化USMART
- Adc_Init(); //ADC初始化
- Dac1_Init(); //DAC初始化
- POINT_COLOR=RED;//设置字体为红色
- LCD_ShowString(60,50,200,16,16,"WarShip STM32");
- LCD_ShowString(60,70,200,16,16,"DAC TEST");
- LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(60,110,200,16,16,"2015/1/15");
- LCD_ShowString(60,130,200,16,16,"WK_UP:+ KEY1:-");
- //显示提示信息
- POINT_COLOR=BLUE;//设置字体为蓝色
- LCD_ShowString(60,150,200,16,16,"DAC VAL:");
- LCD_ShowString(60,170,200,16,16,"DAC VOL:0.000V");
- LCD_ShowString(60,190,200,16,16,"ADC VOL:0.000V");
-
- DAC_SetChannel1Data(DAC_Align_12b_R, 0);//初始值为0
- x=1.8165;
- delay_ms(10000);
- delay_ms(10000);
- delay_ms(10000);
- delay_ms(10000);
- delay_ms(10000);
- delay_ms(10000);
- delay_ms(10000);
- while(1)
- {
-
- Fx1=pow(x,0.6666);
- Fx2=sqrt(3.3-pow(x,2));
- Fx3=sin(31.41592*x);
- Fx4=(Fx1+0.9*Fx2*Fx3)*900;
- Dac1_Set_Vol(Fx4+1100);
- if(t==0)
- {
- x=x-0.001;
- }
- else
- {
- x=x+0.001;
- }
- if(x<=0)t=1;
- if(x==1.8165)
- {
- t=0;
- delay_ms(10000);
- }
-
- }
- }
复制代码
所有资料51hei提供下载:
爱心函数.7z
(251.03 KB, 下载次数: 33)
|