---
+ Post New Thread
Results 1 to 12 of 12
  1. #1
    Newbie level 6
    Points: 274, Level: 3

    Join Date
    Dec 2011
    Posts
    11
    Helped
    2 / 2
    Points
    274
    Level
    3

    [Moved] MikroC Pro for 74HC595 on a PIC16F887

    I have spent 3 days trying to find and understand code to turn simply turn on some LED's through the 74HC595, so figured must be time to ask and see if anyone can help.
    Have read the manuals and tried many examples from Mikro and posts.

    I can write for Arduino but cannot get a handle on what is happening with 'C'. Have tried the Mikro Soft SPI and could not get it to work.
    If anyone can write a few lines so that I can understand how the data is transferred to turn on the LED's that would be greatly appreciated.

    There are 8 LEDS attached to the 74HC595.
    Would like to turn on/off individual LEDs using binary eg 0b00110011

    This is the start of my code.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    #define CLOCK1 PORTD.F0;                 // RD0 -----> Pin 11 Clock
    #define LATCH1 PORTD.F1;                 // RD1 -----> Pin 12 Latch
    #define DATA1 PORTD.F2;                  // RD2 ------> Pin 14 Data
    void main() {
      TRISD.F0 = TRISD.F1 = TRISD.F2 = 0;                // Pins set to output
         // send 0b00110011 to 74HC595
         // clock?
         // latch low to receive data
         // latch high for 74HC595 to turn on LEDs
       }
    }
    Thanks in advance.
    Robert

    •   Alt21st December 2011, 12:09

      advertising

        
       

  2. #2
    Advanced Member level 3
    Points: 8,373, Level: 21
    papunblg's Avatar
    Join Date
    Oct 2010
    Location
    Kolkata India
    Posts
    725
    Helped
    170 / 170
    Points
    8,373
    Level
    21
    Blog Entries
    9

    Re: MikroC Pro for 74HC595 on a PIC16F887

    For idea see the following link for code and schematic for PIC16F84A:--

    See: Extend OUTPUT pins of a PIC micror with the help of output shift register 74HC595
    Extend OUTPUT pins of a PIC microcontroller with the help of output shift register
    Rajsekhar Nag
    -------------..--------
    Knowledge Grows When Shared


    1 members found this post helpful.

  3. #3
    Administrator
    Points: 57,960, Level: 58
    Awards:
    3rd Helpful Member
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    8,147
    Helped
    2140 / 2140
    Points
    57,960
    Level
    58
    Blog Entries
    3

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Here is a recent thread discussion concerning several different varieties of shift registers, including 74HC595, and interfacing to PIC.

    Questions bout shiftregisters (74HC575, 74HC597)

    BigDog


    1 members found this post helpful.

    •   Alt21st December 2011, 19:00

      advertising

        
       

  4. #4
    Member level 4
    Points: 3,101, Level: 13

    Join Date
    Nov 2005
    Location
    Montenegro
    Posts
    70
    Helped
    5 / 5
    Points
    3,101
    Level
    13

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Here is routines for sending data to hc595:
    Code:
    #define SHIFT_DATA     PORTB.F0         // 74HC595 Data
    #define SHIFT_LATCH    PORTB.F1         // 74HC595 Latch
    #define SHIFT_CLOCK    PORTB.F2         // 74HC595 Clock
    
    
    void latch_595() {
       SHIFT_LATCH = 1;
       asm nop;
       SHIFT_LATCH = 0;
    }
    
    void shift_out_HC595(char one_digit) {
       char x;
       for (x=0; x<=7; ++x) {
          if (one_digit & 0x80) SHIFT_DATA = 1;
          else SHIFT_DATA = 0;
          one_digit <<= 1;
          SHIFT_CLOCK = 1;
          asm nop;
          SHIFT_CLOCK = 0;
       }
    }


    1 members found this post helpful.

  5. #5
    Newbie level 6
    Points: 274, Level: 3

    Join Date
    Dec 2011
    Posts
    11
    Helped
    2 / 2
    Points
    274
    Level
    3

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Thanks All, lots to work through here.

    Deniah. Tried the code but still no LEDs turning on.

    In the shift_out_HC595, should '++x' be 'x++' or does it not matter?

    My code for main -

    void main() {
    TRISB = 0; // PortB pins to output
    ansel = anselh = 0; // All pins to digital
    one_digit = 0b00110011;
    SHIFT_LATCH = 0; // latch low to enable data to HC595
    shift_out_HC595;
    latch_595;

    }


    1 members found this post helpful.

    •   Alt23rd December 2011, 10:16

      advertising

        
       

  6. #6
    Member level 4
    Points: 3,101, Level: 13

    Join Date
    Nov 2005
    Location
    Montenegro
    Posts
    70
    Helped
    5 / 5
    Points
    3,101
    Level
    13

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Write this in main:

    Code:
    void main() {
       TRISB = 0;                    // set PORTB to be output
       ANSEL  = 0;                  // configure AN pins as digital I/O
       ANSELH = 0;
    
       shift_out_HC595(0b00110011);
    
       latch_595();
    
       while (1) {
          //
       }
    }


    1 members found this post helpful.

  7. #7
    Newbie level 6
    Points: 274, Level: 3

    Join Date
    Dec 2011
    Posts
    11
    Helped
    2 / 2
    Points
    274
    Level
    3

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Thanks Deniah. Yes ..... it works !!!!!

    Interestingly -

    The LED's light up opposite to the output, that is, the pin that gets a 1 turns off (if I understand the start of the loop correctly)

    The last LED did not light up at all until I shifted the while(1) statement to the top of the main(). Then they all worked fine - Still have not worked out how that made a difference.

    Just two further questions please.
    What does the code "one_digit <<=0" do?
    In the code if (one_digit & 0x80) - is the 0x80 the memory address where the byte is stored for sending to the HC595?

    Thanks again.



  8. #8
    Member level 4
    Points: 3,101, Level: 13

    Join Date
    Nov 2005
    Location
    Montenegro
    Posts
    70
    Helped
    5 / 5
    Points
    3,101
    Level
    13

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    If you move while(1) statement above calls to shift_out_hc595() and latch_595(), then these two functions will newer execute.

    << and & are bitwise operators.

    << operator moves bits to the left, and
    & is bitwise AND operator. It returns 1 if both bits are 1, otherwise returns 0.

    Compile you program and run debugger. From variable list select variable to watch, change value representation to binary and step thru the code to see what is happening.


    1 members found this post helpful.

  9. #9
    Full Member level 4
    Points: 1,245, Level: 7

    Join Date
    Dec 2011
    Posts
    193
    Helped
    0 / 0
    Points
    1,245
    Level
    7

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    In the above code, what should be inside the

    While(1)
    {

    }



  10. #10
    Newbie level 6
    Points: 274, Level: 3

    Join Date
    Dec 2011
    Posts
    11
    Helped
    2 / 2
    Points
    274
    Level
    3

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Quote Originally Posted by Rohith_elec View Post
    In the above code, what should be inside the

    While(1)
    {

    }


    I got a message saying this thread has been deleted so I don't know if you will receive this message.
    If so, I changed to using Arduino code as the MicroC was to difficult for me.

    All the best,

    Robert



  11. #11
    Full Member level 4
    Points: 1,245, Level: 7

    Join Date
    Dec 2011
    Posts
    193
    Helped
    0 / 0
    Points
    1,245
    Level
    7

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Quote Originally Posted by Robert T View Post
    I got a message saying this thread has been deleted
    Robert
    No, its not deleted, its only moved,

    BTW u got it working on mikroC,
    what should be inside the

    while()
    {
    }



  12. #12
    Newbie level 6
    Points: 274, Level: 3

    Join Date
    Dec 2011
    Posts
    11
    Helped
    2 / 2
    Points
    274
    Level
    3

    Re: [Moved] MikroC Pro for 74HC595 on a PIC16F887

    Quote Originally Posted by Rohith_elec View Post
    No, its not deleted, its only moved,

    BTW u got it working on mikroC,
    what should be inside the

    while()
    {
    }

    I used the SPI routine in MicroC after much study it was fairly simple.

    void main() {
    ansel = anselh = 0;

    SPI_Init();

    While(1) {
    SPI1_Write(0b00000001);
    delay_ms(1000);
    SPI1_Write(0b00000000);
    delay_ms(1000);

    }
    }

    Hope this is helpful.

    Robert


    1 members found this post helpful.

+ Post New Thread
Please login