• AVR Freaks

Hot!16F527 compile issue TRIS register

Author
TheDickChuck
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2011/05/01 17:07:32
  • Location: 0
  • Status: offline
2020/07/30 20:53:53 (permalink)
0

16F527 compile issue TRIS register

I can't get my code to compile when I refer to TRISB... get screens of errors and warnings.  Without that reference, all is fine.  Have tried all combos of ex/including xc.h and 16f527.h.  Using MPLAB X v5.20 and xc8 v2.05.  Project set to 16f527/PicKit4.  Tried C90 and C99... no joy.
 
// CONFIG
#pragma config FOSC = INTRC_IO  // Oscillator Selection (INTRC with I/O function on OSC2/CLKOUT and 10 us startup time)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT Disabled)
#pragma config CP = OFF         // Code Protection - User Program Memory (Code protection off)
#pragma config MCLRE = OFF      // Master Clear Enable (MCLR pin functions as I/O, MCLR internally tied to Vdd)
#pragma config IOSCFS = 4MHz    // Internal Oscillator Frequency Select (4 MHz INTOSC Speed)
#pragma config CPSW = OFF       // Code Protection - Self Writable Memory (Code protection off)
#pragma config BOREN = ON       // Brown-out Reset Enable (BOR Enabled)
#pragma config DRTEN = ON       // Device Reset Timer Enable (DRT Enabled (18 ms))

#include <xc.h>
#include <pic16f527.h>

#define     _XTAL_FREQ  4000000

#define     LIGHT_RED   RB6
#define     LIGHT_GRN   RB5
#define     LIGHT_YEL   RB4

TRISB = 0b00001111; //this line breaks stuff

void main(void)
{
    LIGHT_RED = 1;
    LIGHT_GRN = 1;
    LIGHT_YEL = 1;
    while (1)
    {
    };
}
 

 
With C90 output seems a little less angry:
 
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Rick/Documents/PIC Projects/Red Light.X'
make  -f nbproject/Makefile-default.mk dist/default/production/Red_Light.X.production.hex
make[2]: Entering directory 'C:/Users/Rick/Documents/PIC Projects/Red Light.X'
"C:\Program Files (x86)\Microchip\xc8\v2.05\bin\xc8-cc.exe"  -mcpu=16F527 -c  -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=c90 -gdwarf-3 -mstack=compiled:auto     -o build/default/production/main.p1 main.c
main.c:27:7: warning: (374) missing basic type; int assumed
main.c:27:7: error: (984) type redeclared
main.c:27:7: error: (1098) conflicting declarations for variable "TRISB" (main.c:27)
make[2]: *** [build/default/production/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/main.p1' failed
make[2]: Leaving directory 'C:/Users/Rick/Documents/PIC Projects/Red Light.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Rick/Documents/PIC Projects/Red Light.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 563ms)
#1

5 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 11000
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 16F527 compile issue TRIS register 2020/07/30 20:58:28 (permalink)
    +2 (2)
    Executable code must be inside a function. ;)
     
    #2
    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 16F527 compile issue TRIS register 2020/07/30 21:47:31 (permalink)
    +1 (1)
    1and0
    Executable code must be inside a function. ;)

    +1

    Also, get rid of this line:
    #include <pic16f527.h>

    I assume you only added it while trying to solve the problem, but it is unneeded and pointless.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    katela
    Super Member
    • Total Posts : 1833
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: 16F527 compile issue TRIS register 2020/07/31 00:00:35 (permalink)
    +1 (1)
    Put your TRISB inside the main function.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #4
    TheDickChuck
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/05/01 17:07:32
    • Location: 0
    • Status: offline
    Re: 16F527 compile issue TRIS register 2020/08/01 19:15:25 (permalink)
    0
    Thanks to all - I've been out of the saddle a while!  That fixed me up, although it seems you can't refer to individual pins like TRISB6 etc on 16F527 with XC8 like you can with other PICs.
     
    Now... how can I mark this thread as "closed" or is there a need for me to do that?
    -Rick
    #5
    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 16F527 compile issue TRIS register 2020/08/01 22:17:16 (permalink)
    +1 (1)
    TheDickChuck
    Thanks to all - I've been out of the saddle a while!  That fixed me up, although it seems you can't refer to individual pins like TRISB6 etc on 16F527 with XC8 like you can with other PICs.

    That is correct.
    This is a "base line" device, so the TRIS registers are write only, so it's impossible to access individual bits. You have to write to the whole register in one go.
     

    Now... how can I mark this thread as "closed" or is there a need for me to do that?

    If you want to, edit the first post and add "SOLVED" to the title.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5