As the title shows, I have been trying to create a library for the popular shift register, which compiled successfully in Atmel Studio 6. However, in practise, whichever byte I set in the shiftWrite function is meaningless, as the leds are all on, all of the time. If anyone has any ideas for this phenomenon, I would greatly appreciate any replies, and questions surrounding the hardware are welcomed. The library is as follows:
#ifndef shift #define shift #include <avr/io.h> #include <util/delay.h> //define variables for ease of use #define shiftPort PORTB #define shiftDDR DDRB #define shiftDS PB0 #define shiftClock PB1 #define storeClock PB2 void shiftInit(){ shiftDDR |= (1<<shiftClock)|(1<<storeClock)|(1<<shiftDS);//Make output lines } //Define macros for DS line #define shiftHigh() (shiftPort |= 1<<shiftDS) #define shiftLow() (shiftPort &= ~(1<<shiftDS)) void shiftPulse(){//Pulse the shiftClock line shiftPort |= 1<<shiftClock;//High shiftPort &= ~(1<<shiftClock);//Low } void shiftLatch(){//Pulse the storeClock line shiftPort |= 1<<storeClock;//High _delay_loop_1(1); shiftPort &= ~(1<<storeClock);//Low _delay_loop_1(1); } void shiftWrite(uint8_t data){//The main function to send byte: argument is the byte for you to send for(uint8_t i=0;i<8;i++){ if(data & 0b10000000){ shiftHigh();//MSB is high }else{ shiftLow();//MSB is low }//else shiftPulse();//Pulse the Clock line data = data<<1;//Move next bit to MSB place }//For shiftLatch();//Move all 8 bits to output latch at once }//shiftWrite void wait(){//Function to delay 500ms for(uint8_t i=0;i<30;i++){ _delay_loop_2(0); }//For }//Wait #endif