Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Love xc8 could someone point me to why defines not working here

Status
Not open for further replies.

be80be

Well-Known Member
I put some defines just like mplab does and mine don't show as usable.
Code:
#include <xc.h>

#define ledA() PORTCbits.RC0  do { PORTCbits.RC0 = ~PORTCbits.RC0; } while(0)
#define ledB() PORTCbits.RC1  do { PORTCbits.RC1 = ~PORTCbits.RC1; } while(0)
#define ledC() PORTCbits.RC2  do { PORTCbits.RC2 = ~PORTCbits.RC2; } while(0)
#define ledD() PORTCbits.RC3  do { PORTCbits.RC3 = ~PORTCbits.RC3; } while(0)
#define ledE() PORTCbits.RC4  do { PORTCbits.RC4 = ~PORTCbits.RC4; } while(0)
#define ledF() PORTCbits.RC5  do { PORTCbits.RC5 = ~PORTCbits.RC5; } while(0)
#define ledG() PORTBbits.RB4  do { PORTBbits.RB4 = ~PORTBbits.RB4; } while(0)
void main(void) {
  OSCCAL= 0b01111110;
  OPTION =  0b11011111;
  unsigned int a;
  TRISC = 0x00;
  TRISB = 0x00; 
  ledA():
   __delay_ms(20);      
}
first one I use shows a error ledA can't find it
main.c:35: error: (192) undefined identifier "ledA"
 
Brackets tell the compiler it's a function and why do you have the do while construct.

Mike.
 
Why do you have the do while construct. It lets you toggle the pin with just the ledA being called
 
I got the ideal from here
Code:
/**
  @Generated Pin Manager Header File

  @Company:
    Microchip Technology Inc.

  @File Name:
    pin_manager.h

  @Summary:
    This is the Pin Manager file generated using MPLAB(c) Code Configurator

  @Description:
    This header file provides implementations for pin APIs for all pins selected in the GUI.
    Generation Information :
        Product Revision  :  MPLAB(c) Code Configurator - 4.26
        Device            :  PIC16F1825
        Version           :  1.01
    The generated drivers are tested against the following:
        Compiler          :  XC8 1.35
        MPLAB             :  MPLAB X 3.40

    Copyright (c) 2013 - 2015 released Microchip Technology Inc.  All rights reserved.

    Microchip licenses to you the right to use, modify, copy and distribute
    Software only when embedded on a Microchip microcontroller or digital signal
    controller that is integrated into your product or third party product
    (pursuant to the sublicense terms in the accompanying license agreement).

    You should refer to the license agreement accompanying this Software for
    additional information regarding your rights and obligations.

    SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
    EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
    MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
    IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
    CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
    OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
    INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
    CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
    SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
    (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

*/


#ifndef PIN_MANAGER_H
#define PIN_MANAGER_H

#define INPUT   1
#define OUTPUT  0

#define HIGH    1
#define LOW     0

#define ANALOG      1
#define DIGITAL     0

#define PULL_UP_ENABLED      1
#define PULL_UP_DISABLED     0

// get/set led aliases
#define led_TRIS               TRISCbits.TRISC2
#define led_LAT                LATCbits.LATC2
#define led_PORT               PORTCbits.RC2
#define led_WPU                WPUCbits.WPUC2
#define led_ANS                ANSELCbits.ANSC2
#define led_SetHigh()            do { LATCbits.LATC2 = 1; } while(0)
#define led_SetLow()             do { LATCbits.LATC2 = 0; } while(0)
#define led_Toggle()             do { LATCbits.LATC2 = ~LATCbits.LATC2; } while(0)
#define led_GetValue()           PORTCbits.RC2
#define led_SetDigitalInput()    do { TRISCbits.TRISC2 = 1; } while(0)
#define led_SetDigitalOutput()   do { TRISCbits.TRISC2 = 0; } while(0)
#define led_SetPullup()      do { WPUCbits.WPUC2 = 1; } while(0)
#define led_ResetPullup()    do { WPUCbits.WPUC2 = 0; } while(0)
#define led_SetAnalogMode()  do { ANSELCbits.ANSC2 = 1; } while(0)
#define led_SetDigitalMode() do { ANSELCbits.ANSC2 = 0; } while(0)

/**
 
I guess I need something like this
#define ledA PORTCbits.RC0
Then a
#define ledA_Toggle() do {PORTCbits.RC0 = ~ PORTCbits.RC0} while(0)
 
It's funny It don't work but it dose if i use a chip I can use MMC with to make the file
how do I get this to show up.
#define ledA() do {PORTCbits.RC0 = ~ PORTCbits.RC0} while(0)

That should work like it is
if i use ledA in code But it shows up not being able to find ledA
Ok I got it LOL can't have this before the do loop
PORTCbits.RC0 do { } while 0 not no good.
This makes it happen
#define ledA PORTCbits.RC0
#define ledA_Toggle() do { PORTCbits.RC0 = ~ PORTCbits.RC0; } while(0)
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top