📄 test.c
字号:
//--------------------------------------------------------------//
#include "config.h"
#define TASK_STK_SIZE 256 /* 定义任务堆栈大小 */
OS_STK TaskStartStk[TASK_STK_SIZE];
OS_STK TaskRSTStk[TASK_STK_SIZE];
OS_STK TaskRST1Stk[TASK_STK_SIZE];
#define iic 0
#define spi 1
void TaskStart(void *data);
void TaskRST(void *data);
void TaskRST1(void *data);
uint8 p1,p2;
uint8 cp_re1[200];
uint8 p0,p3;
uint8 cp_re0[200];
void Rest_WD(void)
{
//OS_ENTER_CRITICAL();
//WDFEED = 0xAA;
//WDFEED = 0x55;
//OS_EXIT_CRITICAL();
}
void WD_Ini(void)
{ //OS_ENTER_CRITICAL();
//WDTC = 0xFF000000;//6.0s
//WDMOD= 0x03;
//WDFEED = 0xAA;
//WDFEED = 0x55;
//OS_EXIT_CRITICAL();
}
//------------------------------------------------------------------//
//------------------------------------------//
//------------------------系统主函数--------------------------------------//
int main (void)
{
OSInit();
OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);// 创建任务
OSStart();
return 0;
}
//---------------------------任务创建 和串口接收函数-----------------------------------//
void TaskStart(void *pdata)
{
uint8 temp;
uint8 AT45db321[20];
uint8 Timer[8];
uint32 ii=0;
uint8 WenDu[2];
//uint16 xp_glm;
TargetInit(); // 目标板初始化
IO0SET = EN_220V;//GPRS上电
IO0CLR = EN_5V;
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
OSTaskCreate(TaskRST, (void *)0, &TaskRSTStk[TASK_STK_SIZE - 1], 8); //创建任务
OSTaskCreate(TaskRST1, (void *)0, &TaskRST1Stk[TASK_STK_SIZE - 1], 7); //创建任务
OSTimeDly(OS_TICKS_PER_SEC/20);
WD_Ini();
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/2);
IO0SET = Q1;
//IO0CLR = EN_5V;//GPRS上电
//OSTimeDly(OS_TICKS_PER_SEC/2);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;;
Rest_WD();
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
Rest_WD();
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
Rest_WD();
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
Rest_WD();
UART0Write((uint8 *)("it is Rset!"),11);
UART0Write((uint8 *)("it is uart0"),11);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
if( (IO0SET&BEE)==0)
IO0SET = BEE;
else
IO0CLR = BEE;
Rest_WD();
if( iic == 1 )
{
IIC_UART_Init(0);//包含复位芯片。
IIC_UART_Init(1);
OSTimeDly(OS_TICKS_PER_SEC/20);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
temp = IIC_Sendstr(0,(uint8 *)("it is uart2"),11);
Rest_WD();
temp = IIC_Sendstr(1,(uint8 *)("it is uart3"),11);
if( (IO0SET&BEE)==0)
IO0SET = BEE;
else
IO0CLR = BEE;
}
if(spi == 1)
{
Write_Memory(0,0,(uint8 *)("it is AT45db321"),15);
Rest_WD();
OSTimeDly(OS_TICKS_PER_SEC/20);
Read_Memory(0,0,AT45db321,15);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
OSTimeDly(OS_TICKS_PER_SEC/20);
Rest_WD();
UART0Write(AT45db321,15);
if( (IO0SET&BEE)==0)
IO0SET = BEE;
else
IO0CLR = BEE;
}
Rest_WD();
//------------------GPRS复位-----------------------//
IO0CLR = EN_5V;//GPRS上电
IO0SET = RST_GPRS;
OSTimeDly(OS_TICKS_PER_SEC/2);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
OSTimeDly(OS_TICKS_PER_SEC/2);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
IO0CLR = RST_GPRS;
if( (IO0SET&BEE)==0)
IO0SET = BEE;
else
IO0CLR = BEE;
//------------------GPRS复位-----------------------//
for( ; ; )
{
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
Rest_WD();
UART0Write((uint8 *)("it is GETTIME0 "),14);
GetTime(Timer);
//OSTimeDly(OS_TICKS_PER_SEC/5);
UART0Write((uint8 *)("it is GETTIME1 "),14);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
Rest_WD();
//UART0Write(Timer,7);
//UART0Write(AT45db321,15);
/*
xp_glm = Get_key();
WenDu[0] = (uint8)(xp_glm>>8);
WenDu[1] = (uint8)xp_glm;
UART0Write(WenDu,2);
*/
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
if( (IO0SET&LED1)==0)
IO0SET = LED1;
else
IO0CLR = LED1;
UART0Write((uint8 *)("-----------"),11);
UART0Write((uint8 *)("it is WENDU0 "),14);
IRcvStr(LM75A,0x00,WenDu,2);
UART0Write((uint8 *)("it is WENDU1 "),14);
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
for(ii=0;ii<50;ii++)
{
IO0CLR = Q1;
OSTimeDly(OS_TICKS_PER_SEC/5);
IO0SET = Q1;
}
//UART0Write(WenDu,2);
}
}
uint8 Num_lenth;
uint8 Num_lenth1;
void TaskRST(void *pdata)
{
uint8 temp;
//UART1Write((uint8 *)("it is uart1"),11);
//UART1Write((uint8 *)("-----------"),11);
for(;;)
{
if(UART0Getch(&temp,20)==OS_NO_ERR) // 接收串口0的数据
{
if(p0>=180);
else
{
cp_re0[p0++] = temp;
}
}
else // 超时(1次接受完成)且串口不忙
{
Num_lenth1 = p0;
p0 = 0;
if(Num_lenth1>1)
{
UART1Write(cp_re0,Num_lenth);
UART0Write(cp_re0,Num_lenth);
}
OSTimeDly(OS_TICKS_PER_SEC/100);
}
}
}
void TaskRST1(void *pdata)
{
//uint8 p1;
uint8 temp;
UART1Write((uint8 *)("it is uart1"),11);
UART1Write((uint8 *)("-----------"),11);
for(;;)
{
if(UART1Getch(&temp,20)==OS_NO_ERR) // 接收串口0的数据
{
if(p1>=180);
else
{
cp_re1[p1++] = temp;
}
}
else // 超时(1次接受完成)且串口不忙
{
Num_lenth = p1;
p1 = 0;
if(Num_lenth>1)
{
UART1Write(cp_re1,Num_lenth);
//
UART0Write(cp_re1,Num_lenth);
}
OSTimeDly(OS_TICKS_PER_SEC/100);
}OSTimeDly(OS_TICKS_PER_SEC/50);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -