Пример #1
0
//主函数执行
void main(){

    //初始化   
    initial_LCD();//uc1701x 显示屏初始化
 
    displayStr_5x7(0,0,"JKLMNOPQRSTUVWXYZ[\]^");
    DelayXms(600);
//    displayStr_5x7(0,0,"displayStr_5x7");
    DelayXms(600);
    displayStr_5x7(1,1,"displayStr_8x16");
    DelayXms(600);
    displayStr_8x16(4,0,"displayStr_5x7[\]^");
    DelayXms(600);
    while(1){
        
    }
}
Пример #2
0
/********************************************************************
函数功能:USB断开连接函数。
入口参数:无。
返    回:无。
备    注:无。
********************************************************************/
void UsbDisconnect(void)
{
#ifdef DEBUG0
 Prints("断开USB连接。\r\n");
#endif
 UDCON=0x01; //Disconnect pull-up resistor
 DelayXms(1000);  //延迟1秒
}
Пример #3
0
/********************************************************************
函数功能:USB断开连接函数。
入口参数:无。
返    回:无。
备    注:无。
********************************************************************/
void UsbDisconnect(void)
{
#ifdef DEBUG0
 Prints("断开USB连接。\r\n");
#endif
 *AT91C_PIOA_SODR=(1<<16); //Disconnect pull-up resistor
 DelayXms(1000);  //延迟1秒
}
Пример #4
0
/********************************************************************
函数功能:USB断开连接函数。
入口参数:无。
返    回:无。
备    注:无。
********************************************************************/
void UsbDisconnect(void)
{
#ifdef DEBUG0
    Prints("断开USB连接。\r\n");
#endif
    D12WriteCommand(D12_SET_MODE);  //写设置模式命令
    D12WriteByte(0x06); //设置模式的第一字节
    D12WriteByte(0x47); //设置模式的第二字节
    DelayXms(1000);  //延迟1秒
}
Пример #5
0
void Delay1ms(WORD wValue)
{
    WORD wCount; // loop counter
   extern 	void DelayXms(WORD td) ;
DelayXms(wValue);
return;
    while (wValue--)
    {
        wCount = DELAY_1MS_PERIOD; // reset loop counter
        //wCount = g_ucTestCnt; // reset loop counter

      //  WatchDogClear();
        while (wCount--) ;
    } // while
}
Пример #6
0
/*
************************************************************
*	函数名称:	ADCx_GetValueTimes
*
*	函数功能:	获取多次ADCx的值,并求平均值
*
*	入口参数:	ADCx:ADC设备
*				ch:通道
*				times:次数
*
*	返回参数:	电压平均值
*
*	说明:		ADC_Channel_1~ADC_Channel_16
************************************************************
*/
unsigned short ADCx_GetValueTimes(ADC_TypeDef *ADCx, unsigned char ch, unsigned char times)
{

	float adcValue = 0;
	unsigned char i = 0;
	
	for(; i < times; i++)
	{
		adcValue += (float)ADCx_GetValue(ADCx, ch);
		DelayXms(5);
	}
	
	return (unsigned short)(adcValue / times);

}
Пример #7
0
void SwitchADport(BYTE adport)
{
    if(F_ADOK == 0)return;
    //	DBG(printf("sw to Port( %bd )",g_CurrentADport));
    if(adport == 0xff)
    {
        g_CurrentADport++;

        if(g_CurrentADport >= MAXNUMBER_PORT_AD)
            g_CurrentADport = MINNUMBER_PORT_AD;
    }
    else g_CurrentADport = adport;


    adport = g_CurrentADport;
    EIE1 &= ~0x08;
    AD0INT = 0;
    AD0EN = 0;

    if(adport == ADPORT_TempaSensor)
    {
        ADC0MX = 0x10;
    }
    else if(adport == ADPORT_BAT)
    {
        ADC0MX = 0x08;
    }
    else if(adport == ADPORT_POWER)
    {
        ADC0MX = 0x07;
    }
    else if(adport == ADPORT_SENSOR)
    {
        ADC0MX = 0x0C;
    }

    DelayXms(1);
    F_ADInit = 1;
    F_ADOK = 0;
    AD0EN = 1;
    EIE1 |= 0x08;


}
Пример #8
0
void Init_LCD(void)
{
	U8 i;
	PO_LCD_POWER(P_LCD_ON);
	DelayXms(20);
	DisBuffer[0]=CHAR_DASH;
	DisBuffer[1]=CHAR_DASH;
	DisBuffer[2]=CHAR_DASH;
	DisBuffer[3]=CHAR_DASH;

	
	for(i=0;i<TBL_SIZE(LCD_buf);i++)LCD_buf[i]=0;
	SendLCDByte(LCD_MODE);
	SET_STB();
	BUZZY_OFF();

	
	
	
}
Пример #9
0
/*
************************************************************
*	函数名称:	ADXL345_Init
*
*	函数功能:	ADXL345初始化配置
*
*	入口参数:	无
*
*	返回参数:	无
*
*	说明:		
************************************************************
*/
void ADXL345_Init(void)
{
	
    unsigned char devid = 0, val = 0;

    DelayUs(300);

    I2C_ReadByte(ADXL345_ADDRESS, 0x00, &devid);			//读ID	且每次读写之前都需要读ID
	DelayUs(300);

	val = 0x2B;
    I2C_WriteByte(ADXL345_ADDRESS, DATA_FORMAT_REG, &val);	//低电平中断输出,13位全分辨率,输出数据右对齐,16g量程
	DelayUs(50);
    
	val = 0x0A;
    I2C_WriteByte(ADXL345_ADDRESS, BW_RATE, &val);			//数据输出速度为100Hz
	DelayUs(50);
    
	val = 0x28;
    I2C_WriteByte(ADXL345_ADDRESS, POWER_CTL, &val);		//链接使能,测量模式
	DelayUs(50);
    
	val = 0;
    I2C_WriteByte(ADXL345_ADDRESS, INT_ENABLE, &val);		//不使用中断
	DelayUs(50);
	
    DelayXms(20);
	
	//软件偏移校准,视上电时为平放状态,x=0,y=0,z=1=====================
	ADXL345_GetValue();
	
	ofz_X = 0 - adxlInfo.incidence_X;
	ofz_Y = 0 - adxlInfo.incidence_Y;
	ofz_Z = 256 - adxlInfo.incidence_Z;

}
Пример #10
0
//对STC15系列的芯片进行数据下载程序
static int Firmware_Download(BYTE *pdat, long size)
{
    BYTE arg;
    BYTE cnt;
    WORD addr;
	
    Initial();
	
    //握手
    CommInit();
    while (1)
    {
        if (UartRecvStep == 0)
        {
            UartSend(0x7f);
            DelayXms(10);
        }
        if (UartReceived)
        {
            arg = RxBuffer[4];
            if (RxBuffer[0] == 0x50) 
				break;
            return eDownloadErrCodeHandshake;
        }		
        if (TimeOut == 0) {
			printf("waiting for mcu isp timeout\n");
			return eDownloadErrCodeTimeout;
        }
    }

	printf("set comm param\n");

    //设置参数
    TxBuffer[0] = 0x01;
    TxBuffer[1] = arg;
    TxBuffer[2] = 0x40;
	TxBuffer[3] = HIBYTE(RL(MAXBAUD));
	TxBuffer[4] = LOBYTE(RL(MAXBAUD));
	TxBuffer[5] = 0x00;
	TxBuffer[6] = 0x00;
	TxBuffer[7] = 0xc3;
    CommSend(8);
	while (1)
	{
        if (TimeOut == 0) return eDownloadErrCodeTimeout;
        if (UartReceived)
        {
            if (RxBuffer[0] == 0x01) break;
            return eDownloadErrCodeSetCommParam;
        }
	}

	printf("download prepare \n");

    //准备
    serialport_config(handle_download_port,MAXBAUD,8,1,'e');
    DelayXms(10);
	TxBuffer[0] = 0x05;
	CommSend(1);
	while (1)
	{
        if (TimeOut == 0) return eDownloadErrCodeTimeout;
        if (UartReceived)
        {
            if (RxBuffer[0] == 0x05) break;
            return eDownloadErrCodeSetCommParam;
        }
	}
    
	printf("erase flash ...\n");
    //擦除
    DelayXms(10);
	TxBuffer[0] = 0x03;
	TxBuffer[1] = 0x00;
	CommSend(2);
    TimeOut = 100;
    while (1)
	{
        if (TimeOut == 0) return eDownloadErrCodeTimeout;
        if (UartReceived)
        {
            if (RxBuffer[0] == 0x03) break;
            return eDownloadErrCodeEraseFlash;
        }
	}

	printf("program flash size[0x%lx]...\n",size);

    //写用户代码
    DelayXms(10);
    addr = 0;
	TxBuffer[0] = 0x22;
	while (addr < size)
	{
        TxBuffer[1] = HIBYTE(addr);
        TxBuffer[2] = LOBYTE(addr);
        cnt = 0;
        while (addr < size)
        {
            TxBuffer[cnt+3] = pdat[addr];
            addr++;
            cnt++;
            if (cnt >= 128) break;
        }
        CommSend(cnt + 3);
		while (1)
		{
            if (TimeOut == 0) return eDownloadErrCodeTimeout;
            if (UartReceived)
            {
                if ((RxBuffer[0] == 0x02) && (RxBuffer[1] == 'T')) break;
                return eDownloadErrCodeProgramFlash;
            }
		}
		TxBuffer[0] = 0x02;
	}

	printf("program hardware option ... skipped\n");

	#if 0
    //写硬件选项(如果不需要修改硬件选项,此步骤可直接跳过)
    DelayXms(10);
    for (cnt=0; cnt<128; cnt++)
    {
        TxBuffer[cnt] = 0xff;
	}
	//Do we know details of hardware options???
    TxBuffer[0] = 0x04;
	TxBuffer[1] = 0x00;
	TxBuffer[2] = 0x00;
	TxBuffer[34] = 0xfd;
	TxBuffer[62] = arg;
	TxBuffer[63] = 0x7f;
	TxBuffer[64] = 0xf7;
	TxBuffer[65] = 0x7b;
	TxBuffer[66] = 0x1f;
	CommSend(67);
	while (1)
	{
        if (TimeOut == 0) return eDownloadErrCodeTimeout;
        if (UartReceived)
        {
            if ((RxBuffer[0] == 0x04) && (RxBuffer[1] == 'T')) break;
            return eDownloadErrCodeProgramOption;
        }
	}
	#endif

    //下载完成
    return eDownloadErrCodeSuccess;
}
Пример #11
0
////////////////////////////////////////////////////////////////////////////
///////////////
// 函数名:
// 编写者:
// 参考资料:
// 功 能:
// 输入参数:
// 输出参数:
// 备 注:
////////////////////////////////////////////////////////////////////////////
///////////////
void Init_EPROM()
{    BYTE   buf,retrycount=3;
	_SYSINFO  tmpsysinfo;//={0,0};
	
	WORD sum;
	BOOL eepok;
    extern BYTE   Jdispidx;
	DelayXms(300);
	Jiulist.idx=0-1;
	for(buf=0;buf<MAX_JIULST;buf++ )Jiulist.Jvol[buf]=0xffff;
	return;
#ifndef NVRAM_USE_EEP24CXX
	do
	{
	FLASH_Read(&buf,(FLADDR)EEPROM_ID,1);
	FLASH_Read((BYTE*)&tmpsysinfo,(FLADDR)(EEP_SYS_TBLSTART),EEP_SYS_LENTH) ;
	sum= CalChkSum((BYTE*)&tmpsysinfo,  EEP_SYS_LENTH);
	if((buf==BOARD_ID_VER)&&(sum==tmpsysinfo.chksum)){eepok=1;break;}
	DelayXms(300);
	}while(retrycount--) ;
	
	if(eepok)
#endif
	{ //read from flash

	  	FLASH_Read((BYTE*)&SysInfo,(FLADDR)(EEP_SYS_TBLSTART),EEP_SYS_LENTH) ;
		FLASH_Read((BYTE*)&Jiulist,(FLADDR)(EEP_JIULST_TBLSTART),EEP_JIULST_LENTH) ;
	
		
	}
#ifndef NVRAM_USE_EEP24CXX
	else
	{
		DisplayCont=DISPLAY_ERR0;Display_All();	   //显示初始错误
	//初始数据
		SysInfo.TRANCODE=0x5555;
		SysInfo.ADJUST=0;
		SysInfo.VA=(WORD)((DWORD)DEFAULT_NOCOAL_VA*1024/STANDARD_REF_VOLT);		//校准
   		SysInfo.VB=(WORD)((DWORD )DEFAULT_NOCOAL_VB*1024/STANDARD_REF_VOLT);		//校准
		SysInfo.VC=(WORD)((DWORD)DEFALT_130PPM_VC*1024/STANDARD_REF_VOLT); //130PPM
		SysInfo.chksum=CalChkSum((BYTE*)&SysInfo,  EEP_SYS_LENTH);		
		FLASH_Update((FLADDR)EEP_SYS_TBLSTART,(BYTE*)&SysInfo,EEP_SYS_LENTH);
		DPRINTF(printf("-----InitEPROM-----...\r\n"))	 ;
	    FLASH_Update((FLADDR)EEP_JIULST_TBLSTART,(BYTE*)&Jiulist,EEP_JIULST_LENTH);
		buf= BOARD_ID_VER;
		FLASH_Update((FLADDR)EEPROM_ID,(BYTE *)&buf,1) ;
	
	  

	}
#endif
	//初始化变量
	{

	if(Jiulist.idx>=MAX_JIULST)Jiulist.idx=0-1;
	Jdispidx=Jiulist.idx;

	}
	
	
}
Пример #12
0
 ////////////////////////////////////////////////////////////////////////////
///////////////
// 函数名:
// 编写者:
// 参考资料:
// 功 能:
// 输入参数:
// 输出参数:
// 备 注:
////////////////////////////////////////////////////////////////////////////
///////////////
void main (void)
{	PCA0MD &= ~0x40;                    // Disable Watchdog timer
	Init_VAR();
	Init_Device();
	Init_patch();
	BUZZY_OFF();
	Init_sensor();
	P1MDOUT&=~0x06;	//p11 p12 非推挽	 LCD时钟数据和加密
	P1MDOUT&=~0x40;	//p16 非推挽	LCD选通
	P1MDOUT&=~0x80;	//p17 非推挽  LCD电源总开开关
	P1MDOUT&=~0x20;	//p15 非推挽	LCD选通
#ifdef	SECURE_SPI
	P0MDOUT&=~0x80;	//p07 非推挽   //加密MCLK
	P07=1;
#endif
	P0MDOUT&=~0x20;  //充满检测 ,高:充满或未冲  低:充电
	P1|=0x46;	  //srb clk data 
	PO_LCD_POWER(P_LCD_ON);
	Init_LCD();
	Init_EPROM();
#ifdef	SECURE_SPI
  {extern void InitSPICom(void) ;
	extern char TEST_SPI(char CMD_a);
	BYTE tryc=3;
	InitSPICom()  ;
	F_demo=1;
	do
	 {
		if(1==TEST_SPI(CMD_RD_ID))
		{	
		F_demo=0;
		break;
		}
		
		DelayXms(300);

	}while(tryc--)	 ;
	if(1==F_demo)
	{	
		
		DisplayCont=DISPLAY_DEMO;
		Display_All();	   //显示初始错误

	}

	}
	
#endif
	DPRINTF(printf("MAIN Program\n" ))	 ;
#if 0
	if(PI_ADJUST_DET())
	{
	  DelayXms(100);
	  if(PI_ADJUST_DET())	
	  NEW_KEY= KEY_ADJUST;
	  
	}
#endif
#if 1
	if(PWR_G2==0)
	{ 
	  	diaplay_std ();
	    DelayXms(3000);
	}
#endif
	while(1)
	{
		
	   {
//WORD i  ;extern 	  BYTE StateSensor	  ;
//     	if(StateSensor==-1)
//		LEDIO=!LEDIO;
		}
		if(F_5ms)
		{
		F_5ms=0;
	    if(PWR_G1==0)	{StateSensor=0;}
	{extern void TestACHOL();
		  TestACHOL();	
			
		}

		}
	//	if(F_10ms)
	//	{
	//		F_10ms=0;

	//	}
		if(F_50ms)
		{	F_50ms=0;
			
			Task_50ms();

			
			
		}
		if(F_100ms)
		{  
			F_100ms=0;
	/*		

		{extern void TestACHOL();
		  TestACHOL();	
			
		}
*/
		   {	
		    extern WORD CountHeat;	
		    if(CountHeat<=350)
			{
			  CountHeat++;
			} 
			}
			DO_Key_Action()	 ;
			Display_All();
			{
			extern void SendCycbuf(void);
			SendCycbuf();

			}
		    
			
		}
		if(F_200ms)
		{	 
			

			F_200ms=0; 
			
			
		}
		if(F_500ms)
		{	F_500ms=0;
			
			 
			
		}
		
		if(F_1000ms)
		{
		//	DPRINTF(printf("time=%bd \n" ,sys_time.Time_1_sec))	 ;
		 Task_500ms();
		}
		
		
	}
	
}