|
/******************************************************************************
|
* Copyright (C) 2014-2015 HangZhou SiZhu Co.,LTD.
|
*
|
*-----------------------------------------------------------------------------
|
* File: TEST.c
|
* Description: test code used for test all hardware
|
* Author: Lishoujian (867693272@qq.com)
|
* Date: Jan 8, 2015
|
*****************************************************************************/
|
|
/* ----------------------- Platform includes --------------------------------*/
|
#include "TEST.h"
|
|
|
/******************************************
|
* func: AD421_test
|
* desc: code used for test all function of ad421
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void AD421_test(void)
|
{
|
float fp_i = 3.5;
|
|
AD421_ioconfig();//config gpio;initialize hardware interface of ad421
|
|
AD421_output(10.000);
|
|
while(1)
|
{
|
delay_ms(300);
|
AD421_output(fp_i);
|
fp_i += 0.500;
|
if(fp_i > 24.000) fp_i = 3.500;
|
delay_ms(300);
|
}
|
}
|
|
/******************************************
|
* func: Error_test
|
* desc: code used for test all function of error output
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void Error_test(void)
|
{
|
Error_ioconfig();//config gpio;initialize hardware interface of ad421
|
while(1)
|
{
|
Error_out(0,0);
|
delay_ms(10);
|
|
Error_out(1,0);
|
delay_ms(10);
|
|
Error_out(0,1);
|
delay_ms(10);
|
|
Error_out(1,1);
|
delay_ms(10);
|
}
|
}
|
|
/******************************************
|
* func: FM25V02_test
|
* desc: code used for test all function of fram FM25V02
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void FM25V02_test(void)
|
{
|
vuint8 buf[100] = {0},idbuf[9]={0};
|
uint8 addr,i = 0x01;
|
|
FM25V02_ioconfig();//config gpio;initialize hardware interface of FM25V02
|
FM25V02_ID_read((uint8 *)idbuf);//read 9 bytes id
|
delay_ms(100);
|
while(1)
|
{
|
addr = 0;
|
while(addr < 100)
|
{
|
buf[addr] = FM25V02_data_read(addr);
|
addr ++;
|
}
|
|
addr = 0;
|
while(addr < 100)
|
{
|
FM25V02_data_write(addr,addr);
|
addr ++;
|
}
|
|
addr = 0;
|
while(addr < 100)
|
{
|
buf[addr] = FM25V02_data_read(addr);
|
addr ++;
|
}
|
|
addr = 0;
|
while(addr < 100)
|
{
|
FM25V02_data_write(i,addr);
|
addr ++;
|
}
|
i++;
|
delay_ms(100);
|
}
|
}
|
|
/******************************************
|
* func: PWM_test
|
* desc: PWM output code
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void PWM_test(void)
|
{
|
PWM_ioconfig();
|
while(1)
|
{//PWM1_out(uint16 period,uint16 count,uint8 div);
|
PWM1_out(1000,500,71);
|
delay_ms(100);
|
PWM1_standby(0);
|
delay_ms(100);
|
|
PWM1_out(2000,500,71);
|
delay_ms(100);
|
PWM1_standby(1);
|
delay_ms(100);
|
|
PWM2_out(1000,500,71);
|
delay_ms(100);
|
PWM2_standby(0);
|
delay_ms(100);
|
|
PWM2_out(2000,500,71);
|
delay_ms(100);
|
PWM2_standby(1);
|
delay_ms(100);
|
}
|
}
|
|
/******************************************
|
* func: OLED_test
|
* desc: OLED disp code
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void OLED_test(void)
|
{
|
uint8 count;
|
OLED_init();
|
while(1)
|
{
|
OLED_clear();
|
delay_ms(100);
|
for(count = 0;count < 20;count ++)
|
{
|
OLED_setdispaddr(0,count);
|
OLED_disponechar('0'+count);
|
}
|
delay_ms(100);
|
for(count = 0;count < 20;count ++)
|
{
|
OLED_setdispaddr(1,count);
|
OLED_disponechar(('a'+count));
|
}
|
delay_ms(100);
|
for(count = 0;count < 10;count ++)
|
{
|
OLED_clear();
|
delay_ms(100);
|
OLED_setdispaddr(0,(count << 1));
|
OLED_wr_string("&&");
|
delay_ms(100);
|
}
|
for(count = 0;count < 10;count ++)
|
{
|
OLED_clear();
|
delay_ms(100);
|
OLED_setdispaddr(1,(count << 1));
|
OLED_wr_string("**");
|
delay_ms(100);
|
}
|
}
|
}
|
|
/******************************************
|
* func: KEY_test
|
* desc: used for test key
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void KEY_test(void)
|
{
|
uint8 count = 0,keybufs[3]={1,1,1};
|
uint32 keytemp32;
|
|
OLED_init();
|
OLED_clear();
|
|
OLED_setdispaddr(0,0);
|
OLED_wr_string("KEY1:1 KEY2:1 KEY3:1");
|
KEY_ioconfig();
|
|
while(1)
|
{
|
keytemp32 = Get_key();
|
for(count = 0;count < 3;count ++)
|
{
|
if((keytemp32 >> (8 * count)) & 0xff)
|
{
|
if( !keybufs[count] )
|
{
|
OLED_setdispaddr(0,5+7*count);
|
OLED_disponechar('1');
|
keybufs[count] = 0x01;
|
}
|
}
|
else
|
{
|
if( keybufs[count] )
|
{
|
OLED_setdispaddr(0,5+7*count);
|
OLED_disponechar('0');
|
keybufs[count] = 0x00;
|
}
|
}
|
}
|
delay_ms(50);
|
}
|
}
|
|
/******************************************
|
* func: PRESSURE_test
|
* desc: used for test voltage sampled from PRESSURE sensor
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void PRESSURE_test(void)
|
{
|
uint8 dispbuf[4],temp8=0;
|
uint16 temp16;
|
|
Pressure_Init();
|
|
OLED_init();
|
OLED_clear();
|
|
OLED_setdispaddr(0,0);
|
OLED_wr_string("pres volt:0.000 v");
|
OLED_setdispaddr(1,0);
|
OLED_wr_string("pres data:01.0 bar");
|
while(1)
|
{
|
temp16 = Get_pressure_volt();
|
temp16 = temp16 / op;
|
dispbuf[0] = temp16 / 1000;
|
dispbuf[1] = (temp16 % 1000 ) / 100;
|
dispbuf[2] = (temp16 % 100 ) / 10;
|
dispbuf[3] = temp16 % 10;
|
|
OLED_setdispaddr(0,10);
|
OLED_disponechar(0x30 + dispbuf[0]);
|
OLED_setdispaddr(0,12);
|
OLED_disponechar(0x30 + dispbuf[1]);
|
OLED_setdispaddr(0,13);
|
OLED_disponechar(0x30 + dispbuf[2]);
|
OLED_setdispaddr(0,14);
|
OLED_disponechar(0x30 + dispbuf[3]);
|
|
temp16 = Get_pressure(temp16);
|
dispbuf[0] = temp16 / 100;
|
dispbuf[1] = (temp16 % 100 ) / 10;
|
dispbuf[2] = temp16 % 10;
|
|
OLED_setdispaddr(1,10);
|
OLED_disponechar(0x30 + dispbuf[0]);
|
OLED_setdispaddr(1,11);
|
OLED_disponechar(0x30 + dispbuf[1]);
|
OLED_setdispaddr(1,13);
|
OLED_disponechar(0x30 + dispbuf[2]);
|
|
delay_ms(100);
|
OLED_setdispaddr(0,19);
|
temp8 = ~temp8;
|
if(temp8)
|
{
|
OLED_disponechar('*');
|
}
|
else
|
{
|
OLED_disponechar(' ');
|
}
|
}
|
}
|
|
/******************************************
|
* func: TEMPERATURE_test
|
* desc: used for test voltage sampled from TEMPERATURE sensor
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void TEMPERATURE_test(void)
|
{
|
uint8 table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00,0xff};
|
uint16 tep_vol,temp;
|
volatile int16 tep;
|
Adc_Init();
|
OLED_init();
|
OLED_cgr_set(table);
|
OLED_setdispaddr(0,0);
|
OLED_wr_string("tep volt:0.000 v");
|
OLED_setdispaddr(1,0);
|
OLED_wr_string("tep data: 00.0 ");
|
OLED_disponechar(0x00);
|
while(1)
|
{
|
tep_vol = Get_temperature_volt();
|
tep = Get_temperature(tep_vol);
|
delay_ms(10);
|
OLED_setdispaddr(0,9);
|
temp = tep_vol/1000;
|
OLED_disponechar(temp+'0');
|
OLED_setdispaddr(0,11);
|
temp = tep_vol%1000;
|
OLED_disp_num(temp,3,1);
|
OLED_setdispaddr(1,10);
|
if(tep<(-50)||tep>(550))
|
{
|
OLED_wr_string("out ");
|
}
|
else
|
{ if(tep<0)
|
{ OLED_disponechar('-');
|
temp = (-tep)/10;
|
OLED_disponechar(temp+'0');
|
tep += (temp*10);
|
tep = (-tep);
|
}
|
else
|
{
|
temp = tep/10;
|
OLED_setdispaddr(1,10);
|
OLED_disp_num(temp,2,0);
|
}
|
OLED_disponechar('.');
|
tep%=10;
|
OLED_disponechar(tep+'0');
|
OLED_disponechar(' ');
|
OLED_disponechar(0x00);
|
}
|
}
|
}
|
|
/******************************************
|
* func: AD7302_test
|
* desc: used for test ad7302 (FSMC + DA)
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void AD7302_test(void)
|
{
|
uint8 i;
|
FSMC_ioconfig();
|
for(i=0;i<255;i++)
|
{
|
AD7302_VOUTA(i);
|
// AD7302_VOUTB(i);
|
delay_ms(10);
|
}
|
while(1);
|
}
|
|
/******************************************
|
* func: PRESSURE_test
|
* desc: used for test ad9203 voltage sample(FSMC + AD + DMA)
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void AD9203_test(void)
|
{
|
uint16 i,n,temp16;
|
FSMC_ioconfig();
|
DMA_Configuration();
|
while(1)
|
{
|
DMA_Cmd(DMA1_Channel2, ENABLE);
|
while(DMA_GetFlagStatus(DMA1_FLAG_TC2)!=SET)
|
{}
|
DMA_ClearFlag(DMA1_FLAG_TC2);
|
DMA_Cmd(DMA1_Channel2, DISABLE);
|
|
|
for(i=0;i<1000;i++)
|
{
|
SendBuff[i] &= 0x3ff;
|
}
|
|
i = 0;
|
|
while(i < 1000)
|
{
|
for(n=(i+1);n<1000;n++)
|
{
|
if(SendBuff[n] > SendBuff[i])
|
{
|
temp16 = SendBuff[i];
|
SendBuff[i] = SendBuff[n];
|
SendBuff[n] = temp16;
|
}
|
}
|
i++;
|
}
|
|
delay_ms(10);
|
}
|
}
|
|
/******************************************
|
* func: GP22_test
|
* desc: used for test gp22 send pulse & reveive ultrasonic wave
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
/*void GP22_test(void)
|
{
|
uint16 buf;
|
uint8 Num_Count;
|
//offset = 35mv + 2pulse+µÚÒ»²¨¼ì²â+¾§ÕñÒ»Ö±¿ªÆô==>
|
volatile uint32 REG_CONFIG_BUF[7]={0X2917E800,0X21444000,0X201F4000,0x5040C200,0x10004F00,0x40000000,0xC0C06000};//¾§ÕñÒ»Ö±¿ªÆô
|
SPI2_ioconfig();
|
GP22_ioconfig();
|
buf=GP22_Init();
|
delay_ms(50);
|
|
for(Num_Count = 0;Num_Count < 7;Num_Count ++)
|
{
|
GP22_WriteReg(Num_Count,REG_CONFIG_BUF[Num_Count]);
|
delay_ms(50);
|
}
|
|
GP22_Only_Cmd(0x70);
|
delay_ms(50);
|
// FirePulseEn_Enable();
|
delay_ms(50);
|
while(1)
|
{
|
// Start_TOF();
|
delay_ms(100);
|
}
|
}
|
*/
|
/******************************************
|
* func: PRESSURE_test
|
* desc: used for test rs232 communication
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void RS232_test(void)
|
{
|
uint8 sendbuf[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
|
uint8 receivebuf[20];
|
uint8 len;
|
|
RS232_ioconfig(USART2);
|
RS232_Send_Data(USART2,sendbuf,2);
|
delay_ms(10);
|
while(1)
|
{
|
RS232_Receive_Data(receivebuf,&len);
|
delay_ms(10);
|
}
|
}
|
|
/******************************************
|
* func: RS485_test
|
* desc: used for test rs485 communication
|
* input: none
|
* output: none
|
* return: none
|
*****************************************/
|
void RS485_test(void)
|
{
|
uint8 sendbuf[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
|
uint8 receivebuf[20];
|
uint8 len;
|
|
// RS485_ioconfig(UART4);
|
// RS485_Send_Data(UART4,sendbuf,10);
|
|
|
RS485_Send_Data(sendbuf,10);
|
|
// RS485_ioconfig(USART1);
|
// RS485_Send_Data(USART1,sendbuf,10);
|
delay_ms(10);
|
while(1)
|
{
|
// RS485_Receive_Data(receivebuf,&len);
|
delay_ms(10);
|
}
|
}
|