Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [Moved] MikroC Pro for 74HC595 on a PIC16F887

Status
Not open for further replies.

Robert T

Member level 1
Member level 1
Joined
Dec 21, 2011
Messages
40
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,655
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
 

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
https://www.edaboard.com/threads/231411/
 

    V

    Points: 2
    Helpful Answer Positive Rating
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;
   }
}
 

    V

    Points: 2
    Helpful Answer Positive Rating
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;

}
 
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) {
      //
   }
}
 
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.
 

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.
 
In the above code, what should be inside the

While(1)
{

}
 

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
 

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
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top