单片机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6184|回复: 22
打印 上一主题 下一主题
收起左侧

PIC16877A单片机头文件寄存器的中文说明 PWM,AD,IIC等模块的使用例程设置详解

  [复制链接]
跳转到指定楼层
楼主
绝对好资料,自己学习的一个过程,基本的模块都有,如:比较,PWM,AD,IIC等。另外还有头文件寄存器的中文说明,PIC16F877A的原英文使用说明书和PIC16F877中文使用说明书,英文不好的可以对照着看。


PIC16F877引脚图:



PIC16F877中文资料(完整的pdf文档可从本帖附件中下载):





单片机pic16f877a头文件中文说明如下:
  1. /*
  2. * Header file for the Microchip
  3. * PIC 16F873A chip
  4. * PIC 16F874A chip
  5. * PIC 16F876A chip
  6. * PIC 16F877A chip
  7. * Midrange Microcontroller
  8. */

  9. #if defined(_16F874A) || defined(_16F877A)
  10. #define __PINS_40
  11. #endif

  12. static volatile unsigned char INDF @ 0x00;   //间接寻址寄存器
  13. static volatile unsigned char TMR0 @ 0x01;   //定时器0
  14. static volatile unsigned char PCL  @ 0x02;   //低8位程序计数器
  15. static volatile unsigned char STATUS @ 0x03;   //程序状态寄存器
  16. static          unsigned char FSR  @ 0x04;   //特殊功能寄存器
  17. static volatile unsigned char PORTA @ 0x05;   //端口A寄存器
  18. static volatile unsigned char PORTB @ 0x06;   //端口B寄存器
  19. static volatile unsigned char PORTC @ 0x07;   //端口C寄存器
  20. #ifdef __PINS_40
  21. static volatile unsigned char PORTD @ 0x08;   //端口D寄存器
  22. static volatile unsigned char PORTE @ 0x09;   //端口E寄存器
  23. #endif
  24. static          unsigned char PCLATH @ 0x0A;   //高5位程序计数器
  25. static volatile unsigned char INTCON @ 0x0B;   //中断控制寄存器
  26. static volatile unsigned char PIR1 @ 0x0C;   //中断标志寄存器PIR1
  27. static volatile unsigned char PIR2 @ 0x0D;   //中断标志寄存器PIR2
  28. static volatile unsigned char TMR1L @ 0x0E;   //低字节计数寄存器
  29. static volatile unsigned char TMR1H @ 0x0F;   //高字节计数寄存器
  30. static volatile unsigned char T1CON @ 0x10;   //TMR1控制寄存器
  31. static volatile unsigned char TMR2 @ 0x11;   //定时/计数器TMR2
  32. static volatile unsigned char T2CON @ 0x12;   //TMR2控制寄存器
  33. static volatile unsigned char SSPBUF @ 0x13;   //收/发数据缓冲器
  34. static volatile unsigned char SSPCON @ 0x14;   //同步串口控制寄存器,对MSSP模块的功能和指标进行设置和定义。
  35. static volatile unsigned char CCPR1L @ 0x15;   //捕获/比较/PWM寄存器低字节
  36. static volatile unsigned char CCPR1H @ 0x16;   //捕获/比较/PWM寄存器低字节
  37. static volatile unsigned char CCP1CON @ 0x17;   //CCP1CON寄存器
  38. static volatile unsigned char RCSTA @ 0x18;   //USART接收控制兼状态寄存器
  39. static volatile unsigned char TXREG @ 0x19;   //USART发生缓冲器
  40. static volatile unsigned char RCREG @ 0x1A;   //USART接收缓冲器
  41. static volatile unsigned char CCPR2L @ 0x1B;   //捕获/比较/PWM寄存器低字节
  42. static volatile unsigned char CCPR2H @ 0x1C;   //捕获/比较/PWM寄存器低字节
  43. static volatile unsigned char CCP2CON @ 0x1D;   //CCP2CON寄存器
  44. static volatile unsigned char ADRESH @ 0x1E;   //ADC转换结果寄存器高字节
  45. static volatile unsigned char ADCON0 @ 0x1F;   //A/D转换器开关位。

  46. /* bank 1 registers */
  47. static          unsigned char bank1 OPTION @ 0x81;  //选择寄存器,用于配置TMR0/WDT预分频系数、外部INT中断、TMR0和端口B的弱上拉。
  48. static volatile unsigned char bank1 TRISA @ 0x85;  //A口方向寄存器
  49. static volatile unsigned char bank1 TRISB @ 0x86;  //B口方向寄存器
  50. static volatile unsigned char bank1 TRISC @ 0x87;  //C口方向寄存器
  51. #ifdef __PINS_40
  52. static volatile unsigned char bank1 TRISD @ 0x88;  //D口方向寄存器
  53. static volatile unsigned char bank1 TRISE @ 0x89;  //E口方向寄存器
  54. #endif
  55. static volatile unsigned char bank1 PIE1 @ 0x8C;  //中断允许寄存器PIE1
  56. static volatile unsigned char bank1 PIE2 @ 0x8D;  //中断允许寄存器PIE2
  57. static volatile unsigned char bank1 PCON @ 0x8E;  //电源控制状态寄存器
  58. static volatile unsigned char bank1 SSPCON2 @ 0x91;  //MSSP控制寄存器2
  59. static volatile unsigned char bank1 PR2  @ 0x92;  //TMR2周期寄存器
  60. static volatile unsigned char bank1 SSPADD @ 0x93;  //同步串口地址寄存器
  61. static volatile unsigned char bank1 SSPSTAT @ 0x94;  //同步串口状态寄存器
  62. static volatile unsigned char bank1 TXSTA @ 0x98;  //USART发生控制兼状态寄存器
  63. static volatile unsigned char bank1 SPBRG @ 0x99;  //USART波特率发生器初值寄存器
  64. static volatile unsigned char bank1 CMCON @ 0x9C;  //比较控制寄存器
  65. static volatile unsigned char bank1 CVRCON @ 0x9D;  //比较电压参考控制寄存器
  66. static volatile unsigned char bank1 ADRESL @ 0x9E;  //ADC转换结果寄存器低字节
  67. static volatile unsigned char bank1 ADCON1 @ 0x9F;  //ADC控制寄存器ADCON1

  68. /* bank 2 registers */
  69. static volatile unsigned char bank2 EEDATA @ 0x10C; //EEPROM数据寄存器低字节
  70. static volatile unsigned char bank2 EEADR @ 0x10D; //EEPROM地址寄存器低字节
  71. // Alternate definition
  72. volatile unsigned char              EEADRL        @ 0x10D;
  73. static volatile unsigned char bank2 EEDATH @ 0x10E; //EEPROM数据寄存器高字节
  74. static volatile unsigned char bank2 EEADRH @ 0x10F; //EEPROM地址寄存器高字节

  75. /* bank 3 registers */
  76. static volatile unsigned char bank3 EECON1 @ 0x18C; //EEPROM控制寄存器1
  77. static volatile unsigned char bank3 EECON2 @ 0x18D; //EEPROM控制寄存器2

  78. //* STATUS bits状态寄存器 */
  79. static volatile bit IRP     @ (unsigned)&STATUS*8+7; //寄存器bank选择位(用于间接寻址)。0:bank0,1;1:bank2,3
  80. static volatile bit RP1     @ (unsigned)&STATUS*8+6; //寄存器bank选择位(用于直接寻址)。PR1:PR0:00:BANK0;01:BANK1;10:BANK2;11BANK3.
  81. static volatile bit RP0     @ (unsigned)&STATUS*8+5; //
  82. static volatile bit TO  @ (unsigned)&STATUS*8+4; //超时位。0:WDT超时发生;1:上电后,执行了CLRWDT或者SLEEP指令
  83. static volatile bit PD  @ (unsigned)&STATUS*8+3; //掉电标志位。0:执行完SLEEP指令;1:上电后或者执行CLRWDT指令
  84. static volatile bit ZERO    @ (unsigned)&STATUS*8+2; //零标志位。0:算术或逻辑操作结果不为0;1:反之。
  85. static volatile bit DC      @ (unsigned)&STATUS*8+1; //数字进位/退位标志位。0:结果的低4位没有发生进位;1:反之。
  86. static volatile bit CARRY   @ (unsigned)&STATUS*8+0; //进位/退位标志位。0:结果的高4位没有发生进位;1:反之。

  87. /*      PORTA bits      */
  88. static volatile bit RA5 @ (unsigned)&PORTA*8+5;   //RA5
  89. static volatile bit RA4 @ (unsigned)&PORTA*8+4;   //RA4
  90. static volatile bit RA3 @ (unsigned)&PORTA*8+3;   //RA3
  91. static volatile bit RA2 @ (unsigned)&PORTA*8+2;   //RA2
  92. static volatile bit RA1 @ (unsigned)&PORTA*8+1;   //RA1
  93. static volatile bit RA0 @ (unsigned)&PORTA*8+0;   //RA0

  94. /*      PORTB bits      */
  95. static volatile bit RB7 @ (unsigned)&PORTB*8+7;   //RB7
  96. static volatile bit RB6 @ (unsigned)&PORTB*8+6;   //RB6
  97. static volatile bit RB5 @ (unsigned)&PORTB*8+5;   //RB5
  98. static volatile bit RB4 @ (unsigned)&PORTB*8+4;   //RB4
  99. static volatile bit RB3 @ (unsigned)&PORTB*8+3;   //RB3
  100. static volatile bit RB2 @ (unsigned)&PORTB*8+2;   //RB2
  101. static volatile bit RB1 @ (unsigned)&PORTB*8+1;   //RB1
  102. static volatile bit RB0 @ (unsigned)&PORTB*8+0;   //RB0

  103. /*      PORTC bits      */
  104. static volatile bit RC7 @ (unsigned)&PORTC*8+7;   //RC7
  105. static volatile bit RC6 @ (unsigned)&PORTC*8+6;   //RC6
  106. static volatile bit RC5 @ (unsigned)&PORTC*8+5;   //RC5
  107. static volatile bit RC4 @ (unsigned)&PORTC*8+4;   //RC4
  108. static volatile bit RC3 @ (unsigned)&PORTC*8+3;   //RC3
  109. static volatile bit RC2 @ (unsigned)&PORTC*8+2;   //RC2
  110. static volatile bit RC1 @ (unsigned)&PORTC*8+1;   //RC1
  111. static volatile bit RC0 @ (unsigned)&PORTC*8+0;   //RC0

  112. /*      PORTD bits      */
  113. #ifdef __PINS_40         
  114. static volatile bit RD7 @ (unsigned)&PORTD*8+7;   //RD7
  115. static volatile bit RD6 @ (unsigned)&PORTD*8+6;   //RD6
  116. static volatile bit RD5 @ (unsigned)&PORTD*8+5;   //RD5
  117. static volatile bit RD4 @ (unsigned)&PORTD*8+4;   //RD4
  118. static volatile bit RD3 @ (unsigned)&PORTD*8+3;   //RD3
  119. static volatile bit RD2 @ (unsigned)&PORTD*8+2;   //RD2
  120. static volatile bit RD1 @ (unsigned)&PORTD*8+1;   //RD1
  121. static volatile bit RD0 @ (unsigned)&PORTD*8+0;   //RD0

  122. /*      PORTE bits      */
  123. static volatile bit RE2 @ (unsigned)&PORTE*8+2;   //RE2
  124. static volatile bit RE1 @ (unsigned)&PORTE*8+1;   //RE1
  125. static volatile bit RE0 @ (unsigned)&PORTE*8+0;   //RE0
  126. #endif

  127. //* INTCON bits 中断控制寄存器 */
  128. static volatile bit GIE  @ (unsigned)&INTCON*8+7; //总中断使能位。0:屏蔽所有的中断请求;1:允许非屏蔽的中断。
  129. static volatile bit PEIE @ (unsigned)&INTCON*8+6; //外部中断使能位。0:禁止;1:使能
  130. static volatile bit T0IE @ (unsigned)&INTCON*8+5; //TMR0溢出中断使能位。0:禁止;1:使能
  131. static volatile bit INTE @ (unsigned)&INTCON*8+4; //RB0/INT外部中断使能位。0:不使能;1:使能。
  132. static volatile bit RBIE @ (unsigned)&INTCON*8+3; //RB端口变化中断时能位。0:不使能;1:使能。
  133. static volatile bit T0IF @ (unsigned)&INTCON*8+2; //TMR0溢出中断标志位。0:无溢出;1:溢出。
  134. static volatile bit INTF @ (unsigned)&INTCON*8+1; //RB0/INT外部中断标志位。0:RB0外部中断未发生;1:RB0外部中断发生。
  135. static volatile bit RBIF @ (unsigned)&INTCON*8+0; //RB端口变化中断标志位。0:RB口无变化;1:RB口至少有一个引脚变化。
  136. // alternate definitions
  137. static volatile bit TMR0IE @ (unsigned)&INTCON*8+5; //
  138. static volatile bit TMR0IF @ (unsigned)&INTCON*8+2; //

  139. //* PIR1 bits中断标志寄存器PIR1 */
  140. #ifdef __PINS_40
  141. static volatile bit PSPIF @ (unsigned)&PIR1*8+7;  //并行从端口读写中断标志位。0:没有读写操作发生;1:反之
  142. #endif
  143. static volatile bit ADIF @ (unsigned)&PIR1*8+6;  //A/D转换器中断标志位。0:A/D转换没有完成;1:A/D转换完成。
  144. static volatile bit RCIF @ (unsigned)&PIR1*8+5;  //USART接收中断标志位。0:接收缓冲器空;1:反之。
  145. static volatile bit TXIF @ (unsigned)&PIR1*8+4;  //USART发送中断标志位。0:发生缓冲器满;1:反之。
  146. static volatile bit SSPIF @ (unsigned)&PIR1*8+3;  //同步串行端口(ssp)中断标志位。0:没有ssp中断条件发生;
  147. static volatile bit CCP1IF @ (unsigned)&PIR1*8+2;  //CCP1中断标志位。
  148. static volatile bit TMR2IF @ (unsigned)&PIR1*8+1;  //TMR2 TO PR2匹配中断标志位。0:没有匹配发生
  149. static volatile bit TMR1IF @ (unsigned)&PIR1*8+0;  //TMR1溢出中断标志位,0:无溢出

  150. /* PIR2 bits */
  151. static volatile bit CMIF @ (unsigned)&PIR2*8+6;  //比较器中断标志位;0:比较器输入没有改变
  152. static volatile bit EEIF @ (unsigned)&PIR2*8+4;  //EEPROM写操作中断标志位。0:写操作没有完成或没有开始
  153. static volatile bit BCLIF @ (unsigned)&PIR2*8+3;  //总线冲突中断标志位。0:没有总线冲突发生
  154. static volatile bit CCP2IF @ (unsigned)&PIR2*8+0;  //CCP2中断标志位

  155. //* T1CON bits TMR1控制寄存器 */
  156. static volatile bit T1CKPS1 @ (unsigned)&T1CON*8+5;  //TMR1输入时钟预分频选择位
  157. static volatile bit T1CKPS0 @ (unsigned)&T1CON*8+4;  //TMR1输入时钟预分频选择位
  158. static volatile bit T1OSCEN @ (unsigned)&T1CON*8+3;  //TMR1震荡器使能控制位。0:振荡器关闭
  159. static volatile bit T1SYNC  @ (unsigned)&T1CON*8+2;  //TMR1外部时钟输入同步控制位。
  160. static volatile bit TMR1CS  @ (unsigned)&T1CON*8+1;  //TMR1时钟源选择位。0:内部时钟的/4
  161. static volatile bit TMR1ON  @ (unsigned)&T1CON*8+0;  //TMR1使能位。0:禁止

  162. //* T2CON bits TMR2控制寄存器 */
  163. static volatile bit TOUTPS3 @ (unsigned)&T2CON*8+6;  //TMR2后分频选择位。
  164. static volatile bit TOUTPS2 @ (unsigned)&T2CON*8+5;  //TMR2后分频选择位
  165. static volatile bit TOUTPS1 @ (unsigned)&T2CON*8+4;  //TMR2后分频选择位
  166. static volatile bit TOUTPS0 @ (unsigned)&T2CON*8+3;  //TMR2后分频选择位。
  167. static volatile bit TMR2ON  @ (unsigned)&T2CON*8+2;  //TMR2使能位。
  168. static volatile bit T2CKPS1 @ (unsigned)&T2CON*8+1;  //TMR2预分频选择位。
  169. static volatile bit T2CKPS0 @ (unsigned)&T2CON*8+0;  //TMR2预分频选择位

  170. //* SSPCON bits SPI同步串口控制寄存器*/
  171. static volatile bit WCOL @ (unsigned)&SSPCON*8+7; //写操作冲突检测位,在SPI从动方式下,WCOL=0,未发生冲突,WCOL=1,发生冲突。
  172. static volatile bit SSPOV @ (unsigned)&SSPCON*8+6; //接收溢出标志位,SSPOV=0,未发生接收溢出;SSPOV=1,发生接受溢出。
  173. static volatile bit SSPEN @ (unsigned)&SSPCON*8+5; //同步串口MSSP允许位,SSPEN=0,关闭串口;SSPEN=1,允许串行端口功能。
  174. static volatile bit CKP  @ (unsigned)&SSPCON*8+4; //时钟极性选择位,CKP=0,空闲时时钟停留在低电平;CKP=1,空闲时时钟停留在高电平。
  175. static volatile bit SSPM3 @ (unsigned)&SSPCON*8+3; //同步串行口MSSP方式选择位,主动参数。0,1,2,3,4.
  176. static volatile bit SSPM2 @ (unsigned)&SSPCON*8+2;
  177. static volatile bit SSPM1 @ (unsigned)&SSPCON*8+1;
  178. static volatile bit SSPM0 @ (unsigned)&SSPCON*8+0;

  179. /* CCP1CON bits */
  180. static volatile bit CCP1X @ (unsigned)&CCP1CON*8+5; //PWM最小信号位
  181. static volatile bit CCP1Y @ (unsigned)&CCP1CON*8+4; //PWM最小信号位
  182. static volatile bit CCP1M3 @ (unsigned)&CCP1CON*8+3; //CCP1模式选择位
  183. static volatile bit CCP1M2 @ (unsigned)&CCP1CON*8+2; //CCP1模式选择位
  184. static volatile bit CCP1M1 @ (unsigned)&CCP1CON*8+1; //CCP1模式选择位
  185. static volatile bit CCP1M0 @ (unsigned)&CCP1CON*8+0; //CCP1模式选择位

  186. //* RCSTA bits USART接收控制兼状态寄存器  */
  187. static volatile bit SPEN @ (unsigned)&RCSTA*8+7;  //串行端口使能位。0:禁止;1:使能。
  188. static volatile bit RX9  @ (unsigned)&RCSTA*8+6;  //接收数据长度选择位。0:接收8位数据;1:接收9位
  189. static volatile bit SREN @ (unsigned)&RCSTA*8+5;  //单字节使能选择位。0:禁止;1:使能。异步模式未使用
  190. static volatile bit CREN @ (unsigned)&RCSTA*8+4;  //连续接收使能选择位。0:禁止连续接收使能
  191. static volatile bit ADDEN @ (unsigned)&RCSTA*8+3;  //地址匹配检测使能位。0:取消地址匹配检测
  192. static volatile bit FERR @ (unsigned)&RCSTA*8+2;  //帧格式错误标志位。0:未发生错误
  193. static volatile bit OERR @ (unsigned)&RCSTA*8+1;  //溢出标志位。0:未溢出
  194. static volatile bit RX9D @ (unsigned)&RCSTA*8+0;  //接收数据的第9位

  195. /* CCP2CON bits */
  196. static volatile bit CCP2X @ (unsigned)&CCP2CON*8+5; //PWM最小信号位
  197. static volatile bit CCP2Y @ (unsigned)&CCP2CON*8+4; //PWM最小信号位
  198. static volatile bit CCP2M3 @ (unsigned)&CCP2CON*8+3; //CCP2模式选择位
  199. static volatile bit CCP2M2 @ (unsigned)&CCP2CON*8+2; //CCP2模式选择位
  200. static volatile bit CCP2M1 @ (unsigned)&CCP2CON*8+1; //CCP2模式选择位
  201. static volatile bit CCP2M0 @ (unsigned)&CCP2CON*8+0; //CCP2模式选择位

  202. //*  ADCON0 bits A/D控制寄存器位 */
  203. static volatile bit ADCS1 @ (unsigned)&ADCON0*8+7; //选择A/D转换时钟。00:1/2;01:1/8;10:1/32;11:RC
  204. static volatile bit ADCS0  @ (unsigned)&ADCON0*8+6; //选择A/D转换时钟
  205. static volatile bit CHS2 @ (unsigned)&ADCON0*8+5; //AD模拟通道选择
  206. static volatile bit CHS1 @ (unsigned)&ADCON0*8+4; //AD模拟通道选择
  207. static volatile bit CHS0 @ (unsigned)&ADCON0*8+3; //AD模拟通道选择。000:选择信道0.
  208. static volatile bit ADGO @ (unsigned)&ADCON0*8+2; //A/D转换状态位,ADON=1时,0:不在进行ad转换;1:正在进行转换。
  209. // Alternate definition for compatibility with other devices
  210. volatile bit        GODONE        @ (unsigned)&ADCON0*8+2;
  211. static volatile bit ADON @ (unsigned)&ADCON0*8+0; //A/D转换器开关位,0:关闭;1:启动。

  212. //*  OPTION bits 选择寄存器  */
  213. static bank1 bit RBPU @ (unsigned)&OPTION*8+7; //端口B上拉设置允许位
  214. static bank1 bit INTEDG @ (unsigned)&OPTION*8+6; //外中断源选择位
  215. static bank1 bit T0CS @ (unsigned)&OPTION*8+5; //时钟选择位。T0CS=0,使用内部时钟;T0CS=1,使用外部时钟。
  216. static bank1 bit T0SE @ (unsigned)&OPTION*8+4; //计数器使用外部时钟,T0SE=0,上升沿触发;T0SE=1,下降沿触发。
  217. static bank1 bit PSA  @ (unsigned)&OPTION*8+3; //PSA=0,作为time0的预分频器;PSA=1,作为WDT的后分频器。
  218. static bank1 bit PS2  @ (unsigned)&OPTION*8+2; //PS2,PS1,PS0。预分频比例。000=1:2(Timer0)1:1(WDT)...
  219. static bank1 bit PS1  @ (unsigned)&OPTION*8+1; //
  220. static bank1 bit PS0  @ (unsigned)&OPTION*8+0; //

  221. //*      TRISA bits   PORTA数据方向寄存器   */
  222. static volatile bank1 bit TRISA5 @ (unsigned)&TRISA*8+5;  //
  223. static volatile bank1 bit TRISA4 @ (unsigned)&TRISA*8+4;  //
  224. static volatile bank1 bit TRISA3 @ (unsigned)&TRISA*8+3;  //
  225. static volatile bank1 bit TRISA2 @ (unsigned)&TRISA*8+2;  //
  226. static volatile bank1 bit TRISA1 @ (unsigned)&TRISA*8+1;  //
  227. static volatile bank1 bit TRISA0 @ (unsigned)&TRISA*8+0;  //

  228. //*      TRISB bits   PORTB数据方向寄存器   */
  229. static volatile bank1 bit TRISB7 @ (unsigned)&TRISB*8+7;  //
  230. static volatile bank1 bit TRISB6 @ (unsigned)&TRISB*8+6;  //
  231. static volatile bank1 bit TRISB5 @ (unsigned)&TRISB*8+5;  //
  232. static volatile bank1 bit TRISB4 @ (unsigned)&TRISB*8+4;  //
  233. static volatile bank1 bit TRISB3 @ (unsigned)&TRISB*8+3;  //
  234. static volatile bank1 bit TRISB2 @ (unsigned)&TRISB*8+2;  //
  235. static volatile bank1 bit TRISB1 @ (unsigned)&TRISB*8+1;  //
  236. static volatile bank1 bit TRISB0 @ (unsigned)&TRISB*8+0;  //

  237. //*      TRISC bits   PORTC数据方向寄存器   */
  238. static volatile bank1 bit TRISC7 @ (unsigned)&TRISC*8+7;  //
  239. static volatile bank1 bit TRISC6 @ (unsigned)&TRISC*8+6;  //
  240. static volatile bank1 bit TRISC5 @ (unsigned)&TRISC*8+5;  //
  241. static volatile bank1 bit TRISC4 @ (unsigned)&TRISC*8+4;  //
  242. static volatile bank1 bit TRISC3 @ (unsigned)&TRISC*8+3;  //
  243. static volatile bank1 bit TRISC2 @ (unsigned)&TRISC*8+2;  //
  244. static volatile bank1 bit TRISC1 @ (unsigned)&TRISC*8+1;  //
  245. static volatile bank1 bit TRISC0 @ (unsigned)&TRISC*8+0;  //

  246. #ifdef __PINS_40
  247. //*      TRISD bits   PORTD数据方向寄存器   */
  248. static volatile bank1 bit TRISD7 @ (unsigned)&TRISD*8+7;  //
  249. static volatile bank1 bit TRISD6 @ (unsigned)&TRISD*8+6;  //
  250. static volatile bank1 bit TRISD5 @ (unsigned)&TRISD*8+5;  //
  251. static volatile bank1 bit TRISD4 @ (unsigned)&TRISD*8+4;  //
  252. static volatile bank1 bit TRISD3 @ (unsigned)&TRISD*8+3;  //
  253. static volatile bank1 bit TRISD2 @ (unsigned)&TRISD*8+2;  //
  254. static volatile bank1 bit TRISD1 @ (unsigned)&TRISD*8+1;  //
  255. static volatile bank1 bit TRISD0 @ (unsigned)&TRISD*8+0;  //

  256. //*      TRISE bits  PORTE数据方向寄存器    */
  257. static volatile bank1 bit IBF  @ (unsigned)&TRISE*8+7;  //
  258. static volatile bank1 bit OBF  @ (unsigned)&TRISE*8+6;  //
  259. static volatile bank1 bit IBOV @ (unsigned)&TRISE*8+5;  //
  260. static volatile bank1 bit PSPMODE @ (unsigned)&TRISE*8+4;  //

  261. static volatile bank1 bit TRISE2  @ (unsigned)&TRISE*8+2;  //
  262. static volatile bank1 bit TRISE1  @ (unsigned)&TRISE*8+1;  //
  263. static volatile bank1 bit TRISE0  @ (unsigned)&TRISE*8+0;  //
  264. #endif

  265. //* PIE1 bits 外围中断独立使能位 */
  266. #ifdef __PINS_40
  267. static volatile bank1 bit PSPIE @ (unsigned)&PIE1*8+7;  //并行从端口读写中断使能位。0:禁止psp读写中断
  268. #endif
  269. static volatile bank1 bit ADIE @ (unsigned)&PIE1*8+6;  //A/D转换器中断使能位。0:A/D转换没有完成;1:A/D转换完成。
  270. static volatile bank1 bit RCIE @ (unsigned)&PIE1*8+5;  //USART接收中断使能位。0:接收缓冲器空;1:反之。
  271. static volatile bank1 bit TXIE @ (unsigned)&PIE1*8+4;  ////USART发送中断使能位。0:发生缓冲器满;1:反之。
  272. static volatile bank1 bit SSPIE @ (unsigned)&PIE1*8+3;  //同步串行端口中断使能位
  273. static volatile bank1 bit CCP1IE @ (unsigned)&PIE1*8+2;  //CCP1中断使能位
  274. static volatile bank1 bit TMR2IE @ (unsigned)&PIE1*8+1;  //TMR2 TO PR2匹配中断使能位。0:没有匹配发生
  275. static volatile bank1 bit TMR1IE @ (unsigned)&PIE1*8+0;  //TMR1溢出中断使能位,0:无溢出

  276. /* PIE2 bits */
  277. static volatile bank1 bit CMIE @ (unsigned)&PIE2*8+6;  //比较器中断使能位
  278. static volatile bank1 bit EEIE @ (unsigned)&PIE2*8+4;  //EEPROM写操作中断使能位
  279. static volatile bank1 bit BCLIE @ (unsigned)&PIE2*8+3;  //总线冲突中断使能位
  280. static volatile bank1 bit CCP2IE @ (unsigned)&PIE2*8+0;  //CCP2中断使能位

  281. //* PCON bits 电源控制寄存器 */
  282. static volatile bank1 bit POR  @ (unsigned)&PCON*8+1;  //上电复位状态位
  283. static volatile bank1 bit BOR  @ (unsigned)&PCON*8+0;  //掉电复位状态位

  284. //* SSPCON2 bits  MSSP控制寄存器2*/
  285. static volatile bank1 bit GCEN @ (unsigned)&SSPCON2*8+7; //总调用使能位
  286. static volatile bank1 bit ACKSTAT @ (unsigned)&SSPCON2*8+6; //应答状态位
  287. static volatile bank1 bit ACKDT @ (unsigned)&SSPCON2*8+5; //应答数据位
  288. static volatile bank1 bit ACKEN @ (unsigned)&SSPCON2*8+4; //应答顺序使能位
  289. static volatile bank1 bit RCEN @ (unsigned)&SSPCON2*8+3; //接收使能位
  290. static volatile bank1 bit PEN  @ (unsigned)&SSPCON2*8+2; //停止条件使能位
  291. static volatile bank1 bit RSEN @ (unsigned)&SSPCON2*8+1; //重复开始条件使能位
  292. static volatile bank1 bit SEN  @ (unsigned)&SSPCON2*8+0; //开始条件使能位

  293. //*      SSPSTAT bits SPI同步串口状态寄存器   */
  294. static volatile bank1 bit STAT_SMP @ (unsigned)&SSPSTAT*8+7;  //SPI采样控制位。SPI主控方式,STAT_SMP=0,在输出的数据中间采样输入数据,为1时,在末端采样;SPI从动方式,STAT_SMP必须置位。
  295. static volatile bank1 bit STAT_CKE @ (unsigned)&SSPSTAT*8+6;  //SPI时钟沿选择,CKP=0时,STAT_CKE=0,SCK下降沿发送数据,STAT_CKE=1,SCK上升沿发送数据。CKP=1时,反之。
  296. static volatile bank1 bit STAT_DA  @ (unsigned)&SSPSTAT*8+5;  //数据/地址位
  297. static volatile bank1 bit STAT_P  @ (unsigned)&SSPSTAT*8+4;  //停止位
  298. static volatile bank1 bit STAT_S  @ (unsigned)&SSPSTAT*8+3;  //开始位
  299. static volatile bank1 bit STAT_RW  @ (unsigned)&SSPSTAT*8+2;  //读写位信息
  300. static volatile bank1 bit STAT_UA  @ (unsigned)&SSPSTAT*8+1;  //更新地址位
  301. static volatile bank1 bit STAT_BF  @ (unsigned)&SSPSTAT*8+0;  //缓冲器满标志位。STAT_BF=0,缓冲器空;STAT_BF=1,缓冲器满。
  302. #ifdef __STAT_BACKWARD_COMPATIBILITY
  303. #define STAT_SMP        SMP
  304. #define STAT_CKE        CKE
  305. #define STAT_DA        DA
  306. #define STAT_P        STOP
  307. #define STAT_S        START
  308. #define STAT_RW        RW
  309. #define STAT_UA        UA
  310. #define STAT_BF        BF
  311. #endif

  312. //* TXSTA bits USART发送控制兼状态寄存器*/
  313. static volatile bank1 bit CSRC @ (unsigned)&TXSTA*8+7;  //同步时钟选择位。0:选外部时钟;1:选内部时钟。异步模式未用。
  314. static volatile bank1 bit TX9  @ (unsigned)&TXSTA*8+6;  //发生长度选择位。0:发送8位数据;1:发送9位
  315. static volatile bank1 bit TXEN @ (unsigned)&TXSTA*8+5;  //发生使能选择位。0:禁止发送;1:使能发生
  316. static volatile bank1 bit SYNC @ (unsigned)&TXSTA*8+4;  //同步/异步模式选择位。0:异步;1:同步
  317. static volatile bank1 bit BRGH @ (unsigned)&TXSTA*8+2;  //高速波特率选择位。0:低速;1:高速。
  318. static volatile bank1 bit TRMT @ (unsigned)&TXSTA*8+1;  //移位寄存器空标志位。0,发生移位寄存器满,1,为空。
  319. static volatile bank1 bit TX9D @ (unsigned)&TXSTA*8+0;  //发生第9位的选择位,0,不发生,1,发送。

  320. //* CMCON Bits 比较器控制寄存器 */
  321. static volatile bank1 bit C2OUT @ (unsigned)&CMCON*8+7;  //比较器2输出位
  322. static volatile bank1 bit C1OUT @ (unsigned)&CMCON*8+6;  //比较器1输出位
  323. static volatile bank1 bit C2INV @ (unsigned)&CMCON*8+5;  //比较器2输出反向位
  324. static volatile bank1 bit C1INV @ (unsigned)&CMCON*8+4;  //比较器1输出反向位
  325. static volatile bank1 bit CIS  @ (unsigned)&CMCON*8+3;  //比较器输入开关位
  326. static volatile bank1 bit CM2  @ (unsigned)&CMCON*8+2;  //比较器模式位
  327. static volatile bank1 bit CM1  @ (unsigned)&CMCON*8+1;  //比较器模式位
  328. static volatile bank1 bit CM0  @ (unsigned)&CMCON*8+0;  //比较器模式位

  329. //* CVRCON Bits 比较电压参考寄存器 */
  330. static volatile bank1 bit CVREN @ (unsigned)&CVRCON*8+7; //比较器电压参考使能位
  331. static volatile bank1 bit CVROE @ (unsigned)&CVRCON*8+6; //比较器Vref输出使能位
  332. static volatile bank1 bit CVRR @ (unsigned)&CVRCON*8+5; //比较器Vref范围选择位
  333. static volatile bank1 bit CVR3 @ (unsigned)&CVRCON*8+3; //比较器Vref值选择位
  334. static volatile bank1 bit CVR2 @ (unsigned)&CVRCON*8+2; //比较器Vref值选择位
  335. static volatile bank1 bit CVR1 @ (unsigned)&CVRCON*8+1; //比较器Vref值选择位
  336. static volatile bank1 bit CVR0 @ (unsigned)&CVRCON*8+0; //比较器Vref值选择位

  337. //* ADCON1 bits ADC控制寄存器ADCON1*/
  338. static volatile bank1 bit ADFM @ (unsigned)&ADCON1*8+7; //AD转换结果格式选择位
  339. static volatile bank1 bit ADCS2 @ (unsigned)&ADCON1*8+6; //AD转换时钟选择位
  340. static volatile bank1 bit PCFG3 @ (unsigned)&ADCON1*8+3; //PCFG3-PCFG0AD转换引脚功能选择位。详细意义见手册PAGE-130.
  341. static volatile bank1 bit PCFG2 @ (unsigned)&ADCON1*8+2;
  342. static volatile bank1 bit PCFG1 @ (unsigned)&ADCON1*8+1;
  343. static volatile bank1 bit PCFG0 @ (unsigned)&ADCON1*8+0;

  344. //* EECON1 bits EEPROM控制寄存器*/
  345. static volatile bank3 bit EEPGD @ (unsigned)&EECON1*8+7; //程序/数据EEPROM选择位。0:选择访问数据存储器
  346. static volatile bank3 bit WRERR @ (unsigned)&EECON1*8+3; //EEPROM错误标志位。0:写操作完成
  347. static volatile bank3 bit WREN @ (unsigned)&EECON1*8+2; //EEPROM写使能位。1:允许
  348. static volatile bank3 bit WR  @ (unsigned)&EECON1*8+1; //写控制位
  349. ……………………

  350. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


29个常用模块的例程列表:
20170413 BEEP\
20170413 KEYS 4x4\
20170413 KEYS 8x1\
20170413 LCD PATA 1602\
20170413 LED 16x16\
20170413 LED1\
20170413 LED4\
20170415 74HC595x2\
20170416 SS 74HC595x2\
20170417 DS18B20+LCD1602\
20170418 TIMER1_T 0\
20170418 TMR0_T 0\
20170418 TMR0_T 1\
20170419 ADCON\
20170419 MSSP_SPI 74HC595x2\
20170419 TIMER2_T 0\
20170420 MSSP_I2C AT24C02\
20170420 MSSP_I2C PCF8563\
20170422 EEPROM_R_W\
20170422 EUSART_ASYN\
20170423 ECCP_CAPTURE\
20170423 ECCP_COMPARE\
20170424 ECCP_PWM\
20170426 EUSART_SYNC\
20170426 LCD12864_PATA\
20170426 LCD12864_SATA\
20170427 COMPARATOR MODULE\
20170428 CVRCON\
20170428 MSSP_SPI SD\

所有资料51hei提供打包下载:
PIC_C.rar (7.43 MB, 下载次数: 132)

评分

参与人数 1黑币 +5 收起 理由
LQL-LQL + 5 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 转播转播 分享分享 分享淘帖 顶 踩
回复

使用道具 举报

沙发
admin 发表于 2017-5-19 04:18 | 只看该作者
好资料,51黑有你更精彩!!!
回复

使用道具 举报

板凳
HI-xiaomei 发表于 2017-5-25 01:08 | 只看该作者
没钱,真的很需要

评分

参与人数 1黑币 +20 收起 理由
admin + 20 赞一个!

查看全部评分

回复

使用道具 举报

地板
pinkama 发表于 2017-11-10 13:20 | 只看该作者
感谢分享,谢谢!
回复

使用道具 举报

5#
JLennon 发表于 2017-11-22 17:55 | 只看该作者
很不错的资料,谢谢了。
回复

使用道具 举报

6#
初学者1234 发表于 2017-12-19 18:23 | 只看该作者
谢谢分享!!!!!!!!!11
回复

使用道具 举报

7#
YZ2972405 发表于 2017-12-28 20:03 | 只看该作者
刚学PIC,好想下载学习一下。
回复

使用道具 举报

8#
wwwmagic 发表于 2018-2-16 16:03 | 只看该作者

感谢分享,谢谢!
回复

使用道具 举报

9#
caffe 发表于 2018-3-26 20:33 | 只看该作者
没钱,真是尴尬
回复

使用道具 举报

10#
caffe 发表于 2018-3-26 20:36 | 只看该作者
好想要这个学习资料,请问怎么得到?
回复

使用道具 举报

11#
slim443 发表于 2018-4-21 20:46 | 只看该作者
牛贴解释的很详细
回复

使用道具 举报

12#
max0527@126.com 发表于 2018-5-25 15:28 | 只看该作者
好资料,下来学习参考一下
回复

使用道具 举报

13#
slim443 发表于 2018-6-1 02:56 | 只看该作者
51黑论坛,资料精辟
回复

使用道具 举报

14#
qqinhw 发表于 2018-6-24 08:06 | 只看该作者
谢谢分享
回复

使用道具 举报

15#
务真求实 发表于 2018-9-18 14:59 | 只看该作者
感谢无私分享
回复

使用道具 举报

16#
liouxianshu 发表于 2019-4-11 22:33 | 只看该作者
  真的   很不错
回复

使用道具 举报

17#
a441358272 发表于 2019-4-17 19:41 | 只看该作者
感谢楼主分享,先收藏了
回复

使用道具 举报

18#
a441358272 发表于 2019-4-17 19:41 | 只看该作者
感谢楼主分享,先收藏了
回复

使用道具 举报

19#
haihua 发表于 2019-4-24 21:49 | 只看该作者
感谢楼主分享
回复

使用道具 举报

20#
少年偏爱Ta 发表于 2019-6-24 09:40 | 只看该作者
好资料,来学习学习....
回复

使用道具 举报

21#
太阳冰 发表于 2019-6-29 13:50 来自手机 | 只看该作者
谢谢分享
回复

使用道具 举报

22#
电子小白111 发表于 2019-7-15 13:54 | 只看该作者
绝对的好资料,必须赞
回复

使用道具 举报

23#
F1640183 发表于 2019-7-21 07:57 来自手机 | 只看该作者
谢谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|单片机论坛 |51黑电子论坛单片机 联系QQ:125739409;技术交流QQ群582644647

Powered by 单片机教程网

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