PIC24F16KL402开发板使用笔记一: 搭建基本开发环境

申请的PIC24F16KL402开发板使用笔记一: 搭建基本开发环境

开发板类型: Microchiop用于3v PIC24 K系列的Microstick开发板
Author: ARIC

Step 1: 启动开发工具,非常友好的开发界面。


Step 2:使用向导新建一个模板。
 
Step 3:第一个Helloworld的程序
点亮这个LED0
Code:

  1. #include <xc.h>
  2. // Configuration Bits to make the part run from Internal FRCDIV
  3. // Oscillator.
  4. _FBS
  5. (
  6.     BWRP_OFF &      // Boot Segment Write Protect (Disabled)
  7.     BSS_OFF         // Boot segment Protect (No boot flash segment)
  8. )
  9. _FGS
  10. (
  11.     GWRP_OFF &      // General Segment Flash Write Protect (General segment may be written)
  12.     GSS0_OFF        // General Segment Code Protect (No Protection)
  13. )
  14. _FOSCSEL
  15. (
  16.     FNOSC_FRCDIV &  // Oscillator Select (8MHz FRC with Postscaler (FRCDIV))
  17.     SOSCSRC_ANA &   // SOSC Source Type (Analog Mode for use with crystal)
  18.     LPRCSEL_HP &    // LPRC Power and Accuracy (High Power/High Accuracy)
  19.     IESO_ON         // Internal External Switch Over bit (Internal External Switchover mode enabled (Two-speed Start-up enabled))
  20. )
  21. _FOSC
  22. (
  23.     POSCMD_NONE &   // Primary Oscillator Mode (Primary oscillator disabled)
  24.     OSCIOFNC_ON &   // CLKO Enable Configuration bit (CLKO output signal enabled)
  25.     POSCFREQ_MS &   // Primary Oscillator Frequency Range Configuration bits (Primary oscillator/external clock frequency between 100kHz to 8MHz)
  26.     SOSCSEL_SOSCHP &// SOSC Power Selection Configuration bits (Secondary Oscillator configured for high-power operation)
  27.     FCKSM_CSECME    // Clock Switching and Monitor Selection (Clock Switching and Fail-safe Clock Monitor Enabled)
  28. )
  29. _FWDT
  30. (
  31.     WDTPS_PS32768 & // Watchdog Timer Postscale Select bits (1:32768)
  32.     FWPSA_PR128 &   // WDT Prescaler bit (WDT prescaler ratio of 1:128)
  33.     FWDTEN_OFF &    // Watchdog Timer Enable bits (WDT disabled in hardware; SWDTEN bit disabled)
  34.     WINDIS_OFF      // Windowed Watchdog Timer Disable bit (Standard WDT selected (windowed WDT disabled))
  35. )
  36. // Warning:
  37. // Always enable MCLRE_ON config bit setting so that the MCLR pin function will
  38. // work for low-voltage In-Circuit Serial Programming (ICSP). The Microstick
  39. // programming circuitry only supports low-voltage ICSP. If you disable MCLR pin
  40. // functionality, a high-voltage ICSP tool will be required to re-program the
  41. // part in the future.
  42. _FPOR
  43. (
  44.     BOREN_BOR3 &    // Brown-out Reset Enable bits (Enabled in hardware; SBOREN bit disabled)
  45.     PWRTEN_ON &     // Power-up Timer Enable (PWRT enabled)
  46.     I2C1SEL_PRI &   // Alternate I2C1 Pin Mapping bit (Default SCL1/SDA1 Pins for I2C1)
  47.     BORV_V18 &      // Brown-out Reset Voltage bits (Brown-out Reset at 1.8V)
  48.     MCLRE_ON        // MCLR Pin Enable bit (RA5 input disabled; MCLR enabled)
  49. )
  50. _FICD
  51. (
  52.     ICS_PGx3        // ICD Pin Placement Select (EMUC/EMUD share PGC3/PGD3)
  53. )
  54. void DelaymS(unsigned int del) 
  55. {
  56.         unsigned int j;
  57.         while(del--) 
  58.       for(j=0;j<1600;j++);
  59. }
  60. int main(void)
  61. {
  62.     unsigned int i;
  63.     // Set up output pin for LED
  64.     TRISAbits.TRISA0 = 0;
  65.     while(1)
  66.     {
  67.         // (insert your application code here)
  68.         DelaymS(500);
  69.         // Toggle the LED output pin to alternate between the LED being on and off
  70.         LATAbits.LATA0 ^= 1;
  71.     }
  72. }
  73. Step 4:编译链接并下载
  74. 插上开发板,点击"运行项目“,就可以看到LED开始blink.
粽子糖果 发表于10-26 10:30 浏览65535次
分享到:

已有0条评论

暂时还没有回复哟,快来抢沙发吧

添加一条新评论

只有登录用户才能评论,请先登录注册哦!

话题作者

粽子糖果
粽子糖果(总统)
金币:41631个|学分:51991个
立即注册
畅学电子网,带你进入电子开发学习世界
专业电子工程技术学习交流社区,加入畅学一起充电加油吧!

x

畅学电子网订阅号