找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1984|回复: 1
收起左侧

PIC单片机编程学习 编译出现错误,请求给予帮助

[复制链接]
ID:44037 发表于 2018-11-7 22:30 | 显示全部楼层 |阅读模式
PIC 编程学习  编译 出现错误  请求给予帮助
编译软件  MPLAB X IDE v5.05  XC8 2.0  安装在C:  新建工程在桌面  没有中文出现
我在网上 找到例子
游客,本帖隐藏的内容需要积分高于 1 才可浏览,您当前积分为 0

  1. /*
  2. * NEC Protocol IR remote control decoder with PIC16F887 MCU.
  3. * C Code for MPLAB XC8 compiler.
  4. * Internal oscillator used @ 8MHz.
  5. * This is a free software with NO WARRANTY.
  6. */
  7. // set configuration words
  8. #pragma config CONFIG1 = 0x2CD4
  9. #pragma config CONFIG2 = 0x0700

  10. //LCD module connections
  11. #define LCD_RS       RD0
  12. #define LCD_EN       RD1
  13. #define LCD_D4       RD2
  14. #define LCD_D5       RD3
  15. #define LCD_D6       RD4
  16. #define LCD_D7       RD5
  17. #define LCD_RS_DIR   TRISD0
  18. #define LCD_EN_DIR   TRISD1
  19. #define LCD_D4_DIR   TRISD2
  20. #define LCD_D5_DIR   TRISD3
  21. #define LCD_D6_DIR   TRISD4
  22. #define LCD_D7_DIR   TRISD5
  23. //End LCD module connections
  24. #include <xc.h>
  25. #define _XTAL_FREQ 8000000
  26. #include <stdio.h>         // for sprintf
  27. #include <stdint.h>        // include stdint header
  28. #include "LCD_Lib.c"       // include LCD driver source file

  29. __bit nec_ok;
  30. char text[5];
  31. uint8_t nec_state, bit_n;
  32. uint16_t timer_value;
  33. uint32_t nec_code;
  34. // interrupt ISRs
  35. void __interrupt() EXT(void)
  36. {
  37. /*************** start external interrupt ISR ***************/
  38.   if (RBIF && (RB0 || !RB0))   // PORTB change ISR (& clear mismatch condition)
  39.   {
  40.     RBIF = 0;   // clear PORTB interrupt flag bit
  41.     if(nec_state != 0)
  42.     {
  43.       timer_value = (TMR1H << 8) | TMR1L;  // store Timer1 value
  44.       TMR1H = TMR1L = 0;     // reset Timer1
  45.     }
  46.     switch(nec_state)
  47.     {
  48.      case 0 :              // start receiving IR data (we're at the beginning of 9ms pulse)
  49.        TMR1H = TMR1L = 0;  // reset Timer1
  50.        TMR1ON = 1;         // enable Timer1
  51.        nec_state = 1;      // next state: end of 9ms pulse (start of 4.5ms space)
  52.        bit_n = 0;
  53.        break;
  54.      case 1 :                                       // End of 9ms pulse
  55.        if((timer_value > 9500) || (timer_value < 8500))
  56.        { // invalid interval ==> stop decoding and reset
  57.          nec_state = 0;  // reset decoding process
  58.          TMR1ON = 0;     // disable Timer1
  59.        }
  60.        else
  61.          nec_state = 2;  // next state: end of 4.5ms space (start of 562µs pulse)
  62.        break;
  63.      case 2 :                                       // End of 4.5ms space
  64.        if((timer_value > 5000) || (timer_value < 4000))
  65.        { // invalid interval ==> stop decoding and reset
  66.          nec_state = 0;  // reset decoding process
  67.          TMR1ON = 0;     // disable Timer1
  68.        }
  69.        else
  70.          nec_state = 3; // next state: end of 562µs pulse (start of 562µs or 1687µs space)
  71.        break;
  72.      case 3 :    // End of 562µs pulse
  73.        if((timer_value > 700) || (timer_value < 400))
  74.        { // invalid interval ==> stop decoding and reset
  75.          TMR1ON = 0;     // disable Timer1
  76.          nec_state = 0;  // reset decoding process
  77.        }
  78.        else
  79.          nec_state = 4;  // next state: end of 562µs or 1687µs space
  80.        break;
  81.        case 4 :
  82.        if((timer_value > 1800) || (timer_value < 400))
  83.        { // invalid interval ==> stop decoding and reset
  84.          TMR1ON = 0;     // disable Timer1
  85.          nec_state = 0;  // reset decoding process
  86.        }
  87.        else
  88.        {
  89.          if( timer_value > 1000)  // if space width > 1ms (short space)
  90.            nec_code |=   (uint32_t)1 << (31 - bit_n);   // write 1 to bit (31 - bit_n)
  91.          else    // if space width < 1ms (long space)
  92.            nec_code &= ~((uint32_t)1 << (31 - bit_n));  // write 0 to bit (31 - bit_n)
  93.          bit_n++;
  94.          if(bit_n > 31)
  95.          {
  96.            nec_ok = 1;   // decoding process OK
  97.            RBIE = 0;     // disable PORTB change interrupt
  98.          }
  99.          else
  100.            nec_state = 3;  // next state: end of 562µs pulse (start of 562µs or 1687µs space)
  101.          
  102.          break;
  103.        }  // end " else "
  104.       
  105.     }  // end " switch(nec_state) "
  106.   }  // end " if (RBIF && (RB0 || !RB0)) "
  107. /*************** end external interrupt ISR ***************/
  108. /*************** start Timer1 ISR ***************/
  109.   if (TMR1IF)         // Timer1 ISR
  110.   {
  111.     TMR1IF    = 0;   // clear Timer1 overflow flag bit
  112.     nec_state = 0;   // reset decoding process
  113.     TMR1ON    = 0;   // disable Timer1
  114.   }
  115. /*************** end Timer1 ISR ***************/
  116. }

  117. /*************************** main function *********************/
  118. void main(void)
  119. {
  120.   OSCCON = 0x70;   // set internal oscillator to 8MHz
  121.   ANSELH = 0;      // configure all PORTB pins as digital
  122.   TMR1IF = 0;     // clear Timer1 overflow interrupt flag bit
  123.   RBIF   = 0;     // clear PORTB change interrupt flag bit
  124.   TMR1IE = 1;     // enable Timer1 overflow interrupt
  125.   T1CON  = 0x10;  // set Timer1 clock source to internal with 1:2 prescaler (Timer1 clock = 1MHz)
  126.   INTCON = 0xC8;  // enable global, peripheral and PORTB change interrupts
  127.   IOCB0  = 1;     // enable RB0 pin change interrupt
  128.   nec_ok = 0;
  129.   nec_state = 0;
  130.   __delay_ms(1000);   // wait 1 second
  131.   LCD_Begin();       // initialize LCD module
  132.   LCD_Goto(1, 1);    // move cursor to column 1, row 1
  133.   LCD_Print("Address:0x0000");
  134.   LCD_Goto(1, 2);    // move cursor to column 1, row 2
  135.   LCD_Print("Com:0x00 In:0x00");
  136.   while(1)
  137.   {
  138.     while (!nec_ok);   // wait until NEC code receiver
  139.     nec_ok    = 0;   // reset decoding process
  140.     nec_state = 0;
  141.     TMR1ON    = 0;   // disable Timer1
  142.     uint16_t address = nec_code >> 16;
  143.     uint8_t  command = nec_code >> 8;
  144.     uint8_t  inv_command = nec_code;
  145.     sprintf(text,"%04X",address);
  146.     LCD_Goto(11, 1);   // move cursor to column 11 line 1
  147.     LCD_Print(text);   // print address
  148.     sprintf(text,"%02X",command);
  149.     LCD_Goto(7, 2);    // move cursor to column 7 line 2
  150.     LCD_Print(text);   // print command
  151.     sprintf(text,"%02X",inv_command);
  152.     LCD_Goto(15, 2);    // move cursor to column 15 line 2
  153.     LCD_Print(text);    // print inverted command
  154.     RBIE = 1;    // enable PORTB change interrupt
  155.   }
  156. }
  157. /*************************** end main function ********************************/
复制代码


下载
游客,本帖隐藏的内容需要积分高于 1 才可浏览,您当前积分为 0
   新建工程加入 LCD_Lib.c
按照网上  PIC单片机入门教程(四)—— 第一个工程   
https://blog.csdn.net/JYUNefe/article/details/80657918
步骤操作 并进行芯片配置操作
结果 编译 出现错误 大概意思是 LCD_RS 等 引脚没有标识  #include <xc.h>  显示未解析的内部包含文件

思考可能是 什么地方没有设置
请求给予帮助
回复

使用道具 举报

ID:401564 发表于 2018-11-8 17:28 | 显示全部楼层
在头文件中加一个包含PIC16F877A的语句,或者是直接改#define LCD_RS       RD0   这个RD0直接用这个IO的地址,应该是这样的,没有用过C,不知道,你试一下

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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