Curiosity好奇心开发板八位单片机分享
基于Curiosity开发板和PIC18446八位单片机做的简单小Demo,使用了定时器、串口、模数转换和按键等功能!
标签
嵌入式系统
砳此不疲
更新2021-04-16
864

MicroChip Curiosity 好奇心开发板 一.相关开发资源:

主控芯片PIC16f18446(好奇心开发板Curiosity)在Gitee上的代码资源链接:https://gitee.com/microchip-pic-avr-examples/pic16f18446-curiosity-lpc-demo-code.git

开发工具包:https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers#tabs

 

二.开发板的基本介绍:

这是一款嵌入式评估开发板,抛弃掉以往的32位单片机主控芯片,主控使用的是PIC八位芯片,还板载一个MikroBUS模块,可以说扩展性极强,不仅可以更换

 

三.工具的介绍:

MPLAB是一款集成IDE工具,不过需要针对不同位的单片机来安装不同的编译器种类,比如此次我们使用的八位单片机就需要安装XC8编译器

另外这个IDE还支持很多的插件,老师也给我们介绍了图形化配置代码的插件MCC,可以直接在IDE的Tool下进行安装。

接下来就是重点说一下MCC这个插件,我们用的非常多,因此作为一名新手也可能会在工具的配置上出现比较多的问题,刚开始我就出现了对很多的界面没法操作的问题:实际上是芯片的封装没有选择正确造成的,我们这款开发板的主控芯片应该选择DIP20。而且Pin Manage Grid View在IDE的左下角!!!

Pin_Packages

四.任务要求:

由于本次任务要求使用串口,所以需要对串口进行相应的配置,其实和STM32 CubeMX很相似,很容易就可以配置好相应的外设功能,然后我们直接传输速率、同步异步等参数进行修改就可以配置好串口,其余的外设配置方法也是类似的,下面就是我最后所使用的一些IO口以及其相应的配置!(途中LDE_2打错了,后来将LDE_2改成了LED_2

Pin_Manager

外设相应的配置:

UART1

timer0

ADC0

五.主要代码片段:

int fputc(int ch, FILE *f)  //重定义fputc函数,就可以直接使用printf串口打印了
{
       EUSART1_Write((uint8_t) ch);
       while(!EUSART1_is_tx_done());//check if send ok!
       return ch;
}
void ADC_ReadData(uint16_t result) //read data result from ADC from 0 to 4095
{
   double result_conversion;
   ADCC_StartConversion(channel_ANC0);
   //ADCC_StopConversion();
   while(!ADCC_IsConversionDone());
   result = ADCC_GetConversionResult();
   result_conversion = 0.6909*result;
   // printf("usart1 is ok! \r\n ");
   printf("Potentiometer information is:%0.2f ohm \r\n",result_conversion);// print ADC converter data
}

 

void main(void) //主函数 记得一定要在这里使能一下中断
{
   uint16_t a,i;
   uint8_t button_state,b;
   extern uint16_t count_num;
   // initialize the device
   SYSTEM_Initialize();  //no timer initialization
   Timer0_Init();
   // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
   // Use the following macros to:

   // Enable the Global Interrupts
   INTERRUPT_GlobalInterruptEnable();

   // Enable the Peripheral Interrupts
   INTERRUPT_PeripheralInterruptEnable();

   // Disable the Global Interrupts
   //INTERRUPT_GlobalInterruptDisable();

   // Disable the Peripheral Interrupts
   //INTERRUPT_PeripheralInterruptDisable();
   while (1)//check the button and
  {
       LED_1_SetLow();
       LED_2_SetLow();
       LED_3_SetLow();
       button_state=Button_GetValue();
       if(button_state==0)//when the key is pressed
      {
           DELAY_milliseconds(10);//wait for 10ms
           if(button_state==0)
          {
                DELAY_milliseconds(10);//wait for 10ms
               TMR0_StartTimer();//start counting
               button_state=Button_GetValue();//check again
               if(button_state==1)
                  {
                     
                       if(button_state==1&&count_num==0)
                          {
                            printf("%d \r\n\n",count_num);
                               TMR0_StopTimer();
                               count_num=0;
                               ADC_ReadData(a);
                               printf("the key is clicked! \r\n\n");
                               LED_1_SetHigh();
                               DELAY_milliseconds(300);
                          }
                       if(button_state==1&&count_num>=1&&count_num<5)
                          {
                               printf("%d \r\n\n",count_num);
                               TMR0_StopTimer();
                               count_num=0;
                               ADC_ReadData(a);
                               printf("the key is pressed between 1 and 5 Sec! \r\n\n");
                               LED_2_SetHigh();
                               DELAY_milliseconds(300);
                                                   
                          }
                        if(button_state==1&&count_num>=5)
                          {
                               printf("%d \r\n\n",count_num);
                               TMR0_StopTimer();
                               count_num=0;
                               ADC_ReadData(a);
                               printf("the key is pressed over 5 Sec! \r\n\n");
                               LED_3_SetHigh();
                               DELAY_milliseconds(300);
                          }
                  }
               
          }
      }
       
       // Add your application code
 
   //     DELAY_milliseconds(500);
  }
}

六.心得和体会:

非常感谢得捷电子和硬禾学堂对Funpack活动的大力支持,主要补全了以前没有玩过八位单片机的遗憾,而且更加深入了对硬件的理解!

附件下载
demo.zip
团队介绍
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号