- #include "main.h"
- #include "ac780x_gpio.h"
- #include "ucos_ii.h"
- #include "ac780x_uart.h"
- #include "ac780x_uart_reg.h"
- static OS_STK s_task0Stk [Task0StkLengh]; /* Define the DemoTask0 stack */
- static OS_STK s_task1Stk [Task1StkLengh]; /* Define the DemoTask1 stack */
- #define KEY_PRESS (GPIO_LEVEL_LOW)
- #define KEY_RELEASE (GPIO_LEVEL_HIGH)
- #define KEY6_PORT (GPIOC)
- #define KEY6_PIN (GPIO_PIN6)
- #define KEY7_PORT (GPIOA)
- #define KEY7_PIN (GPIO_PIN11)
- #define GET_KEY6_STS() (GPIO_GetPinLevel(KEY6_PORT, KEY6_PIN))
- #define GET_KEY7_STS() (GPIO_GetPinLevel(KEY7_PORT, KEY7_PIN))
- uint32_t TT;
- uint32_t NG;
- void mydelay()
- {
- uint16_t nn=0;
- for(nn=0;nn<3000;nn++)
- {
- }
- }
- void EXTI_Key6_Callback(void *device, uint32_t wpara, uint32_t lpara)
- {
- if (GET_KEY6_STS() == KEY_PRESS)
- {
- TT=TT+1;
- NG=NG+1;
- }
- }
- void EXTI_Key7_Callback(void *device, uint32_t wpara, uint32_t lpara)
- {
- if (GET_KEY7_STS() == KEY_PRESS)
- {
- TT=TT+1;
- }
- }
- void KEY_Init(void)
- {
- GPIO_SetFunc(KEY6_PORT, KEY6_PIN, GPIO_FUN0);
- GPIO_SetFunc(KEY7_PORT, KEY7_PIN, GPIO_FUN0);
- GPIO_SetDir(KEY6_PORT, KEY6_PIN, GPIO_IN);
- GPIO_SetDir(KEY7_PORT, KEY7_PIN, GPIO_IN);
- GPIO_SetPullup(KEY6_PORT, KEY6_PIN, ENABLE);
- GPIO_SetPullup(KEY7_PORT, KEY7_PIN, ENABLE);
- GPIO_EnableExternalInterrupt(KEY6_PORT, KEY6_PIN, EXTI_TRIGGER_FALLING);
- GPIO_EnableExternalInterrupt(KEY7_PORT, KEY7_PIN, EXTI_TRIGGER_FALLING);
- GPIO_SetCallback(KEY6_PIN, EXTI_Key6_Callback);
- GPIO_SetCallback(KEY7_PIN, EXTI_Key7_Callback);
- }
- void UART1_Init(void)
- {
- GPIO_SetFunc(GPIOA,GPIO_PIN4, GPIO_FUN3);
- GPIO_SetFunc(GPIOA,GPIO_PIN5, GPIO_FUN3);
- CKGEN_Enable(CLK_UART1, ENABLE);
- CKGEN_SoftReset(SRST_UART1, ENABLE);
- UART_SetDivisor(UART1, (float)APB_BUS_FREQ / 16 / 9600);
- UART_SetDataBits(UART1, UART_WORD_LEN_8BIT);
- UART_SetStopBit(UART1, UART_STOP_1BIT);
- UART_EnableTX(UART1, ENABLE);
- UART_EnableRX(UART1, ENABLE);
- UART_Set2ByteFIFO(UART1, ENABLE);
- UART_SetInterruptEn(UART1, 9);
- }
- int main(void)
- {
- TT=0;
- NG=0;
- UART1_Init();
- KEY_Init();
- SysTick_Config(SYSTICK_CLOCK);
- OSInit();
- OSTaskCreate(DemoTask0, (void *)0, &s_task0Stk[Task0StkLengh - 1], Task0Prio);
- OSTaskCreate(DemoTask1, (void *)0, &s_task1Stk[Task1StkLengh - 1], Task1Prio);
- OSStart();
- return 0;
- }
- void DemoTask0(void *pdata)
- {
- uint8_t SendBuf[11];
- uint8_t ll=0;
- SendBuf[0]='n';
- SendBuf[1]='0';
- SendBuf[2]='.';
- SendBuf[3]='v';
- SendBuf[4]='a';
- SendBuf[5]='l';
- SendBuf[6]='=';
- SendBuf[7]='1';
- SendBuf[8]=0xff;
- SendBuf[9]=0xff;
- SendBuf[10]=0xff;
- while (1)
- {
- SendBuf[7]=TT+0x30;
- for (ll=0;ll<11;ll++)
- {
- UART_SendData(UART1, SendBuf[ll]);
- mydelay();
- }
- OSTimeDly(97);
- }
- }
- void DemoTask1(void *pdata)
- {
- uint8_t SendBuf[11];
- uint8_t ll=0;
- SendBuf[0]='n';
- SendBuf[1]='1';
- SendBuf[2]='.';
- SendBuf[3]='v';
- SendBuf[4]='a';
- SendBuf[5]='l';
- SendBuf[6]='=';
- SendBuf[7]='1';
- SendBuf[8]=0xff;
- SendBuf[9]=0xff;
- SendBuf[10]=0xff;
- while (1)
- {
- SendBuf[7]=NG+0x30;
- for (ll=0;ll<11;ll++)
- {
- UART_SendData(UART1, SendBuf[ll]);
- mydelay();
- }
- OSTimeDly(103);
- }
- }
七、学习将视频上传
将上述代码编译烧录,看看效果,完全符合设计思路,也具有实用价值,哈哈哈哈
下面演示按钮,视频网址如下:https://www.bilibili.com/video/BV1n54y1Q77A
K7:生产线产品的良品过站,将生产总数+1;
K6:生产线产品检测到不良品,将生产总数+1同时将不良品数量+1;
八、开发板评价
1. AutoChips的这个M0系列的开发板,方便使用;
2. 代码风格和指令有一些特殊,上手时候要看看示例才可以
3. 外设功能大同小异,指令有一些不太一样,看过手册也都能明白
4. 这块开发板的其它功能,待后续慢慢搞
5. 最后,为二姨家举办这样的活动,点赞!!
@21ic小喇叭 ,@21小跑堂 ,我提交作业啦