add practice projs
This commit is contained in:
parent
9a350fc0cc
commit
728c4925ea
13 changed files with 1279 additions and 0 deletions
33
myapps/practice/02-button-int/src/main.c
Normal file
33
myapps/practice/02-button-int/src/main.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// TODO fix line 27
|
||||
// LED: PA8 (active low)
|
||||
// BUT: PB22 (active low, no pullup)
|
||||
|
||||
#include "CH59x_common.h"
|
||||
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void GPIOB_IRQHandler()
|
||||
{
|
||||
if (GPIOB_ReadITFlagBit(GPIO_Pin_8)) {
|
||||
GPIOA_InverseBits(GPIO_Pin_8);
|
||||
GPIOB_ClearITFlagBit(GPIO_Pin_8);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
SetSysClock(CLK_SOURCE_PLL_60MHz);
|
||||
|
||||
GPIOA_SetBits(GPIO_Pin_8); // LED
|
||||
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
|
||||
|
||||
GPIOB_ModeCfg(GPIO_Pin_22, GPIO_ModeIN_PU); // button
|
||||
GPIOB_ITModeCfg(GPIO_Pin_8, GPIO_ITMode_FallEdge); // PB8 mux'd as PB22 see below
|
||||
GPIOB_ClearITFlagBit(GPIO_Pin_8);
|
||||
GPIOPinRemap(ENABLE, RB_PIN_INTX); // <================== workaround, as R16_PB_INT reg is 16b wide
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
while (1);
|
||||
|
||||
}
|
||||
|
||||
41
myapps/practice/02-button-int/src/main.c.bkp1
Normal file
41
myapps/practice/02-button-int/src/main.c.bkp1
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
// LED: PA8 (active low)
|
||||
// BUT: PB22 (active low, no pullup)
|
||||
|
||||
#include "CH59x_common.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
volatile bool buttonPressed = false;
|
||||
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void GPIOB_IRQHandler()
|
||||
{
|
||||
if (GPIOB_ReadITFlagBit(GPIO_Pin_8)) {
|
||||
buttonPressed = true;
|
||||
GPIOB_ClearITFlagBit(GPIO_Pin_8);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
SetSysClock(CLK_SOURCE_PLL_60MHz);
|
||||
|
||||
GPIOA_SetBits(GPIO_Pin_8); // LED
|
||||
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
|
||||
|
||||
GPIOB_ModeCfg(GPIO_Pin_22, GPIO_ModeIN_PU); // button
|
||||
GPIOB_ITModeCfg(GPIO_Pin_8, GPIO_ITMode_FallEdge);
|
||||
GPIOB_ClearITFlagBit(GPIO_Pin_8);
|
||||
GPIOPinRemap(ENABLE, RB_PIN_INTX); // <==================
|
||||
PFIC_EnableIRQ(GPIO_B_IRQn);
|
||||
|
||||
while (1) {
|
||||
if (buttonPressed) {
|
||||
buttonPressed = false;
|
||||
GPIOA_InverseBits(GPIO_Pin_8);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue