做个key和led显示程序。
main 程序
- #include
- #include "wm_hal.h"
- void Error_Handler(void);
- static void GPIO_Init(void);
- static volatile uint8_t key_flag = 0;
- int main(void)
- {
- SystemClock_Config(CPU_CLK_160M);
- printf("enter mainrn");
- HAL_Init();
- GPIO_Init();
-
- while (1)
- {
- HAL_Delay(500);
- key_flag++;
- if(key_flag%3==0)
- {
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0,0);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,1);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2,1);
- printf("uwTick=uint32_t HAL_GetTick(void);;%drn", HAL_GetTick());
- }
- else if(key_flag%3==1)
- {
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0,1);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,0);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2,1);
- }
- else
- {
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0,1);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,1);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2,0);
- }
-
- }
-
- return 0;
- }
- static void GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- __HAL_RCC_GPIO_CLK_ENABLE();
- GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, GPIO_PIN_SET);
-
- GPIO_InitStruct.Pin = GPIO_PIN_5;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- HAL_NVIC_SetPriority(GPIOB_IRQn, 0);
- HAL_NVIC_EnableIRQ(GPIOB_IRQn);
- }
- void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
- {
- if ((GPIOx == GPIOB) && (GPIO_Pin == GPIO_PIN_5))
- {
- key_flag = 1;
- printf("enter EXTI-GPIOB_PIN_5rn");
- }
- if ((GPIOx == GPIOA) && (GPIO_Pin == GPIO_PIN_0))
- {
- key_flag = 1;
- printf("enter EXTI-GPIOA_PIN_0rn");
- }
- }
- void Error_Handler(void)
- {
- while (1)
- {
- }
- }
- void assert_failed(uint8_t *file, uint32_t line)
- {
- printf("Wrong parameters value: file %s on line %drn", file, line);
- }
复制代码
wm_it.c
- #include "wm_hal.h"
- __attribute__((isr)) void CORET_IRQHandler(void)
- {
- uint32_t temp;
-
- temp = (*(volatile unsigned int *) (0xE000E010));
- HAL_IncTick();
- }
- __attribute__((isr)) void GPIOA_IRQHandler(void)
- {
- HAL_GPIO_EXTI_IRQHandler(GPIOA, GPIO_PIN_0);
- }
- __attribute__((isr)) void GPIOB_IRQHandler(void)
- {
- HAL_GPIO_EXTI_IRQHandler(GPIOB, GPIO_PIN_5);
- }
复制代码
Build target ' W805_SDK BuildSet '
"----------Building project:[ W805_SDK - BuildSet ]----------"
csky-elfabiv2-gcc -c ../../../../../../../app/src/main.c -mcpu=ck804ef -mhard-float -DGCC_COMPILE=1 -DTLS_CONFIG_CPU_XT804=1 -O2 -g3 -Wall -ffunction-sections -fdata-sections -c -MMD -MP -MTObj/src_main.o -MFObj/src_main.d -o Obj/src_main.o -I../../../../../../../../../C-Sky/CDK/CSKY/MinGW/csky-abiv2-elf-toolchain/csky-elfabiv2/include -I. -I../../../../../../../include -I../../../../../../../include/arch/xt804 -I../../../../../../../include/arch/xt804/csi_core -I../../../../../../../include/arch/xt804/csi_dsp -I../../../../../../../include/driver -I../../../../../../../app/inc
csky-elfabiv2-gcc -o Obj/W805.elf -Wl,-zmax-page-size=1024 -mhard-float -Wl,--ckmap=.//Lst/W805.map @W805_SDK.txt -mcpu=ck804ef -mhard-float -nostartfiles -Wl,--gc-sections -T"./../../../../../../../ld/W805/gcc_csky.ld" -L../../../../../../../lib/W805 -Wl,--start-group -Wl,--end-group -ldsp
csky-elfabiv2-objdump -S .//Obj/W805.elf > .//Lst/W805.asm
size of target:
text data bss dec hex filename
14188 96 4624 18908 49dc ./Obj/W805.elf
checksum value of target:0x015EAAF4 (1,086,988)
Obj/W805.elf is modified at: 2021/11/29/ÖÜÒ» 13:27:17
Executing Post Build commands ...
W805
1
generate normal image completed.
generate normal image completed.
compress binary completed.
generate compressed image completed.
Done
====0 error(s), 0 warning(s), total time : 5s56ms====
key(pb5)