---
+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Advanced Member level 2
    Points: 11,718, Level: 25

    Join Date
    Feb 2005
    Posts
    615
    Helped
    7 / 7
    Points
    11,718
    Level
    25

    How to write a C program for PIC16f877?

    Hai.......

    How to write a C program??

    i using PIC 16f877, i use PortC as a input, can i write a program when PIC receive 8 input signal than this all input convert to binary form?? example x=0b01010101. How to write the program in C...


    Thy...

    •   Alt16th February 2005, 02:42

      advertising

        
       

  2. #2
    Banned
    Points: 9,649, Level: 23

    Join Date
    Jan 2004
    Location
    Philippines
    Posts
    966
    Helped
    74 / 74
    Points
    9,649
    Level
    23

    pic16f877 c programming

    Can you clarify your question? And what PIC C software are you using CCS C?

    Of course your input is always in binary form as it is digital, but when it is in group of 8 or a byte, always it is better to address it as a hexadecimal.



  3. #3
    Advanced Member level 2
    Points: 11,718, Level: 25

    Join Date
    Feb 2005
    Posts
    615
    Helped
    7 / 7
    Points
    11,718
    Level
    25

    set_tris_c

    Quote Originally Posted by glenjoy
    Can you clarify your question? And what PIC C software are you using CCS C?

    Of course your input is always in binary form as it is digital, but when it is in group of 8 or a byte, always it is better to address it as a hexadecimal.

    Ya... you are right CCS C. Sorry.... How to change in hexadecimal, example input is 00001111 than how to change in hex??? can you give sample??

    Do you have MSN and Mail i can contect you easy....

    Thy....



    •   Alt16th February 2005, 03:37

      advertising

        
       

  4. #4
    Banned
    Points: 9,649, Level: 23

    Join Date
    Jan 2004
    Location
    Philippines
    Posts
    966
    Helped
    74 / 74
    Points
    9,649
    Level
    23

    pic16f877a programs

    What do you mean how to change to hexadecimal? You are handling microcontrollers without understanding Base-N conversions?

    Search GOOGLE for binary to hexadecimal conversion.

    I will only teach you how to read the ports in a PORT of PIC.

    On CCS C there is a command INPUT_X() where X is the PORT letter, either A,B,C,D or E.

    But of course your must set the TRI-State buffers first to input.

    For example PORT_C:

    set_tris_c(0x0F); // means higher nibble of port c is output and lower nibble is input

    so if the instruction is:

    set_tris_c(0xFF); // means all pins are inputs

    to get the value of the port pins:

    char in_value;

    in_value = input_c();

    // if the value you read in in_value is 0x00 means all port pin inputs are logic 0.

    if you are reading CCS C help file you can see there that you can get the value of a single pin without any problem.



  5. #5
    Advanced Member level 2
    Points: 11,718, Level: 25

    Join Date
    Feb 2005
    Posts
    615
    Helped
    7 / 7
    Points
    11,718
    Level
    25

    pic16f877a c programming

    Quote Originally Posted by glenjoy
    What do you mean how to change to hexadecimal? You are handling microcontrollers without understanding Base-N conversions?

    Search GOOGLE for binary to hexadecimal conversion.

    I will only teach you how to read the ports in a PORT of PIC.

    On CCS C there is a command INPUT_X() where X is the PORT letter, either A,B,C,D or E.

    But of course your must set the TRI-State buffers first to input.

    For example PORT_C:

    set_tris_c(0x0F); // means higher nibble of port c is output and lower nibble is input

    so if the instruction is:

    set_tris_c(0xFF); // means all pins are inputs

    to get the value of the port pins:

    char in_value;

    in_value = input_c();

    // if the value you read in in_value is 0x00 means all port pin inputs are logic 0.

    if you are reading CCS C help file you can see there that you can get the value of a single pin without any problem.

    Hai...

    You mean set_tris_c(0x0F); the 0x0F the 0F is port c is o/p and 0xFF is i/p.
    If 0x1F, 0x2F,.... stand for what??

    The example that you give is

    -------------------------------------------------------
    set_tris_c(0xFF); // means all pins are inputs

    char in_value; // Why you put char not int???
    in_value = input_c();
    -------------------------------------------------------

    if my input is 10001100 can i convert to hex 0x8C as you say.....


    Thy....



  6. #6
    Banned
    Points: 9,649, Level: 23

    Join Date
    Jan 2004
    Location
    Philippines
    Posts
    966
    Helped
    74 / 74
    Points
    9,649
    Level
    23

    pic16f877 c

    Better read C programming by Kernigham and Richie first.

    It is one of the best ways to learn C.



  7. #7
    Advanced Member level 2
    Points: 11,718, Level: 25

    Join Date
    Feb 2005
    Posts
    615
    Helped
    7 / 7
    Points
    11,718
    Level
    25

    pic16f877a c

    Quote Originally Posted by glenjoy
    Better read C programming by Kernigham and Richie first.

    It is one of the best ways to learn C.
    --------------------------
    #define LCD 0x81
    --------------------------

    What the meaning for 0x81??

    Added after 4 minutes:

    Quote Originally Posted by glenjoy
    Better read C programming by Kernigham and Richie first.

    It is one of the best ways to learn C.

    ----------------------------------
    #define LCD 0x81
    ----------------------------------

    Above what's the meaning for??



  8. #8
    Banned
    Points: 9,649, Level: 23

    Join Date
    Jan 2004
    Location
    Philippines
    Posts
    966
    Helped
    74 / 74
    Points
    9,649
    Level
    23

    pic16f877 in c

    it means name the equate the number 0x81 to LCD.



+ Post New Thread
Please login