Esempio n. 1
0
/**********************************************函数定义***************************************************** 
* 函数名称: void MotoSetppingSet(u8 en, u8 dr,u8 set) 
* 输入参数: u8 en, u8 dr,u8 set 
* 返回参数: void  
* 功    能:   
* 作    者: by lhb_steven
* 日    期: 2016/7/15
************************************************************************************************************/ 
void MotoSetppingSet(u8 mode , u8 dr, u16 arrive) { 
    if(mode == 0) {//关闭电机
        UART1_CR2_RIEN = 1;//接收中断使能
        TIM1_CR1 = 0x00;//计数器使能,开始计数
        stepping1.en = 0;
        stepping1.sleep = 0;//设置速度
        EepromWrite(10,(u8)(stepping1.position));
        EepromWrite(11,(u8)(stepping1.position >> 8));
        ComSend(0x01,(u8)stepping1.position, (u8)(stepping1.position >> 8),0x00);//发送当前位置
    } else if(mode == 1){//打开电机
Esempio n. 2
0
/**********************************************函数定义***************************************************** 
* 函数名称: void MotoSet(u8 moto, u8 sleep) 
* 输入参数: u8 moto, u8 sleep 
* 返回参数: void  
* 功    能: 打开电机
* 作    者: by lhb_steven
* 日    期: 2016/7/14
************************************************************************************************************/ 
u8 MotoOpen(u8 moto, u8 dir) { 
    //压纸电机
    if(moto == 0) {
        moto1.zero_time = 0;
        if(dir == 0) {
            //压纸
            moto1.dir = ste_dr_pla_counter;
            moto1.pla_hd_time = 0;//转速时间
        } else {
            //收刀
            moto1.dir = ste_dr_pla_positive;
        }
        if(autu_n.specal_old == 0) {
            UART1_CR2_RIEN = 0;//关闭接收中断使能
        }
        PHASE_EN = 1;//开启转速中断
        moto1.en = 1;//打开压纸电机
        TIM2_CR1 = 0x01;
        //压纸电机方向
        PLATEN_DIR = moto1.dir;
    } else {
        //操作切纸电机
        moto2.zero_time = 0;
        if(dir == 0) {//复位
            moto2.dir = ste_dr_cut_counter;
          
        } else {//切纸
            autu_n.specal_rst = 0;
            EepromWrite(13,autu_n.specal_rst);
            moto2.dir = ste_dr_cut_positive;
        }
        if(autu_n.specal_old == 0) {
            UART1_CR2_RIEN = 0;//关闭接收中断使能
        }
        moto2.en = 1;//打开切纸电机
        CUTTER_SLEEP = 0;//低电平有效
        //切纸电机方向使能
        CUTTER_DIR = moto2.dir;
    }
    //开启中断
    //等待继电器稳定
    DelayMs(300);
    //使能电源
    POWER_EN = 1;
    return 0;
}
Esempio n. 3
0
/*****************************************************************************
 *  FUNCTION: NVM_Write
 *
 *  INPUTS:
 *      NVM_BlockId_t p_BlockId
 *          MIN: 0
 *          MAX: NUM_NVM_BLOCKS
 *          DESC: NVM block ID for NVM_Blocks_sa
 *      uint8_t *p_Buf
 *          DESC: pointer to buffer to read EEPROM data from, if NULL return
 *                value will be FALSE
 *
 *  OUTPUTS:
 *      uint8_t (return)
 *          TRUE - write was successful
 *          FALSE - write failed
 *
 *  MODULE VARIABLES:
 *      NVM_Blocks_sa used
 *
 *  DESCRIPTION:
 *      This function writes data to NVM from RAM at the address
 *      of the provided pointer.
 *
 *****************************************************************************/
uint8_t NVM_Write( NVM_BlockId_t p_BlockId, uint8_t *p_Buf )
{
    uint8_t l_return_u8 = FALSE;
    uint8_t l_inx_u8;
    uint16_t l_EEPROM_addr_u8;
    uint8_t *l_ptr_u8;

    if (  ( p_BlockId < NUM_NVM_BLOCKS )
       && ( p_Buf != NULL ) ) {
        l_ptr_u8 = p_Buf;
        l_EEPROM_addr_u8 = NVM_Blocks_sa[p_BlockId].Addr_u16;
        for ( l_inx_u8 = 0; l_inx_u8 < NVM_Blocks_sa[p_BlockId].Size_u8; l_inx_u8++ ) {
            //EEPROM.write( l_EEPROM_addr_u8++, *l_ptr_u8++ );
            EepromWrite( l_EEPROM_addr_u8++, *l_ptr_u8++ );
        }

#if 0 /* CRC not implemented */
        if ( NVM_Blocks_sa[p_BlockId].Flags.b.UseCRC_bt ) {
            /* Calculate CRC and store in EEPROM */
            uint8_t l_crc_u8 = 0;

            l_crc_u8 = CRC8_Calculate( NVM_Blocks_sa[ p_BlockId ].Size_u8, p_Buf );
            EEPROM.write( l_EEPROM_addr_u8, l_crc_u8 );

            //Serial.print( "DEBUG: CRC " );
            //Serial.println( l_crc_u8, DEC );

            l_return_u8 = TRUE;
        } /* NVM_Blocks_sa[p_BlockId].Flags.b.UseCRC  */
#endif
    } else {
        //Serial.println( "DEBUG: ERROR NVM_Write invalid block ID, or NULL pointer!" );
        l_return_u8 = FALSE;
    } /* p_BlockId < NUM_NVM_BLOCKS */

    return l_return_u8;
} /* NVM_Write */
Esempio n. 4
0
void SettingsSave(void)
{
	settings.checksum = SettingsChecksum();
	EepromWrite((unsigned char*)&settings, sizeof(settings_t), SETTINGS_ADDRESS);
}
/*****************************************************************************
*
* The purpose of this function is to illustrate how to use the XSpiPs
* device driver in polled mode. This test writes and reads data from a
* serial EEPROM. The serial EEPROM part must be present in the hardware
* to use this example.
*
* @param	SpiInstancePtr is a pointer to the Spi Instance.
* @param	SpiDeviceId is the Device Id of Spi.
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note
*
* This function calls functions which contain loops that may be infinite
* if interrupts are not working such that it may not return. If the device
* slave select is not correct and the device is not responding on bus it will
* read a status of 0xFF for the status register as the bus is pulled up.
*
*****************************************************************************/
int SpiPsEepromPolledExample(XSpiPs *SpiInstancePtr, u16 SpiDeviceId)
{
	int Status;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XSpiPs_Config *SpiConfig;

	/*
	 * Initialize the SPI driver so that it's ready to use
	 */
	SpiConfig = XSpiPs_LookupConfig(SpiDeviceId);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize(SpiInstancePtr, SpiConfig,
				       SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to check hardware build
	 */
	Status = XSpiPs_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the Spi device as a master. External loopback is required.
	 */
	XSpiPs_SetOptions(SpiInstancePtr, XSPIPS_MASTER_OPTION |
			   XSPIPS_FORCE_SSELECT_OPTION);

	XSpiPs_SetClkPrescaler(SpiInstancePtr, XSPIPS_CLK_PRESCALE_64);

	/*
	 * Initialize the write buffer for a pattern to write to the EEPROM
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		WriteBuffer[WRITE_DATA_OFFSET + Count] =
					(u8)(UniqueValue + Test);
		ReadBuffer[READ_DATA_OFFSET + Count] = 0xA5;
	}

	/*
	 * Assert the EEPROM chip select
	 */
	XSpiPs_SetSlaveSelect(SpiInstancePtr, EEPROM_SPI_SELECT);

	/*
	 * Write the data in the write buffer to the serial EEPROM a page at a
	 * time, read the data back from the EEPROM and verify it
	 */
	UniqueValue = 13;
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		EepromWrite(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				&WriteBuffer[Page * PAGE_SIZE]);
		EepromRead(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				ReadBuffer);

		BufferPtr = &ReadBuffer[READ_DATA_OFFSET];
		for (Count = 0; Count < PAGE_SIZE; Count++, UniqueValue++) {
			if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
				return XST_FAILURE;
			}
		}
	}

	return XST_SUCCESS;
}
Esempio n. 6
0
/**********************************************函数定义***************************************************** 
* 函数名称: void MotoInit(void) 
* 输入参数: void 
* 返回参数: void  
* 功    能:   
* 作    者: by lhb_steven
* 日    期: 2016/7/13
************************************************************************************************************/ 
void MotoInit(void) {
    PD_DDR_DDR2 = 1;//压纸机调速
    PD_CR1_C12 = 1;
    PD_CR2_C22 = 1;
    
    PD_DDR_DDR3 = 1;//切纸机调速
    PD_CR1_C13 = 1;
    PD_CR2_C23 = 1;
    
    PD_DDR_DDR4 = 1;//蜂鸣器
    PD_CR1_C14 = 1;
    PD_CR2_C24 = 1;
    
    PC_DDR_DDR4 = 1;//继电器-压纸方向
    PC_CR1_C14 = 1;
    PC_CR2_C24 = 1;
    
    PC_DDR_DDR5 = 1;//继电器-电源控制
    PC_CR1_C15 = 1;
    PC_CR2_C25 = 1;
    
    PC_DDR_DDR6 = 1;//继电器-切纸方向
    PC_CR1_C16 = 1;
    PC_CR2_C26 = 1;
    
    PC_DDR_DDR1 = 1;//步进电机-方向
    PC_CR1_C11 = 1;
    PC_CR2_C21 = 1;
    
    PC_DDR_DDR2 = 1;//步进电机-脉冲
    PC_CR1_C12 = 1;
    PC_CR2_C22 = 1;
    
    PB_DDR_DDR2 = 0;//压纸霍尔
    PB_CR1_C12 = 1;
    PB_CR2_C22 = 1;
    
    PB_DDR_DDR1 = 0;//压纸上限位
    PB_CR1_C11 = 1;
    PB_CR2_C21 = 0;
    
    PB_DDR_DDR0 = 0;//推纸后限位--步进电机限位
    PB_CR1_C10 = 1;
    PB_CR2_C20 = 0;
    
    PB_DDR_DDR3 = 0;//切纸下限位
    PB_CR1_C13 = 0;
    PB_CR2_C23 = 1;
    
    PB_DDR_DDR4 = 0;//切纸上限位
    PB_CR1_C14 = 1;
    PB_CR2_C24 = 1;
    
    PE_DDR_DDR5 = 0;//交流相位同步
    PE_CR1_C15 = 0;
    PE_CR2_C25 = 0;//需要载打开
    
    EXTI_CR2 |= BIT(1);//开启PD口中断
	EXTI_CR2 &= ~BIT(0);
    
    PC_DDR_DDR3 = 1;//刀光线使能
    PC_CR1_C13 = 1;
    PC_CR2_C23 = 1;
    
    PB_DDR_DDR5 = 0;//安全光幕
    PB_CR1_C15 = 0;
    PB_CR2_C25 = 0;
    
    CUTTER_SLEEP = 1;
    PLATEN_SLEEP = 1;
    
    TIM1_PSCRH = 0;
    TIM1_PSCRL = 15;          //(15+1)分频为1M
    TIM1_ARRH = 0x1;
    TIM1_ARRL = 0xF4;        //每500us中断一次
    TIM1_IER = 0x01;         //允许更新中断
    TIM1_CR1 = 0x00;         //计数器使能,开始计数
    
    //TIM2/3/4/5/6须使用与芯片对应的头文件
    TIM2_PSCR_PSC = 4;          //2^4 分频为1M 
    TIM2_ARRH = 0x17;
    TIM2_ARRL = 0xA0;        //每4000us中断一次
    TIM2_IER = 0x01;         //允许更新中断
    //TIM2_CR1 = 0x00;         //计数器使能,开始计数
    
    
    CUTTER_LIGHT = 1;//打开激光指示
    
    EXTI_CR1 &= ~BIT(2);//开启PD口中断 1 0
	EXTI_CR1 |= BIT(3);
    
    EXTI_CR1_PBIS = 2;    //PB下降沿触发
    //第一次初始化
    if(EepromRead(9) != 0x55) {
        EepromWrite(9,0x55);
        EepromWrite(10,0x00);
        EepromWrite(11,0x00);
//        //力度初始化
//        EepromWrite(12,0x04);
//        EepromWrite(13,0x04);
//        
//        EepromWrite(14,0x04);
    }
    EXTI_CR2_PEIS = 1;    //上升沿触发
    
    stepping1.position = EepromRead(10);
    stepping1.position |= (u16)(EepromRead(11) << 8);
    stepping1.position_last = stepping1.position;
    
    autu_n.process = 0;
    autu_n.push_book = EepromRead(12);
    autu_n.specal_rst = EepromRead(13);
    autu_n.sui_cut_num = EepromRead(14);
    
    autu_n.sui_length = EepromRead(15);
    autu_n.sui_length |= (u16)(EepromRead(16) << 8);
    
    autu_n.sui_length = EepromRead(15);
    autu_n.sui_length |= (u16)(EepromRead(16) << 8);
    
    autu_n.sui_length_book = EepromRead(17);
    autu_n.sui_length_book |= (u16)(EepromRead(18) << 8);
    
    moto1.strength = EepromRead(19);
    moto1.strength |= (u16)(EepromRead(20) << 8);
    //保护
    if(moto1.strength > 4000) {
        moto1.strength = 1000;
    } else if(moto1.strength < 1000) {
        moto1.strength = 1000;
    }
}
/*****************************************************************************
*
* The purpose of this function is to illustrate how to use the XSpiPs
* device driver in interrupt mode . This test writes and reads data from a
* serial EEPROM.
* This part must be present in the hardware to use this example.
*
* @param	IntcInstancePtr is a pointer to the GIC driver to use.
* @param	SpiInstancePtr is a pointer to the SPI driver to use.
* @param	SpiDeviceId is the DeviceId of the Spi device.
* @param	SpiIntrId is the Spi Interrupt Id.
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note
*
* This function calls functions which contain loops that may be infinite
* if interrupts are not working such that it may not return. If the device
* slave select is not correct and the device is not responding on bus it will
* read a status of 0xFF for the status register as the bus is pulled up.
*
*****************************************************************************/
int SpiPsEepromIntrExample(XScuGic *IntcInstancePtr, XSpiPs *SpiInstancePtr,
			 u16 SpiDeviceId, u16 SpiIntrId)
{
	int Status;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XSpiPs_Config *SpiConfig;

	/*
	 * Initialize the SPI driver so that it's ready to use
	 */
	SpiConfig = XSpiPs_LookupConfig(SpiDeviceId);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize(SpiInstancePtr, SpiConfig,
				       SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to check hardware build
	 */
	Status = XSpiPs_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Connect the Spi device to the interrupt subsystem such that
	 * interrupts can occur. This function is application specific
	 */
	Status = SpiSetupIntrSystem(IntcInstancePtr, SpiInstancePtr, SpiIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup the handler for the SPI that will be called from the
	 * interrupt context when an SPI status occurs, specify a pointer to
	 * the SPI driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */
	XSpiPs_SetStatusHandler(SpiInstancePtr, SpiInstancePtr,
				 (XSpiPs_StatusHandler) SpiHandler);

	/*
	 * Set the Spi device as a master. External loopback is required.
	 */
	XSpiPs_SetOptions(SpiInstancePtr, XSPIPS_MASTER_OPTION |
			   XSPIPS_FORCE_SSELECT_OPTION);

	XSpiPs_SetClkPrescaler(SpiInstancePtr, XSPIPS_CLK_PRESCALE_64);

	/*
	 * Initialize the write buffer for a pattern to write to the EEPROM
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		WriteBuffer[WRITE_DATA_OFFSET + Count] =
					(u8)(UniqueValue + Test);
		ReadBuffer[READ_DATA_OFFSET + Count] = 0xA5;
	}

	/*
	 * Assert the EEPROM chip select
	 */
	XSpiPs_SetSlaveSelect(SpiInstancePtr, EEPROM_SPI_SELECT);

	/*
	 * Write the data in the write buffer to the serial EEPROM a page at a
	 * time
	 */
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		EepromWrite(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				&WriteBuffer[Page * PAGE_SIZE]);
	}

	/*
	 * Read the contents of the entire EEPROM from address 0, since this
	 * function reads the entire EEPROM it will take some amount of time to
	 * complete
	 */
	EepromRead(SpiInstancePtr, 0, MAX_DATA, ReadBuffer);

	/*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */
	BufferPtr = &ReadBuffer[READ_DATA_OFFSET];

	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	SpiDisableIntrSystem(IntcInstancePtr, SpiIntrId);
	return XST_SUCCESS;
}