初级会员
- 积分
- 174
- 金钱
- 174
- 注册时间
- 2020-8-16
- 在线时间
- 37 小时
|
1金钱
#include "stm32f10x.h"
#include "gpio.h"
//#define ADDR_BASE 0x08007c00 //′æ′¢êy¾YFlashò3ê×μØÖ·
#include <math.h>
#include "uart.h"
#include "XT9822.h"
#include "stdlib.h"
/**********************************************************/
#define Tm512_data_num 4
extern u32 XT9822Dat[nXT9822];
void RCC_Configuration(void);
void Delay_ms(uint32_t time);
void Delay_us(uint32_t Times);
void NVIC_Configuration(void);
void TIM1_Configuration(void);
void IWDG_Configuration(void);
void W_Tm512_addr(u16 start_addr,u16 num);
void DataL_to_DataH(u8 *data,u8 *data_buff,u16 len);
void DataL_to_DataH_1(u8 *data,u16 len);
u8 Motor_get_info[8]={0x55,0xaa,0x03,0x01,0x04,0x00,0x22,0x2a};
//u16 GetPara(u32 addr);
//void SavePara(u32 addr,u16 data);
u8 data_buff_1[500]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71/*0,0x50,0x00,0x00,0x00,
0x00,0x50,0x00,0x00,
0x00,0x00,0x50,0x00,
0x00,0x00,0x00,0x50,
0x50,0x00,0x00,0x00,
0x00,0x50,0x00,0x00,*/
};
u8 data_buff_2[500]={0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,};
u8 data_buff_3[500]={0,0x00,0x00,0x50,
0x50,0x00,0x00,};
u8 data_buff_4[500]={0,0x00,0x00,0x00,0x50,
0x50,0x00,0x00,0x00,};
//u8 addr_data_1[50]={0x00,0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x40,
// 0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x43,
// 0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x46,
// 0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x49,
// 0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x4c,
// 0xaa,0xf0,0x34,0x55,0xac,0x80,0x80,0x4f
// };
u8 addr_data_1[4800]={0};
//u8 addr_data_2[50]={0x00,0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x40,
// 0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x43,
// 0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x46,
// 0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x49,
// 0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x4c,
// 0xaa,0xf0,0x34,0x55,0xac,0xc0,0x80,0x4f,
// };
//u8 addr_data_buff[50];
/**********************************************************/
int main(void)
{
u16 i,j,n;
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
Delay_ms(10);
USART1_Config();
TX1_EN;
Delay_ms(2000);
// W_Tm512_addr(0,6);//DT¸ÄμØÖ·
Delay_ms(1000);
uart1_send_buff(data_buff_2,25);
Delay_ms(500);
uart1_send_buff(data_buff_1,8);
Delay_ms(100);
while(1)
{
uart1_send_buff(data_buff_1,25);
Delay_ms(100);
// uart1_send_buff(data_buff_2,109);
// Delay_ms(100);
// uart1_send_buff(data_buff_3,109);
// Delay_ms(500);
// uart1_send_buff(data_buff_4,109);
// Delay_ms(500);
// for(n=0;n<3;n++)
// {
// for(i=0;i<160;i++)
// {
// for(j=0;j<481;j++)
// {
// data_buff_4[j]=0;
// }
// data_buff_4[i*3+1+n]=30;
// {
// uart1_send_buff(data_buff_4,481);
// Delay_ms(100);
// }
// }
// }
}
}
void W_Tm512_addr(u16 start_addr,u16 num)
{
u16 i,j;
if(start_addr+num*Tm512_data_num<0xfff)
{
addr_data_1[0]=0;
for(i=0;i<num;i++)
{
addr_data_1[i*8+1]=0xaa;
addr_data_1[i*8+2]=0xf0;
addr_data_1[i*8+3]=0x34;
addr_data_1[i*8+4]=0x55;
addr_data_1[i*8+5]=0xac;
addr_data_1[i*8+6]=0x80;
addr_data_1[i*8+7]=0x80|(((start_addr+i*Tm512_data_num)&0x0FC0)>>6);
addr_data_1[i*8+8]=0x40|((start_addr+i*Tm512_data_num)&0x3f);
}
DataL_to_DataH_1(addr_data_1,num*8+1);
GPIO_Tx_Config(1);
uart1_send_buff1(addr_data_1,num*8+1);
addr_data_1[0]=0;
for(i=0;i<num;i++)
{
addr_data_1[i*8+1]=0xaa;
addr_data_1[i*8+2]=0xf0;
addr_data_1[i*8+3]=0x34;
addr_data_1[i*8+4]=0x55;
addr_data_1[i*8+5]=0xac;
addr_data_1[i*8+6]=0xc0;
addr_data_1[i*8+7]=0x80|(((start_addr+i*Tm512_data_num)&0x0FC0)>>6);
addr_data_1[i*8+8]=0x40|((start_addr+i*Tm512_data_num)&0x3f);
}
DataL_to_DataH_1(addr_data_1,num*8+1);
GPIO_Tx_Config(1);
uart1_send_buff1(addr_data_1,num*8+1);
}
}
void DataL_to_DataH_1(u8 *data,u16 len)
{
u16 i,j;
u8 temp;
for(i=0;i<len;i++)
{
*data=((*data>>7)&0x01)|((*data>>5)&0x02)|((*data>>3)&0x04)|((*data>>1)&0x08)|
((*data<<7)&0x80)|((*data<<5)&0x40)|((*data<<3)&0x20)|((*data<<1)&0x10);
data++;
}
}
void DataL_to_DataH(u8 *data,u8 *data_buff,u16 len)
{
u16 i,j;
u8 temp;
for(i=0;i<len;i++)
{
*data_buff=((*data>>7)&0x01)|((*data>>5)&0x02)|((*data>>3)&0x04)|((*data>>1)&0x08)|
((*data<<7)&0x80)|((*data<<5)&0x40)|((*data<<3)&0x20)|((*data<<1)&0x10);
data_buff++;
data++;
}
}
void TIM2_IRQHandler(void)
{
u8 i;
u8 music_data_temp;
if(TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
{
}
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) == SET)
{
}
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4, TIM_IT_Update) == SET)
{
}
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
void Motor_test(void)
{
}
void IO_test(void)
{
}
void send_data(u8 Txdata)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET){}
USART_SendData(USART3,Txdata );
}
void send_test_data(u8 rxdata,u16 run_count )
{
}
/*****************************************************************************************************
** oˉêyÃû3Æ: SavePara()
** oˉêyÃèêö: ±£′æ2Îêy
** ½ó¿ú2Îêy: addr,data
------------------------------------------------------------------------------------------------------
** ±¸×¢:ÿ′ÎD′êy¾YÇ°μÃÏè2á3yËùòa′æ′¢λÖÃËùÔúμÄÕû¸öò3£¬ÕaêÇoíEEPROMμÄ2»í¬Ö®′|¡£Flash2»¾ß±¸DT¸Ä1|Äü£¬
Ö»ÄüÏè2á3yÔùD′£¬¶ø2á3yê±£¬Ö»Ö§3Öò32á3y¡£
addrμØÖ··¶Î§£oADDR_BASE ~ADDR_BASE+1022
*****************************************************************************************************/
//void SavePara(u32 addr,u16 data)
//{
// FLASH_Unlock(); //ÿ′Î2á3yFlashÖDêy¾Yê±μÃÏè½aËø
// FLASH_ErasePage(ADDR_BASE); //2á3yò3
// FLASH_ProgramHalfWord(addr,data);//D′16λ°ë×Ö
// FLASH_Lock(); //éÏËø
//
//}
/*****************************************************************************************************
** oˉêyÃû3Æ: GetPara()
** oˉêyÃèêö: ¶á3ö2Îêy
** ½ó¿ú2Îêy: addr ¶áè¡êy¾YËùÔúμÄFlashμØÖ·
------------------------------------------------------------------------------------------------------
** ±¸×¢: addrμØÖ··¶Î§£oADDR_BASE ~ADDR_BASE+1022
*****************************************************************************************************/
//u16 GetPara(u32 addr)
//{
// u16 data;
// data=(u16)(*(u32*)addr); //¶áè¡Ïàó|μØÖ·ÖDμÄ16λêy¾Y
// return data;
//}
void IWDG_Configuration(void) //¿′ÃÅ1·3õê¼»ˉ
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(IWDG_Prescaler_256);
IWDG_SetReload(0xfff);
IWDG_ReloadCounter();
IWDG_Enable();
}
void Delay_us(uint32_t Times)
{
uint32_t i=0;
while(Times--)
{
i=8; //
while(i--);
}
}
void Delay_ms(uint32_t time)
{
uint32_t i=0;
while(time--)
{
i=10000; //
while(i--);
}
}
void TIM2_Configuration(void) //TIM23õê¼»ˉ 5ms
{
// TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
// //Ô¤·ÖÆμÏμêyÎa36000-1£¬ÕaÑù¼ÆêyÆ÷ê±ÖóÎa72MHz/7200=10kHz
// TIM_TimeBaseStructure.TIM_Prescaler=72-1;
// TIM_TimeBaseStructure.TIM_Period = 5000;
// TIM_TimeBaseStructure.TIM_ClockDivision=0;//éèÖÃê±Öó·Ö¸îTIM_CKD_DIV1=0x0000,2»·Ö¸î
// TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //éèÖüÆêyÆ÷Ä£ê½ÎaÏòéϼÆêyÄ£ê½
// TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
// TIM_ClearFlag(TIM2, TIM_FLAG_Update);
// TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
// TIM_Cmd(TIM2,DISABLE);//TIM2
// TIM_Cmd(TIM2,ENABLE);//TIM2
//*****************************
}
/*******************************************************************************
* oˉêyÃû : NVIC_Configuration
* oˉêyÃèêö : éèÖÃNVIC2Îêy
* êäèë2Îêy : ÎT
* êä3ö½á1û : ÎT
* ·μ»ØÖμ : ÎT
*******************************************************************************/
void NVIC_Configuration(void)
{
/* ¶¨òå NVIC 3õê¼»ˉ½á11ìå */
NVIC_InitTypeDef NVIC_InitStructure;
/* #ifdef...#else...#endif½á11μÄ×÷óÃêǸù¾YÔ¤±àòëìõ¼t¾ö¶¨ÖD¶ÏÏò῱íÆeê¼μØÖ·*/
#ifdef VECT_TAB_RAM
/* ÖD¶ÏÏò῱íÆeê¼μØÖ·′ó 0x20000000 ¿aê¼ */
NVIC_SetVectorTable(NVIC_VectTab_RAM , 0x0);
#else /* VECT_TAB_FLASH */
/* ÖD¶ÏÏò῱íÆeê¼μØÖ·′ó 0x80000000 ¿aê¼ */
NVIC_SetVectorTable(NVIC_VectTab_FLASH , 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;//
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//
NVIC_Init(&NVIC_InitStructure);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=2;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
// NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
//
// NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=8;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
//
// NVIC_InitStructure.NVIC_IRQChannel=TIM4_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=10;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
//
// NVIC_InitStructure.NVIC_IRQChannel=DMA1_Channel2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=4;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
//
// NVIC_InitStructure.NVIC_IRQChannel=DMA1_Channel4_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=4;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
// NVIC_InitStructure.NVIC_IRQChannel=TIM1_CC_IRQn;//Ñ¡ÔñUSART3ÖD¶Ï
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;//
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//ê1Äü
// NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
* RCC_Configuration
*******************************************************************************/
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/* ¸′λÏμí3ê±ÖóéèÖÃ*/
RCC_DeInit();
/* ¿aÆôHSE*/
RCC_HSEConfig(RCC_HSE_ON);
/* μè′yHSEÆeÕe2¢Î趨*/
HSEStartUpStatus = RCC_WaitForHSEStartUp();
/* HSEêÇ·ñÆeÕñ3é1| */
if(HSEStartUpStatus == SUCCESS)
{
/* HCLK(AHB)ê±ÖóÔ′ÎaSYSCLK 1·ÖÆμ*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2ê±ÖóÔ′ÎaHCLK(AHB) 1·ÖÆμ */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1ê±ÖóÔ′ÎaHCLK(AHB) 2·ÖÆμ */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* éèÖÃFLASHÑóê±ÖüÆúÎa2 */
FLASH_SetLatency(FLASH_Latency_2);
/* ê1ÄüFLASHԤ衻o′æ */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Ñ¡ÔñËøÏà»·£¨PLL£©ê±ÖóÔ′ÎaHSE 1·ÖÆ죬±¶ÆμêyÎa12£¬Ôòêä3öÆμÂêÎa72MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_12);
RCC_PLLCmd(ENABLE); /* ê1Äü PLL */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* μè′y PLL êä3öÎ趨 */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Ñ¡ÔñSYSCLKμÄê±ÖóÔ′ÎaPLL
while(RCC_GetSYSCLKSource() != 0x08)
{}
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
while (1)
{}
}
#endif
|
|