[mw_shl_code=applescript,true]#include "stm32f10x.h"
#include "usart.h"
#include "adc.h"
#include "dac.h"
#include "delay.h"
#include "key.h"
#include "led.h"
#include "stdio.h"
#include "includes.h"
u16 USART_RX_STA;
u8 USART_RX_BUF[USART_REC_LEN];
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(intch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE*f)
#endif
PUTCHAR_PROTOTYPE
{
USART1->DR = (u8) ch;
while((USART1->SR&0X40)==0);
return ch;
}
#define START_TASK_PRIO 20
#define START_STK_SIZE 64
OS_STK START_TASK_STK[START_STK_SIZE];
void start_task(void *pdata);
#define usart_TASK_PRIO 7
#define usart_STK_SIZE 64
OS_STK usart_TASK_STK[usart_STK_SIZE];
void usart_task(void *pdata);
#define usart1_TASK_PRIO 8
#define usart1_STK_SIZE 64
OS_STK usart1_TASK_STK[usart1_STK_SIZE];
void usart1_task(void *pdata);
int main()
{
//KEY_Init();
delay_init(); //Ñóê±3õê¼»ˉ
NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
uart_init(72,9600);
adc_init();
Dac1_init();
OSInit();
OSTaskCreate(start_task,(void *)0,(OS_STK *)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO );//′′½¨Æeê¼èÎÎñ
OSStart();
}
void start_task(void *pdata)
{
OS_CPU_SR cpu_sr=0;
pdata = pdata;
OS_ENTER_CRITICAL(); //½øèëáù½çÇø(ÎT·¨±»ÖD¶Ï′ò¶Ï)
//OSTaskCreate( usart_task,(void *)0,(OS_STK*)&usart_TASK_STK[usart_STK_SIZE-1],usart_TASK_PRIO);
OSTaskCreate(usart1_task,(void *)0,(OS_STK*)&usart1_TASK_STK[usart1_STK_SIZE-1],usart1_TASK_PRIO);
OSTaskSuspend(START_TASK_PRIO); //1òÆeÆeê¼èÎÎñ.
OS_EXIT_CRITICAL(); //íË3öáù½çÇø(¿éòÔ±»ÖD¶Ï′ò¶Ï)
}
void usart1_task(void *pdata)
{
u16 t=0;
float temp=0;
u16 num=0; //¶¨òåDACêäèë3õÖμÎaá㣻
u32 adcx=0;
while(1)
{
if(t<=100)
{
t++;
num=0;
DAC->DHR12R1=num;
adcx=DAC->DHR12R1;
temp=(float)adcx*10*10*(3.3/4096);
printf("%f",temp);
printf("
");
}
if(t>100)
{
t++;
num=1000;
DAC->DHR12R1=num;
adcx=DAC->DHR12R1;
temp=(float)adcx*10*10*(3.3/4096);
printf("%f",temp);
printf("
");
if(t>=200) t=0;
}
//if(KEY1==0)
//{
// LED1=!LED1;
//OSTaskSuspend(7);
//}
}
}
void usart_task(void *pdata)
{
u16 t=0;
float temp=0;
u16 num=0; //¶¨òåDACêäèë3õÖμÎaá㣻
u32 adcx=0;
u16 n=0;
while(1)
{
if(t<=100)
{
t++;
num=0;
DAC->DHR12R1=num;
adcx=DAC->DHR12R1;
temp=(float)adcx*10*10*(3.3/4096);
printf("%f",temp);
printf("
");
}
if(t>100)
{
t++;
num=300;
DAC->DHR12R1=num;
adcx=DAC->DHR12R1;
temp=(float)adcx*10*10*(3.3/4096);
printf("%f",temp);
printf("
");
if(t>=200) t=0,n++;
}
}
}
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>