1. 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.
    Dismiss Notice

Bool

Discussion in 'Microcontrollers' started by be80be, Aug 12, 2017.

  1. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    How would one write this in xc8
    Code (text):
    bool read_SCL(void);
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Typedef unsigned char BOOL;

    If you include <stdbool.h> it's defined in there, also true and false are also defined...
     
  3. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    I tried that it saying it can't find the .h file include <stdbool.h>
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE

    Well it's definitely in the include directory... I just check V1.32, V1.33 and V1.41.. All three have the file..
    upload_2017-8-13_9-45-29.png
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    But!! Even so.... It's just an unsigned char.... 1 ~ 255 is true 0 is false..
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Ian I no it's in there when I try to use it I get error that it can't be found.

    You know I don't mean this in a mean way but I seen people post and get all kind of help I'm not a C programmer I don't no it all but I googled for 2 days. And this is about all I found about boolen
    It's Not really for c It can be used if you add the #include "stdbool.h"
    Which I did
    Code (text):

    #include "xc.h"
    #include "stdbool.h"
    #include "GenericTypeDefs.h"

    #include "boolType.h"
    #define I2CSPEED 100

    void I2C_delay(void);
    BOOL read_SCL(void);  // Return current level of SCL line, 0 or 1
    BOOL read_SDA(void);  // Return current level of SDA line, 0 or 1
    void set_SCL(void);   // Do not drive SCL (set pin high-impedance)
    void clear_SCL(void); // Actively drive SCL signal low
    void set_SDA(void);   // Do not drive SDA (set pin high-impedance)
    void clear_SDA(void); // Actively drive SDA signal low
    void arbitration_lost(void);
     
    I get a bucket load of these
    C:/Users/USER/Desktop/Clearning/bitbang/bitbang.X/main.c:81: warning: (374) missing basic type; int assumed
    I can change to a .cpp C++ and I can use them.
    But bool is being used a type of int to just check if I'm getting a 0 or 1 bit for ack on the scl line .
    I found this code from microchip sample and some reason mplab x 3.65 or 4.00 dosen't like bool at all.
     
    Last edited: Aug 13, 2017
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Code (c):
    #include "xc.h"
    #include "stdbool.h"
    #include "GenericTypeDefs.h"

    #include "boolType.h"
    All wrong!!
    Use...
    Code (c):
    #include <xc.h>
    #include <stdbool.h>
    #include <GenericTypeDefs.h>

    #include <boolType.h>
    Quotes "" are for working directory and triangular braces <> are for the compiler directory..
     
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    I Be leave you but It still not right I did it both ways " " and < > get the same bull it can't even find xc.h
    belive.png

    I guess I need write a BOOL
    Like
    Code (text):

    int BOOL;
    int bool;
    int false;
    false== 0;
    int true;
    true==1;
    BOOL== bool;
    If  (BOOL=1){
    return (true)
    }
    else if (BOOL=0){
    return (false)
     
    But I don't think this is the right way cause the code is testing false or true
     
    Last edited: Aug 13, 2017
  10. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Let's say I do it this way
    #define bool int
    #define true 1
    #define false 0
    I need BOOL and bool to be the same BOOL is the function name
    where as bool is just a test
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,306
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Its easier to typedef..

    typedef unsigned int bool;
    typedef bool BOOL;

    Job done...
     
  12. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    I think I figured why
    #include <xc.h>
    #include <stdbool.h>
    Was not working I was using the plib and to get that to work I had to point to where they where
    Then when I went to play with this i2c code it's still pointing to plib folder.
    So now it cant find the files as it should I reset the compiler path and what not back to default and it's using it now.
     

Share This Page