搜索
bottom↓
回复: 63

PIC16F1824有什么C编译器能用?

[复制链接]

出0入0汤圆

发表于 2013-6-14 13:03:34 | 显示全部楼层 |阅读模式
本帖最后由 1125526801 于 2013-6-15 09:24 编辑

PIC16F1824有什么C编译器能用?之前学习板上的单片机不一样是18F4520,用的MCC18。PIC16F1824是用PICC吗?





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2013-6-14 15:29:16 | 显示全部楼层
我用的PICC9.71A。

出0入0汤圆

发表于 2013-6-14 15:31:09 | 显示全部楼层
XC8破解了谁还用PICC那个老掉牙的东西?

出0入0汤圆

发表于 2013-6-14 16:01:47 | 显示全部楼层
老不见得就不好,够用就可以了,不必盲目追高,新版编译器有可能BUG会多一些。

出0入0汤圆

发表于 2013-6-14 16:16:59 | 显示全部楼层
i55x 发表于 2013-6-14 15:31
XC8破解了谁还用PICC那个老掉牙的东西?

Sir:

Where is the "XC8破解"?

Thank you.

出0入0汤圆

 楼主| 发表于 2013-6-14 18:16:22 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-15 09:25 编辑

前辈们,PIC16F1824,帮忙给个流水灯程序吧。。。折腾了一天都没亮灯。。。。实然觉得学了几年STC白学了。。。。。。。。。


头文件PIC16F1824.h

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2013-6-14 18:37:35 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-14 18:52 编辑


电路图。
  1. #include <pic16f1824.h>       //调用头文件,

  2. //---------------------------------------
  3. //名称: 主函数                 
  4. //-----------------------------------------
  5. void main(void)
  6. {       
  7.         TRISA=0B00000000;       //RA设置为输出
  8.         TRISC=0B00000000;           //RC设置为输出
  9.         PORTC=0B00000000;       //RA的LED全亮
  10.         PORTA=0B00000000;       //RC的LED全亮
  11. }
复制代码
难道还要配置时钟?怎么配置?内部时钟。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-6-14 21:30:22 | 显示全部楼层
难道还要配置时钟?怎么配置?内部时钟。


read the datasheet and then read the compiler manual.

no other way out.

出0入0汤圆

发表于 2013-6-14 21:30:51 | 显示全部楼层
谁还用PICC那个老掉牙的东西?


I do.      

出0入0汤圆

发表于 2013-6-14 22:42:33 | 显示全部楼层
CCS也不错

出0入0汤圆

发表于 2013-6-14 22:46:23 | 显示全部楼层
一直使用PICC的路过.

出0入0汤圆

发表于 2013-6-14 23:10:14 | 显示全部楼层
config1 config2需要配置的

出0入0汤圆

 楼主| 发表于 2013-6-15 09:15:16 | 显示全部楼层
millwood0 发表于 2013-6-14 21:30
read the datasheet and then read the compiler manual.

no other way out.

ok,thank you

出0入0汤圆

 楼主| 发表于 2013-6-15 09:19:34 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-15 09:38 编辑
yklstudent 发表于 2013-6-14 23:10
config1 config2需要配置的


除了学习板上的18F4520我还没用过其它PIC单片机。装了XC8免费版后,才找到PIC16F1824.h头文件。发现照搬之前的时钟配置
config过来用不了。打开之前用的PIC.h和现在的PIC16F1824.h对比,差远了。。。。

时钟不知道怎么配置。在DEBUG状态LED是能亮了。拔了仿真,直接给电不会运行。

头文件的部分:
  1. // Register: OSCCON
  2. extern volatile unsigned char           OSCCON              @ 0x099;
  3. #ifndef _LIB_BUILD
  4. asm("OSCCON equ 099h");
  5. #endif
  6. // bitfield definitions
  7. typedef union {
  8.     struct {
  9.         unsigned SCS0                   :1;
  10.         unsigned SCS1                   :1;
  11.         unsigned                        :1;
  12.         unsigned IRCF0                  :1;
  13.         unsigned IRCF1                  :1;
  14.         unsigned IRCF2                  :1;
  15.         unsigned IRCF3                  :1;
  16.         unsigned SPLLEN                 :1;
  17.     };
  18.     struct {
  19.         unsigned SCS                    :2;
  20.         unsigned                        :1;
  21.         unsigned IRCF                   :4;
  22.     };
  23. } OSCCONbits_t;
  24. extern volatile OSCCONbits_t OSCCONbits @ 0x099;
  25. // bitfield macros
  26. #define _OSCCON_SCS0_POSN                                   0x0
  27. #define _OSCCON_SCS0_POSITION                               0x0
  28. #define _OSCCON_SCS0_SIZE                                   0x1
  29. #define _OSCCON_SCS0_LENGTH                                 0x1
  30. #define _OSCCON_SCS0_MASK                                   0x1
  31. #define _OSCCON_SCS1_POSN                                   0x1
  32. #define _OSCCON_SCS1_POSITION                               0x1
  33. #define _OSCCON_SCS1_SIZE                                   0x1
  34. #define _OSCCON_SCS1_LENGTH                                 0x1
  35. #define _OSCCON_SCS1_MASK                                   0x2
  36. #define _OSCCON_IRCF0_POSN                                  0x3
  37. #define _OSCCON_IRCF0_POSITION                              0x3
  38. #define _OSCCON_IRCF0_SIZE                                  0x1
  39. #define _OSCCON_IRCF0_LENGTH                                0x1
  40. #define _OSCCON_IRCF0_MASK                                  0x8
  41. #define _OSCCON_IRCF1_POSN                                  0x4
  42. #define _OSCCON_IRCF1_POSITION                              0x4
  43. #define _OSCCON_IRCF1_SIZE                                  0x1
  44. #define _OSCCON_IRCF1_LENGTH                                0x1
  45. #define _OSCCON_IRCF1_MASK                                  0x10
  46. #define _OSCCON_IRCF2_POSN                                  0x5
  47. #define _OSCCON_IRCF2_POSITION                              0x5
  48. #define _OSCCON_IRCF2_SIZE                                  0x1
  49. #define _OSCCON_IRCF2_LENGTH                                0x1
  50. #define _OSCCON_IRCF2_MASK                                  0x20
  51. #define _OSCCON_IRCF3_POSN                                  0x6
  52. #define _OSCCON_IRCF3_POSITION                              0x6
  53. #define _OSCCON_IRCF3_SIZE                                  0x1
  54. #define _OSCCON_IRCF3_LENGTH                                0x1
  55. #define _OSCCON_IRCF3_MASK                                  0x40
  56. #define _OSCCON_SPLLEN_POSN                                 0x7
  57. #define _OSCCON_SPLLEN_POSITION                             0x7
  58. #define _OSCCON_SPLLEN_SIZE                                 0x1
  59. #define _OSCCON_SPLLEN_LENGTH                               0x1
  60. #define _OSCCON_SPLLEN_MASK                                 0x80
  61. #define _OSCCON_SCS_POSN                                    0x0
  62. #define _OSCCON_SCS_POSITION                                0x0
  63. #define _OSCCON_SCS_SIZE                                    0x2
  64. #define _OSCCON_SCS_LENGTH                                  0x2
  65. #define _OSCCON_SCS_MASK                                    0x3
  66. #define _OSCCON_IRCF_POSN                                   0x3
  67. #define _OSCCON_IRCF_POSITION                               0x3
  68. #define _OSCCON_IRCF_SIZE                                   0x4
  69. #define _OSCCON_IRCF_LENGTH                                 0x4
  70. #define _OSCCON_IRCF_MASK                                   0x78

  71. // Register: OSCSTAT
  72. extern volatile unsigned char           OSCSTAT             @ 0x09A;
  73. #ifndef _LIB_BUILD
  74. asm("OSCSTAT equ 09Ah");
  75. #endif
  76. // bitfield definitions
  77. typedef union {
  78.     struct {
  79.         unsigned HFIOFS                 :1;
  80.         unsigned LFIOFR                 :1;
  81.         unsigned MFIOFR                 :1;
  82.         unsigned HFIOFL                 :1;
  83.         unsigned HFIOFR                 :1;
  84.         unsigned OSTS                   :1;
  85.         unsigned PLLR                   :1;
  86.         unsigned T1OSCR                 :1;
  87.     };
  88. } OSCSTATbits_t;
  89. extern volatile OSCSTATbits_t OSCSTATbits @ 0x09A;
  90. // bitfield macros
  91. #define _OSCSTAT_HFIOFS_POSN                                0x0
  92. #define _OSCSTAT_HFIOFS_POSITION                            0x0
  93. #define _OSCSTAT_HFIOFS_SIZE                                0x1
  94. #define _OSCSTAT_HFIOFS_LENGTH                              0x1
  95. #define _OSCSTAT_HFIOFS_MASK                                0x1
  96. #define _OSCSTAT_LFIOFR_POSN                                0x1
  97. #define _OSCSTAT_LFIOFR_POSITION                            0x1
  98. #define _OSCSTAT_LFIOFR_SIZE                                0x1
  99. #define _OSCSTAT_LFIOFR_LENGTH                              0x1
  100. #define _OSCSTAT_LFIOFR_MASK                                0x2
  101. #define _OSCSTAT_MFIOFR_POSN                                0x2
  102. #define _OSCSTAT_MFIOFR_POSITION                            0x2
  103. #define _OSCSTAT_MFIOFR_SIZE                                0x1
  104. #define _OSCSTAT_MFIOFR_LENGTH                              0x1
  105. #define _OSCSTAT_MFIOFR_MASK                                0x4
  106. #define _OSCSTAT_HFIOFL_POSN                                0x3
  107. #define _OSCSTAT_HFIOFL_POSITION                            0x3
  108. #define _OSCSTAT_HFIOFL_SIZE                                0x1
  109. #define _OSCSTAT_HFIOFL_LENGTH                              0x1
  110. #define _OSCSTAT_HFIOFL_MASK                                0x8
  111. #define _OSCSTAT_HFIOFR_POSN                                0x4
  112. #define _OSCSTAT_HFIOFR_POSITION                            0x4
  113. #define _OSCSTAT_HFIOFR_SIZE                                0x1
  114. #define _OSCSTAT_HFIOFR_LENGTH                              0x1
  115. #define _OSCSTAT_HFIOFR_MASK                                0x10
  116. #define _OSCSTAT_OSTS_POSN                                  0x5
  117. #define _OSCSTAT_OSTS_POSITION                              0x5
  118. #define _OSCSTAT_OSTS_SIZE                                  0x1
  119. #define _OSCSTAT_OSTS_LENGTH                                0x1
  120. #define _OSCSTAT_OSTS_MASK                                  0x20
  121. #define _OSCSTAT_PLLR_POSN                                  0x6
  122. #define _OSCSTAT_PLLR_POSITION                              0x6
  123. #define _OSCSTAT_PLLR_SIZE                                  0x1
  124. #define _OSCSTAT_PLLR_LENGTH                                0x1
  125. #define _OSCSTAT_PLLR_MASK                                  0x40
  126. #define _OSCSTAT_T1OSCR_POSN                                0x7
  127. #define _OSCSTAT_T1OSCR_POSITION                            0x7
  128. #define _OSCSTAT_T1OSCR_SIZE                                0x1
  129. #define _OSCSTAT_T1OSCR_LENGTH                              0x1
  130. #define _OSCSTAT_T1OSCR_MASK                                0x80
复制代码

出0入0汤圆

 楼主| 发表于 2013-6-15 09:20:59 | 显示全部楼层
millwood0 发表于 2013-6-14 21:30
I do.

me too.

出0入0汤圆

发表于 2013-6-15 09:41:07 | 显示全部楼层
MPLAB应该可以!

出0入0汤圆

发表于 2013-6-15 10:18:31 | 显示全部楼层
本帖最后由 xiongh 于 2013-6-15 10:20 编辑

MPLAB X  + PICC  挺好用。
#include "pic.h"
#include <htc.h>

__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_ON & FCMEN_OFF);
__CONFIG(WRT_OFF & PLLEN_ON & STVREN_ON & BORV_LO & LVP_OFF);

现在正在用PIC16F1824做项目,8路AD全用了,还有一路PWM。

出0入0汤圆

 楼主| 发表于 2013-6-15 12:38:31 | 显示全部楼层
xiongh 发表于 2013-6-15 10:18
MPLAB X  + PICC  挺好用。
#include "pic.h"
#include

好的,谢谢。我试试看。

出0入0汤圆

 楼主| 发表于 2013-6-15 12:42:36 | 显示全部楼层
xiongh 发表于 2013-6-15 10:18
MPLAB X  + PICC  挺好用。
#include "pic.h"
#include

#include <pic16f1824.h>       //调用头文件,
#include "pic.h"
#include <htc.h>

__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_ON & FCMEN_OFF);
__CONFIG(WRT_OFF & PLLEN_ON & STVREN_ON & BORV_LO & LVP_OFF);


编译不成功:
Build E:\PIC\PIC_1824E\PIC_1824E for device 16F1824
Using driver C:\Program Files (x86)\Microchip\xc8\v1.12\bin\xc8.exe

Make: The target "E:\PIC\PIC_1824E\main.p1" is up to date.
Executing: "C:\Program Files (x86)\Microchip\xc8\v1.12\bin\xc8.exe" -oPIC_1824E.cof -mPIC_1824E.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 main.p1 --chip=16F1824 "-IC:\Program Files (x86)\Microchip\xc8\v1.12\include" "-IC:\Program Files (x86)\HI-TECH Software\PICC\std\9.60\include" -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,-config,+clib,+plib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -N255 -D__DEBUG=1 --debugger=pickit3 -Bsmall --double=32 --float=32 --addrqual=ignore -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Microchip MPLAB XC8 C Compiler V1.12
Copyright (C) 2012 Microchip Technology Inc.
License type: Node Configuration

Warning [1273] ; . Omniscient Code Generation not available in Free mode
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "FCMEN_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "IESO_ON"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "CLKOUTEN_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "BOREN_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "CPD_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "CP_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "MCLRE_ON"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "PWRTE_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "WDTE_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 339. undefined symbol "FOSC_INTOSC"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 343. undefined symbol "LVP_OFF"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 343. undefined symbol "BORV_LO"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 343. undefined symbol "STVREN_ON"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 343. undefined symbol "PLLEN_ON"
Error   [800] C:\Users\guoliang\AppData\Local\Temp\ss2k.; 343. undefined symbol "WRT_OFF"
(908) exit status = 1

********** Build failed! **********

出0入0汤圆

 楼主| 发表于 2013-6-15 13:59:39 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-15 14:08 编辑
xiongh 发表于 2013-6-15 10:18
MPLAB X  + PICC  挺好用。
#include "pic.h"
#include
  1. #include<pic.h>
  2. __CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_OFF&BOREN_ON&CLKOUTEN_OFF&IESO_ON&FCMEN_ON);
  3. __CONFIG(PLLEN_OFF&LVP_OFF) ;//将FOSC<2:0>:振荡器选择位设置成 INTOSC,
  4. void init_fosc(void)
  5. {
  6. OSCCON = 0x70;//8MHZ IRCF<3:0>时钟频率选择位设置成8MHZ
  7. }
复制代码
谢谢大家!终于找到个能用的了。。。不过暂时还不能理解。

出0入0汤圆

 楼主| 发表于 2013-6-15 14:08:15 | 显示全部楼层
xiongh 发表于 2013-6-15 10:18
MPLAB X  + PICC  挺好用。
#include "pic.h"
#include

就RA3的灯没亮,为啥子呢

  1. #include<pic.h>
  2. __CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_OFF&BOREN_ON&CLKOUTEN_OFF&IESO_ON&FCMEN_ON);
  3. __CONFIG(PLLEN_OFF&LVP_OFF) ;//将FOSC<2:0>:振荡器选择位设置成 INTOSC,

  4. void init_fosc(void)
  5. {
  6. OSCCON = 0x70;//8MHZ IRCF<3:0>时钟频率选择位设置成8MHZ
  7. }


  8. void delay500ms(void)   //误差 0us
  9. {
  10.     unsigned char a,b,c;
  11.     for(c=20;c>0;c--)
  12.         for(b=152;b>0;b--)
  13.             for(a=7;a>0;a--);
  14. }
  15. //---------------------------------------
  16. //名称: 主函数                 
  17. //-----------------------------------------
  18. void main()
  19. {       
  20.         init_fosc();
  21.         TRISA=0B00000000;       //RA设置为输出
  22.         TRISC=0B00000000;           //RC设置为输出
  23.         PORTC=0x00;       //RA的LED全不亮
  24.         PORTA=0x00;       //RC的LED全不亮
  25.         while(1)
  26.         {
  27.                 PORTC=0x00;
  28.                 delay500ms();
  29.                 PORTC=0xff;
  30.                 delay500ms();
  31.                
  32.                 PORTA=0x00;
  33.                 delay500ms();
  34.                 PORTA=0xff;
  35.                 delay500ms();

  36.         }
  37. }
复制代码

出0入0汤圆

发表于 2013-6-15 15:28:00 | 显示全部楼层
本帖最后由 xiongh 于 2013-6-15 15:31 编辑

看手册:

12.2 PORTA 寄存器
PORTA 是一个6 位宽的双向端口。对应的数据方向寄存
器是TRISA(寄存器12-4)。将TRISA 某位置1(= 1)
时,会将PORTA 的相应引脚为输入(即,禁止输出
驱动器)。将TRISA 某位清零(= 0)时,会将PORTA
的相应引脚设为输出(即,使能输出驱动器并将输出锁
存器中的内容输出到选定的引脚)。RA3 是个例外,它仅
可作为输入引脚,其TRIS 位总是读为1。例12-1 显示
了如何初始化PORTA。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入42汤圆

发表于 2013-6-15 22:13:29 来自手机 | 显示全部楼层
楼上正解

出0入0汤圆

 楼主| 发表于 2013-6-20 17:31:27 | 显示全部楼层
xiongh 发表于 2013-6-15 15:28
看手册:

12.2 PORTA 寄存器

好。谢谢!我再摸索一下。

出0入0汤圆

 楼主| 发表于 2013-6-20 18:48:23 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-20 18:52 编辑
  1. #include<pic.h>

  2. __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_OFF);
  3. __CONFIG(WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_OFF);//将FOSC<2:0>:振荡器选择位设置成 INTOSC,


  4. void init_fosc(void)
  5. {
  6. OSCCON = 0x70;//8MHZ IRCF<3:0>时钟频率选择位设置成8MHZ
  7. }


  8. void delay500ms(void)   //误差 0us
  9. {
  10.     unsigned char a,b,c;
  11.     for(c=20;c>0;c--)
  12.         for(b=152;b>0;b--)
  13.             for(a=7;a>0;a--);
  14. }
  15. //---------------------------------------
  16. //名称: 主函数                 
  17. //-----------------------------------------
  18. void main()
  19. {       
  20.         init_fosc();
  21.        
  22.         TRISA=0B00000000;       //RA设置为输出
  23.         TRISC=0B00000000;           //RC设置为输出

  24.         PORTA=0B00000000;        //初始化RA
  25.         PORTC=0B00000000;        //初始化RC


  26.         while(1)
  27.         {
  28.                  RC2=1;
  29.                 delay500ms();
  30.                 RC1=1;
  31.                 delay500ms();       
  32.         }
  33. }
复制代码
又出状况了。按理接在RC1和RC2的两个LED,应该是常亮的,可是实际他是交替闪。RC1=1时,RC2会自动变为0,什么情况???

一个IO置1,会让同一组的其它自动置0?  试了下一如 RC2=1; RA1=1;,  则不会互相影响。

出0入0汤圆

发表于 2013-6-20 21:01:49 | 显示全部楼层
估计应该是两个原因,一个是ANSELC寄存器,一个是硬件的问题。

出0入0汤圆

 楼主| 发表于 2013-6-20 22:49:54 | 显示全部楼层
xiongh 发表于 2013-6-15 15:28
看手册:

12.2 PORTA 寄存器
  1.         while(1)
  2.         {
  3.                  RC0=1;
  4.                 delay500ms();
  5.                   RC1=1;
  6.                 delay500ms();
  7.                 RC2=1;
  8.                 delay500ms();
  9.                 RC3=1;
  10.                 delay500ms();
  11.                   RC4=1;
  12.                 delay500ms();
  13.                 RC5=1;
  14.                 delay500ms();       
  15.                
  16.                 RA0=1;
  17.                 delay500ms();
  18.                   RA1=1;
  19.                 delay500ms();
  20.                 RA2=1;
  21.                 delay500ms();
  22.                 RA3=1;
  23.                 delay500ms();
  24.                   RA4=1;
  25.                 delay500ms();
  26.                 RA5=1;
  27.                 delay500ms();
  28.         }
复制代码
只有RA5   RC4    RC5,是一直亮的,RA0~4,RC0~3,都变成流水灯了!

出0入0汤圆

发表于 2013-6-21 04:28:02 来自手机 | 显示全部楼层
"成流水灯了!"

If you don't try to read and understand the datasheet, you will never learn.

出0入0汤圆

 楼主| 发表于 2013-6-21 08:19:40 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-21 09:19 编辑
millwood0 发表于 2013-6-21 04:28
"成流水灯了!"

If you don't try to read and understand the datasheet, you will never learn.


我在看了,只是还没看懂,毕竟刚接触PIC,很多术语以前做STC51都没有的,一时没理解。  millwood0真是全能的,在很多版区都能看到你出现哦。Excuse me
,Where are you from
?我英文比较差,只能用中文回复你,希望你能看得懂,抱歉

出0入0汤圆

 楼主| 发表于 2013-6-21 09:04:20 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-21 09:14 编辑
millwood0 发表于 2013-6-21 04:28
"成流水灯了!"

If you don't try to read and understand the datasheet, you will never learn.


OK!  after  add   " ANSELA  = 0x00;   ANSELC  = 0x00;"   in.  原来是数字口,模拟口的问题。很好,顺便学下英文。thank you!

出0入0汤圆

 楼主| 发表于 2013-6-21 09:14:18 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-21 09:15 编辑
xiongh 发表于 2013-6-15 15:28
看手册:

12.2 PORTA 寄存器


RA3 是个例外,它仅
可作为输入引脚。现在除了RA3,其它做数字口,都能正常使用了。谢谢提醒!不然我又以为RA3不正常,又得折腾半天了。

出0入0汤圆

发表于 2013-6-21 09:47:41 | 显示全部楼层
RA3我没有使用,专门作为复位用。

出0入0汤圆

 楼主| 发表于 2013-6-21 14:44:53 | 显示全部楼层


总算把LCD点亮了!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-6-22 06:07:57 | 显示全部楼层
原来是数字口,模拟口的问题。


Generally speaking, mcus have alternate uses for any pin. Sometimes, the power-on state / mode is not (digital) GPIO - PICs as you have found out power up in the analog mode. Other PICs may also default some of their pins for comparators.

Many PICs provide a gpio initialization sequence in the GPIO section of the datasheet, or to identify all relevant registers / bits, etc.

I always execute a routine, called mcu_init(), as the first user-space routine to reset the pins to digital IO. On some mcus, that routine could be an empty routines - AVRs for example. But it is a good idea to always have that.

出0入0汤圆

 楼主| 发表于 2013-6-22 10:10:48 | 显示全部楼层
millwood0 发表于 2013-6-22 06:07
Generally speaking, mcus have alternate uses for any pin. Sometimes, the power-on state / mode is  ...

原来,手册上的引脚功能说明中,有标ANx的IO都是带有模拟输入功能的,必须将其设置为数字输出。

出0入4汤圆

发表于 2013-6-22 12:58:46 | 显示全部楼层
作输出用的时候 最好使用 LATx 寄存器 而不要用PORTx  。

出0入0汤圆

 楼主| 发表于 2013-6-24 08:49:58 | 显示全部楼层
xiongh 发表于 2013-6-15 15:28
看手册:

12.2 PORTA 寄存器


在学习中断,发现无论是定时器0还是定时器1还是其它,
中断程序都是这个:
void interrupt isr(void)


  }

不像51单片机那样带有中断号来对应中断源。

难道PIC的所有中断程序都写在void interrupt isr(void)里,然后用判断语句来识别中断源吗?

出0入0汤圆

发表于 2013-6-24 09:24:54 | 显示全部楼层
XC8免费版也一样用

出0入0汤圆

发表于 2013-6-24 10:05:03 | 显示全部楼层
1125526801 发表于 2013-6-24 08:49
在学习中断,发现无论是定时器0还是定时器1还是其它,
中断程序都是这个:
void interrupt isr(void)

进入中断后,判断中断标志,然后确定是什么中断,再进行相应处理。

出0入0汤圆

 楼主| 发表于 2013-6-24 11:12:02 | 显示全部楼层
气球 发表于 2013-6-24 09:24
XC8免费版也一样用

我是破解了用,代码优化好

出0入0汤圆

 楼主| 发表于 2013-6-24 11:12:43 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-24 12:09 编辑
xiongh 发表于 2013-6-24 10:05
进入中断后,判断中断标志,然后确定是什么中断,再进行相应处理。


嗯嗯。试了用if,可以。ADC和PWM输出也弄出来了。消化一下,再熟悉一下PID算法,应对准备做的项目就勉强够用了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-6-24 12:51:25 | 显示全部楼层
PIC单片机的稳定性非常的不错,就是价格有点贵了,不过用来做工业产品不在乎这点成本。

出0入0汤圆

 楼主| 发表于 2013-6-24 13:19:25 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-24 13:21 编辑
xiongh 发表于 2013-6-24 12:51
PIC单片机的稳定性非常的不错,就是价格有点贵了,不过用来做工业产品不在乎这点成本。 ...


是有点贵,我只是想积累些PIC的经验,你看我发这个帖子时之前机根本没用过PIC。。。。调试成功后再换别的低成本MCU吧,要是找不到合适的就不换了。要求要耐高温。

出0入0汤圆

发表于 2013-6-24 15:32:01 | 显示全部楼层
PIC有自带的延时函数,完全由编译器计算生成的,
首先定义一下时钟,然后就可以直接用了,
如果用很多的延时就写一个延时函数,
#define _XTAL_FREQ 4000000                // 定义时钟频率为4M
void delay_ms(uint16_t xms)
{
        for(;xms!=0;xms--)
        {
                __delay_us(986);               
        }
}

注意__delay_us和__delay_ms是两根下划线的,
其中_delay()是延时指令周期时间,一根下划线

出0入0汤圆

 楼主| 发表于 2013-6-24 18:15:18 | 显示全部楼层
chengzepeng 发表于 2013-6-24 15:32
PIC有自带的延时函数,完全由编译器计算生成的,
首先定义一下时钟,然后就可以直接用了,
如果用很多的延 ...

哦!原来这样啊,我还按51单片机的写,然后接上示波器调整。。。。

出0入0汤圆

发表于 2013-6-25 09:26:36 | 显示全部楼层
用PICC9.8的吧

出0入0汤圆

 楼主| 发表于 2013-6-25 17:55:19 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-25 20:20 编辑
xiongh 发表于 2013-6-15 10:18
MPLAB X  + PICC  挺好用。
#include "pic.h"
#include


    一般PIC的ADC输入,需要加RC滤波吗?我直接从电位器采样,只加了只103电容。我那小板实验做了两通道输入。

  1.         while(1)
  2.         {

  3.                 test=ADC_BAT_contiue(0);//ADC0转换
  4.                 Numshow_XY(2,0,test);        //显示转换结果
  5.                 test=ADC_BAT_contiue(1);//ADC1转换
  6.                 Numshow_XY(6,0,test);        //显示转换结果
  7.                 delay20ms();

  8.         }
复制代码




我在学习PPM输出,用CCP1做半桥输出,CCP2做呼吸灯。同时使用,按照手册需要设置寄存器CCPTMRSx来选择使用的定时器资源。
但是编译不过,提示CCPTMRS0  未定义。后来改成CCPTMRS搞定了:CCPTMRS=0b11110100;//给CCP1和CCP2选择定时器资源。







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-6-25 21:10:24 | 显示全部楼层
1125526801 发表于 2013-6-25 17:55
一般PIC的ADC输入,需要加RC滤波吗?我直接从电位器采样,只加了只103电容。我那小板实验做了两通道 ...

可以采用软件滤波

出0入0汤圆

 楼主| 发表于 2013-6-25 22:08:01 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-25 22:11 编辑
xiongh 发表于 2013-6-25 21:10
可以采用软件滤波


嗯。现在我那103电容也去了,是采样8次平均,做软件滤波,挺稳定的了。所用的两路AD都跟ICSPI有关,加了电容没法下载了。没加电容,也比STC的ADC稳定多了,以前玩STC的12C5A60S2,加了RC,还得采样30次以上做软件滤波效果才满意。

出0入0汤圆

 楼主| 发表于 2013-6-26 16:51:52 | 显示全部楼层
yoyobbs 发表于 2013-6-14 22:46
一直使用PICC的路过.


我试了下,用PICC和XC8编译同一个工程,XC8优化好像要好点。(都是和谐过的)

HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.80:


Microchip MPLAB XC8 C Compiler V1.12:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2013-6-26 18:44:20 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-26 19:05 编辑
xiongh 发表于 2013-6-21 09:47
RA3我没有使用,专门作为复位用。


哥,看看我的EEPROM读写错哪了?读应该对的,我用kit3写入EEPROM,能正确读出来。但是写了数据无效。

  1. void EEPROM_write(uchar add,uchar dat)//add为0x00~0xff
  2. {

  3.        
  4.         EEADRL = add;        //地址写入EEADRL 寄存器
  5.         EEDATL = dat;        //将数据写入EEDATL 寄存器

  6. //对写操作进行解锁
  7.         EECON2 = 0x55;  //先将 55h 写入 EECON2,
  8.         EECON2 = 0xaa;  //随后将 AAh 写入 EECON2
  9.         EECON1 = 0b00000110;//然后再将 EECON1中的WREN位置1 以使能写操作


  10.         EECON1 = 0b00000010;//最后将 WR位(bit 1)置 1
  11. }

  12. uchar EEPROM_read(uchar add)//add为0x00~0xff
  13. {
  14.         uchar dat_tmep = 0;
  15.        
  16.         EEADRL = add;//写要要读的地址
  17.         EECON1 = 0b00000001;        //清零EECON1寄存器的EEPGD 和CFGS 控制位,然后将控制位RD 置1。
  18.                                                 //                 bit7     bit6                   bit0
  19.         dat_tmep=EEDATL;//读出地址add上的数据
  20.         return dat_tmep;
  21. }

复制代码

出0入0汤圆

 楼主| 发表于 2013-6-26 19:55:30 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-26 20:04 编辑
1125526801 发表于 2013-6-26 18:44
哥,看看我的EEPROM读写错哪了?读应该对的,我用kit3写入EEPROM,能正确读出来。但是写了数据无效。{:sa ...



硬着头皮一边百度一边翻译手册上的汇编例程,终于成功写入EEPROM!看来汇编还是有必要去了解一下。
突然觉悟:学会了看STC的数据手册,不代表你能看懂PIC的手册。。。不过,当真的学会了用一种PIC的MCU,PIC的其它MCU应该不难了吧,但愿。


  1. void EEPROM_write(uchar add,uchar dat)//add为0x00~0xff
  2. {

  3.         EEADRL = add;        //地址写入EEADRL 寄存器
  4.         EEDATL = dat;        //将数据写入EEDATL 寄存器
  5.        
  6.         CFGS = 0;//EECON1
  7.         EEPGD = 0;
  8.         WREN = 1;
  9.         GIE = 0;
  10. //对写操作进行解锁
  11.         EECON2 = 0x55;  //先将 55h 写入 EECON2,
  12.         EECON2 = 0xaa;  //随后将 AAh 写入 EECON2
  13.         WR = 1;
  14.         GIE = 1;
  15.         WREN = 0;
  16.         while(WR);//Wait for write to complete
  17. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-6-26 20:20:03 | 显示全部楼层
The unlock sequence is outlined in the datasheet. Other peripherals (like RTCC) have similiar mechanism to prevent accidental write to them. You should implement that in assembly (as there are fairly strict timing requirements for those sequences that your compiler may not be able to meet), and repeat the sequence until a write is successful.

出0入0汤圆

发表于 2013-6-26 20:20:51 | 显示全部楼层
This is an example of why reading the datasheet is invaluable.

You cannot be a good embedded programmer if you cannot read and more importantly understand the datasheet.

出0入0汤圆

 楼主| 发表于 2013-6-26 22:19:53 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-27 09:00 编辑
millwood0 发表于 2013-6-26 20:20
This is an example of why reading the datasheet is invaluable.

You cannot be a good embedded progra ...


I  read it, but I  don't understand because thar text description for sequence is not very clear. and I cannot read assembly language,it is a big drawback for me.

In the PIC datasheet, all the examples are written in assembly language.

出0入0汤圆

 楼主| 发表于 2013-6-26 22:20:53 | 显示全部楼层
本帖最后由 1125526801 于 2013-6-27 09:02 编辑
millwood0 发表于 2013-6-26 20:20
The unlock sequence is outlined in the datasheet. Other peripherals (like RTCC) have similiar mechan ...


不好意思,昨晚这段英文还没读懂。。。。

今天早上特意下载了个词典翻译了一下,不知道对了没:

The unlock sequence is outlined in the datasheet.
解锁序列数据手册中已列出。
Reply: oh yes, I see it.


另外,开始我并不知道EECON1原来是需要位操作:
CFGS = 0;//EECON1
EEPGD = 0;//EECON1
WREN = 1;//EECON1
GIE = 0;//EECON1
而我之前是字节操作,如:EECON1 = 0b00000010;//最后将 WR位(bit 1)置 1
显然这和正确的时序是不一样的,所以写入不成功。后来边学边看,终于大概看明白了汇编时序例程,跟着他的时序写成C,才成功写入EEPROM。


Other peripherals (like RTCC) have similiar mechanism to prevent accidental write to them.
其他外围设备(如RTCC)也有类似的机制来防止它们被意外误写。

You should implement that in assembly (as there are fairly strict timing requirements for those sequences that your compiler may not be able to meet), and repeat the sequence until a write is successful.
你应该用汇编来实现(这些序列有相当严格的时间要求,你的编译器可能无法满足),并重复这个过程直到写操作成功。

出0入0汤圆

发表于 2013-6-27 08:42:38 | 显示全部楼层
1125526801 发表于 2013-6-26 16:51
我试了下,用PICC和XC8编译同一个工程,XC8优化好像要好点。(都是和谐过的)

HI-TECH C Compiler for P ...

PIC的编译XC上我没试过,但是在PIC9.8与8.05上编译,9.8确实优化得比较好.
另外,PIC在高版本的编译器上,对bank的处理与8.05略有不同.

出0入0汤圆

 楼主| 发表于 2013-6-27 09:14:03 | 显示全部楼层
PIC_1824E - 12864S&ADC&time0&PWM&EEPROM
程序上传一下,留着以后用

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2016-12-12 16:29:44 | 显示全部楼层
1125526801 发表于 2013-6-14 18:16
前辈们,PIC16F1824,帮忙给个流水灯程序吧。。。折腾了一天都没亮灯。。。。实然觉得学了几年STC白学了。 ...

非常感谢上传了中文版手册,我英语比较差,看的头晕。。。。多谢

出0入0汤圆

 楼主| 发表于 2017-4-7 20:16:59 | 显示全部楼层
zenghouyun 发表于 2016-12-12 16:29
非常感谢上传了中文版手册,我英语比较差,看的头晕。。。。多谢

转眼过去好几年了,喜欢就好

出0入0汤圆

发表于 2017-4-7 22:56:54 | 显示全部楼层
楼主你这个板子手里还有吗,淘宝了一圈没找到

出0入0汤圆

 楼主| 发表于 2017-4-20 19:12:42 | 显示全部楼层
活到老学到老 发表于 2017-4-7 22:56
楼主你这个板子手里还有吗,淘宝了一圈没找到

好久之前的了,早不知道哪里去了。你可以画个板发去打样出来就行了

出0入4汤圆

发表于 2017-6-4 20:57:45 | 显示全部楼层
楼主用的是哪个编译器?

出0入0汤圆

 楼主| 发表于 2017-6-12 10:22:23 | 显示全部楼层
MagicYang 发表于 2017-6-4 20:57
楼主用的是哪个编译器?

没用PIC了,改用台产芯片了,便宜。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 18:11

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表