📄 main_archive.c
字号:
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Enable I2C2 event interrupt
// I2C_ITConfig(I2C1, I2C_IT_EVT | I2C_IT_BUF, ENABLE);
// I2C1 Init
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = LIS_ADDRESS;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_Init(I2C1, &I2C_InitStructure);
// Enable I2C
I2C_Cmd(I2C1, ENABLE);
// Send I2C1 START condition
I2C_GenerateSTART(I2C1, ENABLE);
// Recuire acknowledge
I2C_AcknowledgeConfig(I2C1, ENABLE);
// Send Address and Cmd for read/write
I2C_SendData(I2C1, LIS_ADDRESS + CMD_WRITE);
// Wait for acknowledge
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)==SET) {
I2C_ClearFlag(I2C1, I2C_FLAG_AF);
}
// Recuire acknowledge
I2C_AcknowledgeConfig(I2C1, ENABLE);
// Send Address and Cmd for read/write
I2C_SendData(I2C1, REG_WHO_AM_I);
// Wait for acknoledge
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)==SET) {
I2C_ClearFlag(I2C1, I2C_FLAG_AF);
}
// Send I2C1 START condition
I2C_GenerateSTART(I2C1, ENABLE);
// Send Address and Cmd for read/write
I2C_SendData(I2C1, LIS_ADDRESS + CMD_READ);
// Wait for acknoledge
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)==SET) {
I2C_ClearFlag(I2C1, I2C_FLAG_AF);
}
value = I2C_ReceiveData(I2C1);
// Recuire acknowledge
I2C_AcknowledgeConfig(I2C1, DISABLE);
// Send I2C1 STOP condition
I2C_GenerateSTOP(I2C1, ENABLE);
*/
/*
//StartBit
while (I2C1->SR1 & SR1_BUSY);
if (!I2C_StartBit())
return;
//Send bytes: SLAVE_ADDR + WRITE_FLAG, REG_ADDR
if (!I2C_SendByte(*(pBuffer+0)))
return;
if (!I2C_SendByte(*(pBuffer+1)))
return;
//Repeat StartBit
if (!I2C_StartBit())
return;
//Send byte: SLAVE_ADDR + READ_FLAG
I2C->DR = *(pBuffer+2);
while (!(I2C->SR1 & SR1_EVF));
I2C->CR |= CR_ACK;
if (!I2C_TestErr())
return;
while (!(I2C->SR1 & SR1_BTF));
//ReceiveBytes, when finish generate StopBit
for (i=3;i<=NoOfBytes;i++)
{
while (!(I2C->SR1 & SR1_EVF));
if (i < (NoOfBytes-1))
I2C->CR |= CR_ACK;
if (i == (NoOfBytes-1))
I2C->CR &= ~CR_ACK;
if (i > (NoOfBytes-1))
I2C->CR |= CR_STOP;
if (!I2C_TestErr())
return;
while (!(I2C->SR1 & SR1_BTF));
if (i <= (NoOfBytes-1))
*(pBuffer+i) = I2C->DR;
else
(void)I2C->DR;
}
*/
// while(1);
// LCD init
LCDInit();
LCDContrast(0x45);
LCDClear();
LCDStr ( 0, " Walcome to ", 0 );
LCDStr ( 1, " STM32F103-STK", 0 );
LCDStr ( 2, " development ", 0 );
LCDStr ( 3, " board ", 0 );
LCDStr ( 5, "www.olimex.com", 1 );
LCDUpdate();
// Delay :-)
for(dly=0; dly<5000000; dly++);
label1:
// Init joystick
InitJoystick();
// Draw menue
UpdateMenu(MenuPos);
while(1) {
JoyPos = GetJoystickPosition();
if(JoyPos==KEY_UP) {
MenuPos--;
if((MenuPos<1)) MenuPos = 1;
UpdateMenu(MenuPos);
for(dly=0; dly<700000; dly++);
}
if(JoyPos==KEY_DOWN) {
MenuPos++;
if((MenuPos>8)) MenuPos = 8;
UpdateMenu(MenuPos);
for(dly=0; dly<700000; dly++);
}
if(JoyPos==KEY_CENTER) break;
}
// Test MMC ------------------------------------------------------------------
if(MenuPos == 1) {
test_state = TestMMC();
if(test_state == 1) {
LCDClear();
LCDStr ( 0, " Test MMC card", 0 );
LCDStr ( 1, " SUCCESS!!! ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
else if (test_state == 2) {
LCDClear();
LCDStr ( 0, " MMC card is ", 0 );
LCDStr ( 1, " protected!!!", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
else if (test_state == 3) {
LCDClear();
LCDStr ( 0, " MMC card is ", 0 );
LCDStr ( 1, "not present!!!", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
else {
LCDClear();
LCDStr ( 0, " Test MMC card", 0 );
LCDStr ( 1, " FAILED!!! ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET);
goto label1;
}
// Test Audio ----------------------------------------------------------------
if(MenuPos == 2) {
// WAKE UP
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
LCDClear();
LCDStr ( 0, " Audio test ", 0 );
LCDStr ( 1, "The device is ", 0 );
LCDStr ( 2, " STANBY, pls ", 0 );
LCDStr ( 3, "press WAKE-UP ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_RESET);
// Set STNBY pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Chip on
GPIO_WriteBit(GPIOC, GPIO_Pin_3, Bit_RESET);
// Microphone and headphone
ADCInit();
InitPWM();
// Enable interrupts
__enable_interrupt();
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) {
if((TIM1->SR)&(0x1)) {
// clear flag
TIM1->SR &= ~0x1;
if((jjj++)==3) {
jjj = 0;
ADCValue = GetADCChanel(ADC_Channel_1);
ADCValue>>=2;
SetDutyPeriod(ADCValue);
}
}
}
goto label1;
}
// Test RTC ------------------------------------------------------------------
if(MenuPos == 3) {
RTCInit();
LCDClear();
LCDStr ( 0, " RTC Test ", 0 );
LCDStr ( 1, "STAT led have ", 0 );
LCDStr ( 2, "to blink every", 0 );
LCDStr ( 3, " second ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET);
// Disable RTC
RCC_RTCCLKCmd(DISABLE);
// TURN OFF led
GPIOC->BSRR |= 0x00001000;
// restart :-)
goto label1;
}
// Test NRF ------------------------------------------------------------------
if(MenuPos == 4) {
LCDClear();
LCDStr ( 0, " Test NRF ", 0 );
LCDStr ( 1, " press WAKE-UP", 0 );
LCDStr ( 2, " send/receive ", 0 );
LCDStr ( 3, " one byte ", 0 );
LCDUpdate();
while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==Bit_RESET);
// RESET LCD
GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_SET);
nRFSetting();
// B1 as input
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) {
TestNRF();
}
goto label1;
}
// Test USB ------------------------------------------------------------------
if(MenuPos == 5) {
LCDClear();
LCDStr ( 0, " Test USB ", 0 );
LCDStr ( 1, " connect usb ", 0 );
LCDStr ( 2, " cable ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
USBSettings();
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) {
if((UsbCoreReq(UsbCoreReqDevState)==UsbDevStatusConfigured)&&(UsbCoreReq(UsbCoreReqDevSusState)==0)) {
LCDClear();
LCDStr ( 0, " Test USB ", 0 );
LCDStr ( 1, " SUCCESS!!! ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
}
goto label1;
}
// Test MMA--------------------------------------------------------
if(MenuPos == 6) {
}
// Test Extension Port--------------------------------------------------------
if(MenuPos == 7) {
LCDClear();
LCDStr ( 0, " Test EXT ", 0 );
LCDStr ( 1, " Pls, put EXTs", 0 );
LCDStr ( 2, " and press B1 ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
if(TestEXT()) {
LCDClear();
LCDStr ( 0, " Test EXT ", 0 );
LCDStr ( 1, " SUCCESS!!! ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
else {
LCDClear();
LCDStr ( 0, " Test EXT ", 0 );
LCDStr ( 1, " FAILED!!! ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET);
goto label1;
}
// Test Joystick and Button --------------------------------------------------
if(MenuPos == 8) {
while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) {
JoyPos = GetJoystickPosition();
if(JoyPos==KEY_UP) {
LCDClear();
LCDStr ( 0, " UP ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
if(JoyPos==KEY_DOWN) {
LCDClear();
LCDStr ( 4, " DOWN ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
if(JoyPos==KEY_LEFT) {
LCDClear();
LCDStr ( 2, "LEFT ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
if(JoyPos==KEY_RIGHT) {
LCDClear();
LCDStr ( 2, " RIGHT", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
if(JoyPos==KEY_CENTER) {
LCDClear();
LCDStr ( 2, " CENTER ", 0 );
LCDStr ( 5, "exit ", 0 );
LCDUpdate();
}
}
goto label1;
}
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -