Beispiel #1
0
void Write1302(uint8_t addr,uint8_t data)
{
  DS1302_OUT();
	DS1302_RST_L();
	DS1302_CLK_L();
	DS1302_RST_H();
	delay_nus(4); 
	DS1302SendByte(addr);
	DS1302SendByte(data);
	delay_nus(4); 
	DS1302_CLK_H();
	DS1302_RST_L();
}
Beispiel #2
0
uint8_t DS1302ReceiveByte(void)
{
	uint8_t	i,byte=0;
	delay_nus(2);  
	for(i=0x01;i;i<<=1)
	{
		if(DS1302_IN_X)	byte |= i;
		DS1302_CLK_H();
		delay_nus(2);  
		DS1302_CLK_L();
		delay_nus(2); 
	}
	return(byte);
}
Beispiel #3
0
/********************************************************************************************************
* 函 数 名 :  void Display_LedNum(u8 leddata) 
* 描    述 : 数码管显示数字
* 输入参数 : 待显示数据.
* 输出参数 : None.
* 返   回  : None.
********************************************************************************************************/
void Display_LedNum(u16 LedData)  
{
  u32 i=9,j=0,k=0,sngtmp=0;
  
  if(LedData==0)
  {
    Hex_test(8,0);
  }
  else
  {
      while(LedData>0)
      {
        if(sngtmp%500==0)
        {
          j=LedData%10;
          LedData=LedData/10;
          i--;
        }
        Hex_test(i,j);
        sngtmp++;
        k++;
      }
      delay_nus(2000);
  }
}
Beispiel #4
0
/*
 *    读数据函数
 *    输入参数:  无
 *    输出参数:  无
 *    返回参数:  读取的数据
 *
 */
unsigned char DS18B20_Read(void)
{
    unsigned char rdData;     //读出的数据
    unsigned char i, dat;     //临时变量
    
    rdData = 0;               //读出的数据初始化为0     
    
    /* 每次读一位,读8次 */
    for(i=0; i<8; i++)
    {
        CL_DQ();            //IO拉低
        SET_DQ();           //IO拉高
        SET_IN();           //设置IO方向为输入 DS18B20->CC2540
        dat = DQ;           //读数据,从低位开始
        
        if(dat)
        {
          rdData |= (1<<i); //如果读出的数据位为正
        }
        else
        {
          rdData &= ~(1<<i);//如果读出的数据位为负
        }
        
        delay_nus(70);      //保持60~120us
        SET_OUT();          //设置IO方向为输出 CC2540->DS18B20

    }
    return (rdData);        //返回读出的数据
}
Beispiel #5
0
void ADC1_2_IRQHandler(void)
{
  ADCReData=ADC_GetConversionValue(ADC2);
  
  ADCInt=340*ADCReData/4096;
  
  
   delay_nus(10000);
   if(ADCInt>100)
   {
   Display_LedNum(ADCInt);
   GPIO_SetBits(GPIOC, HEX_D7);
   }
   else
   {
     if(ADCInt<10)
     {
       Hex_test(7,0);
     }
     Display_LedNum(ADCInt);
     Hex_test(6,0);
     GPIO_SetBits(GPIOC, HEX_D7);
   }
       
  ADC_ClearITPendingBit(ADC2,ADC_IT_EOC);
}
Beispiel #6
0
void DS1302SendByte(uint8_t byte)
{
	uint8_t	i;
	DS1302_CLK_L();           //拉低SCLK,为脉冲上升沿写入数据做好准备
  delay_nus(2);        //稍微等待,使硬件做好准备
	for(i=0x01;i;i<<=1)
	{
		if(byte&i)	
		DS1302_OUT_H();
		else	
			DS1302_OUT_L();
		delay_nus(2);      
		DS1302_CLK_H();
		delay_nus(2); 
		DS1302_CLK_L();
	}
}
Beispiel #7
0
uint8_t Read1302(uint8_t addr)
{
    uint8_t data=0;

    DS1302_OUT();
	DS1302_RST_L();
	DS1302_CLK_L();
	DS1302_RST_H();
	delay_nus(4); 
	DS1302SendByte(addr|0x01);
	DS1302_IN();
	delay_nus(4);
	data = DS1302ReceiveByte();
	delay_nus(4); 
	DS1302_CLK_H();
	DS1302_RST_L();
	return(data);
}
Beispiel #8
0
/*
 *    DS18B20初始化/复位函数
 *    输入参数:  无
 *    输出参数:  无
 *    返回参数:  无
 *
 */
void DS18B20_Init(void)
{
    SET_OUT();
    SET_DQ();         //IO口拉高
    CL_DQ();          //IO口拉低
    delay_nus(550);   //IO拉低后保持一段时间 480-960us
    SET_DQ();         //释放
    SET_IN();         //IO方向为输入 DS18B20->CC2540
    delay_nus(40);    //释放总线后等待15-60us
    
    /* 等待DQ变低 */
    while(DQ)
    {
        ; 
    }
    delay_nus(240);   //检测到DQ 变低后,延时60-240us
    SET_OUT();        //设置IO方向为输出 CC2540->DS18B20
    SET_DQ();         //IO拉高
}
Beispiel #9
0
/*
写时间函数,顺序为:年周月日时分秒
*/
void WriteDS1302Clock(uint8_t *p)
{
	Write1302(DS1302_WRITE,0x00);		//关闭写保护
	DS1302_OUT();
	DS1302_RST_L();
	DS1302_CLK_L();
	DS1302_RST_H();
	delay_nus(4); 
	DS1302SendByte(0xbe);				//突发模式
	DS1302SendByte(p[5]);				//秒
	DS1302SendByte(p[4]);				//分
	DS1302SendByte(p[3]);				//时
	DS1302SendByte(p[2]);				//日
	DS1302SendByte(p[1]);				//月
	DS1302SendByte(0x01);				//周,设置成周一,没有使用
	DS1302SendByte(p[0]);				//年
	DS1302SendByte(0x80);				//保护标志字节
	delay_nus(4); 
	DS1302_RST_L();
}
Beispiel #10
0
/*
读时间函数,顺序为:年周月日时分秒
*/
void ReadDS1302Clock(uint8_t *p)
{
	DS1302_OUT();
	DS1302_RST_L();
	DS1302_CLK_L();
	DS1302_RST_H();
	delay_nus(4); 
	DS1302SendByte(0xbf);			//突发模式
	DS1302_IN();
	p[5] = DS1302ReceiveByte();		//秒
	p[4] = DS1302ReceiveByte();		//分
	p[3] = DS1302ReceiveByte();		//时
	p[2] = DS1302ReceiveByte();		//日
	p[1] = DS1302ReceiveByte();		//月
	DS1302ReceiveByte();			//周
	p[0] = DS1302ReceiveByte();		//年
	DS1302ReceiveByte();			//保护标志字节
	delay_nus(4); 
	DS1302_RST_L();
}
Beispiel #11
0
void function3(void)
{
    u16 i;
    extern unsigned char send;
    /* Enable the USART Receive interrupt: this interrupt is generated when the
    USART1 receive data register is not empty */
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    /* Enable USART1 */
    USART_Cmd(USART1, ENABLE);

    for(i=0; i<104; i++)
    {
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1,save_y[i]);
        delay_nus(100000);

    }
    send=0;

}
Beispiel #12
0
/******************************************************************************
* Function Name  : FSMC_NAND_ReadSpareArea
* Description    : This routine read the spare area information from the specified
*                  pages addresses.
* Input          : - pBuffer: pointer on the Buffer to fill  
*                  - Address: First page address
*                  - NumSpareAreaToRead: Number of Spare Area to read
* Output         : None
* Return         : New status of the NAND operation. This parameter can be:
*                   - NAND_TIMEOUT_ERROR: when the previous operation generate 
*                     a Timeout error
*                   - NAND_READY: when memory is ready for the next operation 
*                  And the new status of the increment address operation. It can be:
*                  - NAND_VALID_ADDRESS: When the new address is valid address
*                  - NAND_INVALID_ADDRESS: When the new address is invalid address
*******************************************************************************/
uint32_t FSMC_NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead)
{
  uint32_t numsparearearead = 0x00, index = 0x00, addressstatus = NAND_VALID_ADDRESS;
  uint32_t status = NAND_READY, size = 0x00;

  while((NumSpareAreaToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
  {     
    /* Page Read command and page address */     
    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;

    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00; 
    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);     
    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);     
    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);    

    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
    delay_nus(15);

    /* Data Read */
    size = NAND_SPARE_AREA_SIZE +  (NAND_SPARE_AREA_SIZE * numsparearearead);
	
    /* Get Data into Buffer */
    for ( ;index < size; index++)
    {
      pBuffer[index] = *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
    }
    
    numsparearearead++;
    
    NumSpareAreaToRead--;

    /* Calculate page address */           			 
    addressstatus = FSMC_NAND_AddressIncrement(&Address);
  }

  status = FSMC_NAND_GetStatus();

  return (status | addressstatus);
}
Beispiel #13
0
/*
 *    写命令函数
 *    输入参数:  命令(DS18B20.H中定义)
 *    输出参数:  无
 *    返回参数:  无
 *
 */
void DS18B20_Write(unsigned char cmd)
{
    unsigned char i;
    SET_OUT();                  //设置IO为输出,2530->DS18B20
    
    /*每次一位,循环8次*/
    for(i=0; i<8; i++)
    {
        CL_DQ();              //IO为低    
        if( cmd & (1<<i) )    //写数据从低位开始
        {
          SET_DQ();           //IO输入高电平
        }
        else
        {
          CL_DQ();            //IO输出低电平
        }
        delay_nus(40);        //保持15~60us
        SET_DQ();             //IO口拉高
    }
    SET_DQ();                 //IO口拉高
}
Beispiel #14
0
/********************************************************************************************************
* 函 数 名 :  void Hex_close(void)
* 描    述 : 开机扫描数码管
* 输入参数 : None.
* 输出参数 : None.
* 返   回  : None.
********************************************************************************************************/
void Display_LedScan(void)  
{
  u32 i,j=0,k=0,sngtmp=0;
  
  while(1)
  {
    for(i=1;i<9;i++)
    {
      if(sngtmp%500==0)
      {
        if(j==9)
          j=0;
        else
          j++;
      }
      Hex_test(i,j);
      delay_nus(1000);
      sngtmp++;
    }
     if(sngtmp>4500)
        break;
  }
  
}
Beispiel #15
0
void Delay_ms(__IO u32 nTime)
{
	while(nTime--)
	delay_nus(1000);
}
Beispiel #16
0
/*---------------------------------
函数名:延时调整形式的delaynms函数, 
描 述:参数1即为1ms,1000即为1s;
-----------------------------------*/
void delay_nms(unsigned long n)
{
	while(n--)
	delay_nus(1030);
}
Beispiel #17
0
void main(void)
{ 
    
    u8 x,y[104],y1;
    extern u8 save_y[104];
    u32 count=0;
    extern u8 flag_dma,pulse;
    extern unsigned char stop,send,save;
    extern signed char y_shift;
    int a,b,c,d,f,i,j,save_a,save_b; 
    extern volatile unsigned short ADCConvertedValue[104];
    unsigned char e;
    u16 V0_value,V0_flag=0,s=0,V0_temp[104],Vmax,Vmin,Vpp,Vmax1,Vmin1,Vpp1;;
    extern unsigned char AD_dis_buffer[],dis_x_y_buffer[],AD_dis_save[];
    //目标板初化,

    Target_Init();  
    init12864lcd(); 
    Clean_12864_GDRAM();
    draw_side();
    dis_AD_dis_buffer(dis_x_y_buffer);
    write_12864com(0x30);
    Vmin=62;
    Vmax=0;
    y_shift=0;
    pulse=1;
    while(1)
    {
      if(flag_dma)
      {
       if(i<104)
       {
         i++;
       }
       else
       {
         //TIM_Cmd(TIM2, DISABLE); 
         pulse=0;
         for(i=0;i<104;)
         {
           if(stop==1);
           else{
           V0_value=ADCConvertedValue[i++];
           
           c=(int)(V0_value*3.3/4096)%10;
           d=(int)(V0_value*3.3/4096*10)%10;

           y[i]=(u8)(31-(c*10+d)*2*4/5+26+y_shift);
           y1=(u8)(31-(c*10+d)*2*4/5+26+y_shift);
           if(Vmin1>=V0_value)
           {
             Vmin1=V0_value;
           }
           if(Vmax1<=V0_value){
             Vmax1=V0_value;
           }
           
           if(Vmin>=y[i])
           {
             Vmin=y[i];
           }
           if(Vmax<=y[i]){
             Vmax=y[i];
           }
           Vpp=(Vmax-Vmin)*90/100;
           Vpp1=(Vmax1-Vmin1)*60/100;
           b=(int)((Vpp)*5/4)%10;
           a=(int)((Vpp)*5/4)/10;
           f=(int)((Vpp1*3.3/4096)*100)%10;
           
           dis_define_dot(y1,x++);
           if(x==104)x=0;
           }
         }
  
         Vmax=0;
         Vmin=62;
         
         if(GPIO_ReadInputDataBit(GPIOF,KEY7)==0){
           delay_nus(50000);
           count++;
         }
         if(count%2==0){
         dis_AD();
         
         delay_nus(10000);
         write_12864com(0x30);
         locate16(1, 1);
         write_12864dat('V');
         write_12864dat('=');
         if(GPIO_ReadInputDataBit(SW_GRP,SW1)==0){
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         write_12864dat('.');
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         e=(unsigned char)f+0x30;
         write_12864dat(e);
         }
         else if(GPIO_ReadInputDataBit(SW_GRP,SW2)==0){
         write_12864dat('0');  
         write_12864dat('.');
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         }
         else if(GPIO_ReadInputDataBit(SW_GRP,SW3)==0){
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         write_12864dat('m');
         write_12864dat('v');
         }
         //e=(unsigned char)f+0x30;
         //write_12864dat(e);
         }
         if(save==1){
           save_a=a;
           save_b=b;
           for(i=0;i<992;i++)
           {
             AD_dis_save[i]=AD_dis_buffer[i];
           }
           for(i=0;i<104;i++){
             save_y[i]=y[i];
           }
           save=0;
         }
         
         if(count%2==1){
           dis_AD_dis_buffer(AD_dis_save);
           //delay_nus(10000);
           write_12864com(0x30);
           locate16(1, 1);
           write_12864dat('V');
           write_12864dat('=');
           e=(unsigned char)save_a+0x30;  
           write_12864dat(e);
           write_12864dat('.');
           e=(unsigned char)save_b+0x30;
           write_12864dat(e);
           
         }
         
         if(send==1){
         function3();
         }
         
         for(i=0;i<992;i++)
         {
          AD_dis_buffer[i]=0x00; 
         }
        
         pulse=1;
         //TIM_Cmd(TIM2, ENABLE);
       }
       DMAReConfig();
       flag_dma=0; 
      }
   
   }
}