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