[mw_shl_code=c,true]#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "includes.h"
#include "can.h"
#include "beep.h"
#include "lcd.h"
#include "ds18b20.h"
#include "dht11.h"
#include "key.h"
/************************************************
ALIENTEK????STM32??·?°?UCOS???é
??4-1 UCOSIII UCOSIII????
?????§????www.openedv.com
??±??ê????http://eboard.taobao.com
??×????????????¨????????"??????×?"????·?????STM32×?????
?????????í??×?????????????
×÷??????????×? @ALIENTEK
************************************************/
short Stemp;
u8 Shumidity;
//??????????
#define START_TASK_PRIO 3
//?????????ó??
#define START_STK_SIZE 512
//?????????é
OS_TCB StartTaskTCB;
//????????
CPU_STK START_TASK_STK[START_STK_SIZE];
//????????
void start_task(void *p_arg);
//??????????
#define CAN_TASK_PRIO 4
//?????????ó??
#define CAN_STK_SIZE 256
//?????????é
OS_TCB CANTaskTCB;
//????????
CPU_STK CAN_TASK_STK[CAN_STK_SIZE];
void CAN_task(void *p_arg);
//??????????
#define WARING_TASK_PRIO 5
//?????????ó??
#define WARING_STK_SIZE 128
//?????????é
OS_TCB WARINGTaskTCB;
//????????
CPU_STK WARING_TASK_STK[WARING_STK_SIZE];
//????????
void WARING_task(void *p_arg);
////??????????
//#define FLOAT_TASK_PRIO 6
////?????????ó??
//#define FLOAT_STK_SIZE 128
////?????????é
//OS_TCB FloatTaskTCB;
////????????
//__align(8) CPU_STK FLOAT_TASK_STK[FLOAT_STK_SIZE];
////????????
//void float_task(void *p_arg);
int main(void)
{
OS_ERR err;
CPU_SR_ALLOC();
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//
uart_init(115200);
LED_Init();
LCD_Init();
KEY_Init();
BEEP_Init();
//??????CAN?¤×÷????
CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_9tq,4,CAN_Mode_LoopBack);//CAN???????·??????,?¨????500Kbps
OSInit(&err);
OS_CRITICAL_ENTER();
OSTaskCreate((OS_TCB * )&StartTaskTCB,
(CPU_CHAR * )"start task",
(OS_TASK_PTR )start_task,
(void * )0,
(OS_PRIO )START_TASK_PRIO,
(CPU_STK * )&START_TASK_STK[0],
(CPU_STK_SIZE)START_STK_SIZE/10,
(CPU_STK_SIZE)START_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
OS_CRITICAL_EXIT();
OSStart(&err);
while(1);
}
void start_task(void *p_arg)
{
OS_ERR err;
CPU_SR_ALLOC();
p_arg = p_arg;
CPU_Init();
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
#if OS_CFG_SCHED_ROUND_ROBIN_EN
OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
#endif
OS_CRITICAL_ENTER();
OSTaskCreate((OS_TCB * )&CANTaskTCB,
(CPU_CHAR * )"CAN task",
(OS_TASK_PTR )CAN_task,
(void * )0,
(OS_PRIO )CAN_TASK_PRIO,
(CPU_STK * )&CAN_TASK_STK[0],
(CPU_STK_SIZE)CAN_STK_SIZE/10,
(CPU_STK_SIZE)CAN_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
OSTaskCreate((OS_TCB * )&WARINGTaskTCB,
(CPU_CHAR * )"WARING task",
(OS_TASK_PTR )WARING_task,
(void * )0,
(OS_PRIO )WARING_TASK_PRIO,
(CPU_STK * )&WARING_TASK_STK[0],
(CPU_STK_SIZE)WARING_STK_SIZE/10,
(CPU_STK_SIZE)WARING_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err);
OS_CRITICAL_EXIT();
}
//CAN????????
void CAN_task(void *p_arg)
{
OS_ERR err;
short mtemperature;
u8 key;
short temperature;
u8 humidity;
u8 define;
u8 snum=0;
u8 rnum=0;
u8 t=0;
u8 cnt=0;
u8 canbuf[8];
u8 res;
u8 mode=CAN_Mode_LoopBack; POINT_COLOR=DARKBLUE;//
LCD_ShowString(30,30,200,16,16,"CAN AND DS18B20");
LCD_ShowString(30,50,200,16,16,"KEY0:Send WK_UP:Mode");
LCD_ShowString(30,90,200,16,16,"Send Data Count:");
LCD_ShowString(30,110,200,16,16,"DS18B20: . C");
POINT_COLOR=BLACK;
LCD_ShowString(30,170,200,16,16,"Receive Data Count:");
LCD_ShowString(30,190,200,16,16,"Receive DS18b20: . C");
LCD_ShowString(30,230,200,16,16,"Receive DHT11: C");
LCD_ShowString(30,250,200,16,16,"Receive DHT11: %");
POINT_COLOR=RED;
while(DS18B20_Init())
{
LCD_ShowString(30,70,200,16,16,"DS18B20 Check Error");
delay_ms(200);
LCD_Fill(92,10,239,10+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,70,200,16,16,"DS18B20 Check OK");
while(1)
{
key=KEY_Scan(0);
if(t%10==0)
{
POINT_COLOR=GREEN;
mtemperature=DS18B20_Get_Temp();//就是这一步,mtemperature一直是0,但单独把这段程序拿出来在裸机跑,却可以正常显示。
if(mtemperature<0)
{
LCD_ShowChar(30+8*8,110,'-',16,0);
mtemperature=-mtemperature;
}else LCD_ShowChar(30+8*8,110,' ',16,0);
LCD_ShowNum(30+9*8,110,mtemperature/10,2,16); //??????????·?
LCD_ShowNum(30+9*8+32,110,mtemperature%10,1,16); //??????????·?
}
//·??????? key==KEY0_PRESS
if(cnt==40)//KEY0°???,·???????????
{
cnt=0;
POINT_COLOR=LBBLUE;
snum+=1;
LCD_ShowNum(30+16*8,90,snum,3,16);
canbuf[1]=mtemperature;//????·?????????
canbuf[0]=1; //??±????? 1 is DS18B20,2 is DHT11
canbuf[2]=0;
res=Can_Send_Msg(canbuf,3);//·???8??×???
POINT_COLOR= BRRED;
if(res)LCD_ShowString(30,130,200,16,16,"DS18B20 Send Data Err"); //?á??·????§°?
else LCD_ShowString(30,130,200,16,16,"DS18B20 Send Data Ok"); //?á??·???????
}
//????CAN?¤×÷????
if(key==KEYUP_PRESS)//WK_UP°???????±?CAN???¤×÷????
{
mode=!mode;
CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_9tq,4,mode);//CAN???¨??????????, ?¨????500Kbps
POINT_COLOR=RED;//?è??×??????ì??
if(mode==0)//???¨???????è??2????·?°?
{
LCD_ShowString(60,10,200,16,16,"Nnormal Mode ");
}else //???·????,??????·?°?????????????.
{
LCD_ShowString(60,10,200,16,16,"LoopBack Mode");
}
}
//????????
key=Can_Receive_Msg(canbuf);
if(key)//????????????
{
POINT_COLOR=BLUE;//?è??×?????????
rnum+=1;
LCD_ShowNum(30+19*8,170,rnum,3,16);
temperature=canbuf[1];
define=canbuf[0];
humidity=canbuf[2];
POINT_COLOR=GREEN;
//??????DS18B20????
if(define==1)
{
LCD_ShowString(30,210,200,16,16,"DS18B20 Receive Data ok");
LCD_Fill(30+16*8,190,30+16*8+3*8,190+16,WHITE);//?????®?°??????
if(temperature<0)
{
LCD_ShowChar(30+16*8,190,'-',16,0); //????????
temperature=-temperature; //×???????
}else LCD_ShowChar(30+16*8,190,' ',16,0); //????????
LCD_ShowNum(30+17*8,190,temperature/10,2,16); //??????????·?
LCD_ShowNum(30+17*8+32,190,temperature%10,1,16); //??????????·?
LCD_ShowString(30,270,200,16,16,"DHT111 is Lost ");
LCD_ShowNum(30+14*8,230,000,3,16); //????????
LCD_ShowNum(30+14*8,250,000,3,16); //????????
}
//??????DHT11????
else if(define==2)
{
POINT_COLOR=BROWN;
LCD_ShowString(30,270,200,16,16,"DHT11 Receive Data ok ");
LCD_ShowNum(30+14*8,230,temperature,3,16); //????????
LCD_ShowNum(30+14*8,250,humidity,3,16); //????????
LCD_ShowNum(30+17*8,190,000,2,16); //??????????·?
LCD_ShowNum(30+17*8+32,190,000,1,16); //??????????·?
LCD_ShowString(30,210,200,16,16,"DS18B20 is Lost ");
}
}
t++;
OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_HMSM_STRICT,&err); //???±10ms
if(t==20)
{
LED0=!LED0;//?á??????????????
t=0;
cnt++;
}
}
}
////WARING????????
void WARING_task(void *p_arg)
{
OS_ERR err;
p_arg = p_arg;
while(1)
{
//DS18B20?????ó??23??,·??ù?÷±¨??
if(Stemp/10>25)
{
OSTimeDlyHMSM(0,0,0,800,OS_OPT_TIME_HMSM_STRICT,&err); //???±800ms
BEEP=1;
OSTimeDlyHMSM(0,0,0,100,OS_OPT_TIME_HMSM_STRICT,&err); //???±100ms
BEEP=0;
}else BEEP=0;
// ????????DHT11???????ó??73%??LED1????±¨??
if(Shumidity>73)
{
OSTimeDlyHMSM(0,0,0,700,OS_OPT_TIME_HMSM_STRICT,&err); //???±700ms
LED1=0;
OSTimeDlyHMSM(0,0,0,100,OS_OPT_TIME_HMSM_STRICT,&err); //???±100ms
LED1=1;
}else LED1=1;
OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_HMSM_STRICT,&err); //???±500ms
}
}
[/mw_shl_code]
---------------------------------
学习了,厉害~~~~~
一周热门 更多>