[PIC®/AVR®/dsPIC®产品] AVR64DD32测试程序

[复制链接]
 楼主| 稳稳の幸福 发表于 2024-4-15 22:16 | 显示全部楼层 |阅读模式
  1. /*
  2.     (c) 2018 Microchip Technology Inc. and its subsidiaries.
  3.    
  4.     Subject to your compliance with these terms, you may use Microchip software and any
  5.     derivatives exclusively with Microchip products. It is your responsibility to comply with third party
  6.     license terms applicable to your use of third party software (including open source software) that
  7.     may accompany Microchip software.
  8.    
  9.     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  10.     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
  11.     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
  12.     FOR A PARTICULAR PURPOSE.
  13.    
  14.     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  15.     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  16.     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
  17.     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
  18.     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
  19.     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
  20.     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
  21.     SOFTWARE.
  22. */

  23. #include "mcc_generated_files/mcc.h"
  24. #include <util/delay.h>

  25. #define BLINK_DELAY         500
  26. #define RAMP_DELAY          300
  27. #define DV_START_VALUE      0x03
  28. #define DV_STOP_VALUE       0xFC

  29. /*
  30.     Main application
  31. */

  32. typedef enum {BLINKY, BUTTON, RAMP} programs_t;

  33. static uint8_t Unblocking_Read(void);
  34. static void Print_Menu(void);
  35. static void CLI_Execute_Command(uint8_t);
  36. static void CLI_Run(void);
  37. static void DEMO_Run(void);
  38. static void Blink_LED(void);
  39. static void Button_LED(void);
  40. static void Send_DataVisualizer_Ramp(void);
  41. static void USART_to_CDC(void);

  42. static programs_t current_program = BLINKY;

  43. int main (void)
  44. {  
  45.     SYSTEM_Initialize();
  46.     USART_to_CDC();
  47.     Print_Menu();
  48.        
  49.     while(1)
  50.     {
  51.         CLI_Run();
  52.         DEMO_Run();
  53.     }
  54. }

  55. static void USART_to_CDC(void)
  56. {
  57.     PORTD.DIRSET = PIN4_bm;
  58.     PORTMUX.USARTROUTEA = PORTMUX_USART0_ALT3_gc;
  59. }

  60. static uint8_t Unblocking_Read(void)
  61. {
  62.     if(USART0_IsRxReady() != 0)
  63.     {
  64.         return USART0_Read();
  65.     }
  66.     else
  67.     {
  68.         return '\0';
  69.     }
  70. }

  71. static void Print_Menu(void)
  72. {
  73.     printf("\n\r");
  74.     printf("********************************************************************************************************\n\r");
  75.     printf("*                        Out of the box application for AVR64DD32 Curiosity Nano                       *\n\r");
  76.     printf("********************************************************************************************************\n\r");
  77.     printf("*        MMMMMMMMMNddhysyyyysyyhdmMMNNNMMMMM                                                           *\r\n");
  78.     printf("*        MMMMMMmhssssssssssssssssshMNmmMMMMM                                                           *\r\n");
  79.     printf("*        MMMMdyssssssssssssssssssssyNMMMMMMM                                                           *\r\n");
  80.     printf("*        MMmyssssso-`.ossssssso-.-osymMMMMMM                                                           *\r\n");
  81.     printf("*        Mdssssss/`   `/sssss:    `+ssdMMMMM       __  __ _                     _     _                *\r\n");
  82.     printf("*        mssssss/       -sss-       /ssyNMMM      |  \\/  (_)                   | |   (_)               *\r\n");
  83.     printf("*        yssssoso-       .oso.       -ssymMM      | \\  / |_  ___ _ __ ___   ___| |__  _ _ __           *\r\n");
  84.     printf("*        ysso- -ss/`      `/ss-       .ossdM      | |\\/| | |/ __| '__/ _ \\ / __| '_ \\| | '_ \\          *\r\n");
  85.     printf("*        ys+`   .os+`       :ss/`      `/ssh      | |  | | | (__| | | (_) | (__| | | | | |_) |         *\r\n");
  86.     printf("*        y:      `+so-       .os+`       :sh      |_|  |_|_|\\___|_|  \\___/ \\___|_| |_|_| .__/          *\r\n");
  87.     printf("*        m`      -osss/       -sso-       /M                                           | |             *\r\n");
  88.     printf("*        Mh`   `/ssssss+`    :sssss/     -NM                                           |_|             *\r\n");
  89.     printf("*        MMm: -osssssssso-`.+sssssss+`  +NMM                                                           *\r\n");
  90.     printf("*        MMMMhysssssssssssssssssssssso+mMMMM                                                           *\r\n");
  91.     printf("*        MMMMMMNdysssssssssssssssssydNMMMMMM                                                           *\r\n");
  92.     printf("*        MMMMMMMMMNmdhyyysssyyhhdmMMMMMMMMMM                                                           *\r\n");
  93.     printf("********************************************************************************************************\n\r");
  94.     printf("*                                                                                                      *\n\r");
  95.     printf("* -Press a key corresponding to a program:                                                             *\n\r");
  96.     printf("*  '1' - Default program; Blinking LED                                                                 *\n\r");
  97.     printf("*  '2' - LED turns on while button is pressed                                                          *\n\r");
  98.     printf("*  '3' - An ascending ramp visible in MPLAB Data Visualizer sent through USART while button is pressed *\n\r");
  99.     printf("*                                                                                                      *\n\r");
  100.     printf("* -Press any other key to view the menu again.                                                         *\n\r");
  101.     printf("*                                                                                                      *\n\r");
  102.     printf("********************************************************************************************************\n\r");
  103. }

  104. static void CLI_Execute_Command(uint8_t command)
  105. {
  106.     switch(command)
  107.     {
  108.         case '1':
  109.             current_program = BLINKY;
  110.             printf("Program changed to blink LED\r\n");
  111.             break;
  112.         case '2':
  113.             LED_SetHigh();
  114.             current_program = BUTTON;
  115.             printf("Program changed to press button to turn on LED\r\n");
  116.             break;
  117.         case '3':
  118.             LED_SetHigh();
  119.             current_program = RAMP;
  120.             printf("Program changed to press button to send a ramp through USART\r\n");
  121.             break;
  122.         default:
  123.             Print_Menu();
  124.             break;
  125.     }
  126. }

  127. static void CLI_Run(void)
  128. {
  129.     uint8_t ch = 0;
  130.    
  131.     ch = Unblocking_Read();
  132.    
  133.     if((ch != '\n') && (ch != '\r') && (ch != '\0'))
  134.     {
  135.         CLI_Execute_Command(ch);
  136.     }
  137. }

  138. static void DEMO_Run(void)
  139. {
  140.     if(current_program == BLINKY)
  141.     {
  142.         Blink_LED();
  143.     }
  144.     else if(current_program == BUTTON)
  145.     {
  146.         Button_LED();
  147.     }
  148.     else if(current_program == RAMP)
  149.     {
  150.         Send_DataVisualizer_Ramp();
  151.     }
  152. }

  153. static void Blink_LED(void)
  154. {
  155.     LED_Toggle();
  156.     _delay_ms(BLINK_DELAY);
  157. }

  158. static void Button_LED(void)
  159. {
  160.     if(Button_GetValue())
  161.     {
  162.         LED_SetHigh();
  163.     }
  164.     else
  165.     {
  166.         LED_SetLow();
  167.     }
  168. }

  169. static void Send_DataVisualizer_Ramp(void)
  170. {
  171.     static uint8_t counter = 0;

  172.     if(!Button_GetValue())
  173.     {
  174.         USART0_Write(DV_START_VALUE);
  175.         USART0_Write(counter++);
  176.         USART0_Write(DV_STOP_VALUE);
  177.         _delay_ms(RAMP_DELAY);
  178.     }
  179. }
  180. /**
  181.     End of File
  182. */


 楼主| 稳稳の幸福 发表于 2024-4-15 22:16 | 显示全部楼层
涵盖了,执行串口指令,Blink,按钮等测试。
呐咯密密 发表于 2024-4-17 20:49 | 显示全部楼层
这个**打印很好玩
643757107 发表于 2024-4-20 22:44 | 显示全部楼层
点灯,按钮,串口,打印测试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

203

主题

3409

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部