在编写CODE时摸索和失败.工作代码,不适用于我



我已经安装了MPLAB X IDE、XC8和MPLAB IPE来编写代码。此外,我还买了2块开发板,用于用PIC16F88测试代码。一个小芯片,让我的脚湿。当我浏览许多网站时,我看到他们提供了代码进行测试。通常是按下按钮,使LED亮起的例子。

#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000                  // Fosc  frequency for _delay()  library
/*
* 
*/
#include <xc.h>     /* Hardware device support files. */
#include "16F88_xc8_header.h"

/*
* 
*/
void main()
{
OSCCON = 0b01100000;              // Internal frequency 4MHz
TRISA.F0 = 1;                    //Configure 1st bit of PORTA as input
TRISA.F1 = 1;                    //Configure 2nd bit of PORTA as input
TRISA.F2 = 1;
TRISA.F3 = 1;
TRISA.F0 = 0;                    //Configure 1st bit of PORTB as output
TRISB.F1 = 0;                    //Configure 2nd  bit of PORTB as output
TRISB.F2 = 0;
TRISB.F3 = 0;
PORTB = "0x00";                   //All LEDs OFF
do
{
if(PORTA.F0==0)            //If 1st switch is pressed
{
__delay_ms(100);    //Switch Debounce
if(PORTA.F0==0)//If the switch is still pressed
{
PORTB.F0 = 1;           //1st LED ON
__delay_ms(1000);              //1 Second Delay
PORTB.F0 = 0;           //LED OFF
}
}
if(PORTA.F1 == 0)            //If the 2nd switch is pressed
{
PORTB.F1 = 1;           //2nd LED ON
__delay_ms(1000);              //1 Second Delay
PORTB.F1 = 0;           //LED OFF
}
if(PORTA.F2 == 0)            //If the 3rd switch is pressed
{
PORTB.F2 = 1;           //3rd LED ON
__delay_ms(1000);              //1 Second Delay
PORTB.F2 = 0;           //LED OFF
}
if(PORTA.F3 == 0)            //If 4th switch is pressed
{
PORTB.F3 = 1;           //4thLED ON
__delay_ms(1000);              //1 Second Delay
PORTB.F3 = 0;           //LED OFF
}
}
while(1);
}

这是代码来自的网站。。。https://microcontrollerslab.com/use-input-output-ports-pic18f452/

我调整了一些事情,比如更改PORT字母和尝试构建时出现的错误。但是有些错误我不理解,所以我可以改正。以下是生成错误。。。

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'F:/PIC Stuff/Basic Scanner PIC16F88/B_SCAN_TEST2.X'
make  -f nbproject/Makefile-default.mk dist/default/production/B_SCAN_TEST2.X.production.hex
make[2]: Entering directory 'F:/PIC Stuff/Basic Scanner PIC16F88/B_SCAN_TEST2.X'
"C:Program FilesMicrochipxc8v2.32binxc8-cc.exe"  -mcpu=16F88 -c   -mdfp="C:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC16Fxxx_DFP/1.2.33/xc8"  -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default  -msummary=-psect,-class,+mem,-hex,-file  -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall   -std=c99 -gdwarf-3 -mstack=compiled:auto:auto     -o build/default/production/16F88_TEST2.p1 16F88_TEST2.c 
::: advisory: (2049) C99 compliant libraries are currently not available for baseline or mid-range devices, or for enhanced mid-range devices using a reentrant stack; using C90 libraries
16F88_TEST2.c:28:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISA.F0 = 1;                    //Configure 1st bit of PORTA as input
~~~~~^~~
16F88_TEST2.c:30:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISA.F1 = 1;                    //Configure 2nd bit of PORTA as input
~~~~~^~~
16F88_TEST2.c:32:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISA.F2 = 1;
~~~~~^~~
16F88_TEST2.c:34:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISA.F3 = 1;
~~~~~^~~
16F88_TEST2.c:36:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISA.F0 = 0;                    //Configure 1st bit of PORTB as output
~~~~~^~~
16F88_TEST2.c:38:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISB.F1 = 0;                    //Configure 2nd  bit of PORTB as output
~~~~~^~~
16F88_TEST2.c:40:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISB.F2 = 0;
~~~~~^~~
16F88_TEST2.c:42:8: error: member reference base type 'volatile unsigned char' is not a structure or union
TRISB.F3 = 0;
~~~~~^~~
16F88_TEST2.c:44:9: warning: incompatible pointer to integer conversion assigning to 'volatile unsigned char' from 'char [5]' [-Wint-conversion]
PORTB = "0x00";                   //All LEDs OFF
^ ~~~~~~
16F88_TEST2.c:50:9: error: member reference base type 'volatile unsigned char' is not a structure or union
if(PORTA.F0==0)            //If 1st switch is pressed
~~~~~^~~
16F88_TEST2.c:53:16: error: member reference base type 'volatile unsigned char' is not a structure or union
if(PORTA.F0==0)//If the switch is still pressed
~~~~~^~~
16F88_TEST2.c:55:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F0 = 1;           //1st LED ON
~~~~~^~~
16F88_TEST2.c:57:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F0 = 0;           //LED OFF
~~~~~^~~
16F88_TEST2.c:63:9: error: member reference base type 'volatile unsigned char' is not a structure or union
if(PORTA.F1 == 0)            //If the 2nd switch is pressed
~~~~~^~~
16F88_TEST2.c:67:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F1 = 1;           //2nd LED ON
~~~~~^~~
16F88_TEST2.c:71:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F1 = 0;           //LED OFF
~~~~~^~~
16F88_TEST2.c:78:9: error: member reference base type 'volatile unsigned char' is not a structure or union
if(PORTA.F2 == 0)            //If the 3rd switch is pressed
~~~~~^~~
16F88_TEST2.c:82:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F2 = 1;           //3rd LED ON
~~~~~^~~
16F88_TEST2.c:86:15: error: member reference base type 'volatile unsigned char' is not a structure or union
PORTB.F2 = 0;           //LED OFF
~~~~~^~~
16F88_TEST2.c:90:9: error: member reference base type 'volatile unsigned char' is not a structure or union
if(PORTA.F3 == 0)            //If 4th switch is pressed
~~~~~^~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/16F88_TEST2.p1' failed
make[2]: Leaving directory 'F:/PIC Stuff/Basic Scanner PIC16F88/B_SCAN_TEST2.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'F:/PIC Stuff/Basic Scanner PIC16F88/B_SCAN_TEST2.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/16F88_TEST2.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 781ms)

所有位声明都是错误的。查看控制器收割台。例如,这个

TRISA.F0 = 1;

应该是

TRISAbits.TRISA0 = 1;  //Bit 0 of PORTA is an input

正如@Tagli所提到的,还有更多的错误,比如:

PORTB = "0x00"; 

应该是:

PORTB = 0x00;

相关内容

  • 没有找到相关文章

最新更新