int main(void)
{
//u8 x,y,z;
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration**********************************************/
RCC_Configuration();
/* NVIC Configuration*******************************************************/
NVIC_Configuration();
/* USART Configuration*******************************************************/
USART_Configuration();
/* MMA7455 Configuration****************************************************/
MMA7455_Configuration();
/* Configure all unused GPIO port pins in Analog Input mode (floating input
trigger OFF), this will reduce the power consumption and increase the device
immunity against EMI/EMC *************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF, ENABLE); /*Enable the APB2 periph clock*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
//GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
//GPIO_Init(GPIOF, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF, DISABLE); /*Disable the APB2 periph clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOF , ENABLE);
/*set PA6 as input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*set PA5,PA7,PA8 as output*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*set PF6 as output*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/*for showing the result of successful uart configuration*/
printf("\r\n Welcome to www.PowerAVR.com \r\n");
printf("\r\n Please Input Character From Keyboard \r\n");
/*Write the contrl command on the register,set the mode as measurement*/
Write_Reg(0x16,0x05);
Delay(0xff);
//Write_Reg(0x18,0x20); //
//Delay(0xff);
//Write_Reg(0x19,0x00);
//Delay(0xff);
//Write_Reg(0x1a,0x00);
//Delay(0xff);
/*get the 3-axis data from MMA7455L by Reading the register*/
while(1)
{
x=Read_Reg(0x06);
y=Read_Reg(0x07);
z=Read_Reg(0x08);
GPIO_ResetBits(GPIOF, GPIO_Pin_6);
Delay(0xffffff);
GPIO_SetBits(GPIOF, GPIO_Pin_6);
Delay(0xffffff);
printf("\n%x%x%x\n",x,y,z);
}
}