This is actually a continuation of my blog entry https://www.edaboard.com/blog/1628/ where I have used C language routine. Now its the time to use Assembly Language for PIC. The Code is tested on PIC16F84A with 4MHz crystal. Compiler used MCS-51 under M-IDE Studio.
The associated program shows how to transfer a byte data serially to the 74HC595 and then sets the output accordingly.
According to page 5 of Datasheet, the outputs of 74HC595 provide 8 mA. Though I have used 330E resistors to drive LEDs , this should not be done! It is therefore recommended to connect a higher resistance (620E). LEDs light up very, very little, but enough to test the circuit.
I will mainly cover the technical details to connect a 74HC595 with a microcontroller. I will avoid the theory of a shift register and all those theoretical details.
The data are transferred into the shift register 74HC595 pin through the PIN 14 (Serial date).
PIN 11 (Shift register clock). Once finished sending data, just bring a high level on the pin 12 (Storage Clock or Latch) to transfer data from the shift register to the latch. The pin 13 (Output Enable - active low) enables the transfer of data from the latch to the output ports when it is brought low: since we connected the drive pin to ground, they meet again on the data outputs as soon as we give the shot clock on the latch. The pin 10 is the master reset: placing it at a low level resets the contents of the shift register, for which we keep it up for safety. The pin 9 we keep it disconnected because it is not used in this application.
You can use any microcontroller but be careful, in case of open collector pins, add pull up resistors.
And the HC595.inc library
The associated program shows how to transfer a byte data serially to the 74HC595 and then sets the output accordingly.
According to page 5 of Datasheet, the outputs of 74HC595 provide 8 mA. Though I have used 330E resistors to drive LEDs , this should not be done! It is therefore recommended to connect a higher resistance (620E). LEDs light up very, very little, but enough to test the circuit.
I will mainly cover the technical details to connect a 74HC595 with a microcontroller. I will avoid the theory of a shift register and all those theoretical details.
The data are transferred into the shift register 74HC595 pin through the PIN 14 (Serial date).
PIN 11 (Shift register clock). Once finished sending data, just bring a high level on the pin 12 (Storage Clock or Latch) to transfer data from the shift register to the latch. The pin 13 (Output Enable - active low) enables the transfer of data from the latch to the output ports when it is brought low: since we connected the drive pin to ground, they meet again on the data outputs as soon as we give the shot clock on the latch. The pin 10 is the master reset: placing it at a low level resets the contents of the shift register, for which we keep it up for safety. The pin 9 we keep it disconnected because it is not used in this application.
You can use any microcontroller but be careful, in case of open collector pins, add pull up resistors.
Code - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 ;Following is the code to switch on alternate LEDs for 1 seconds list p=16F84A #include <p16F84A.inc> __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC ERRORLEVEL -302 CBLOCK 0X0C TX ; COUNTSPI d1 d2 d3 ENDC #define DATA1 PORTA,0 #define CLOCK PORTA,1 #define LATCH PORTA,2 ORG 0X00 GOTO MAIN #include "HC595.INC" ;;Thanks to Nebojsa Matic of mikroElektronika for idea ;;;;;;;;;;;;;;;;;1 sec delay;;;;;;;;;;;;;;;;;;;;;;; DELAY1s ;999990 cycles movlw 0x07 movwf d1 movlw 0x2F movwf d2 movlw 0x03 movwf d3 Delay_01 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_01 ;6 cycles goto $+1 goto $+1 goto $+1 ;4 cycles (including call) return MAIN BSF STATUS,RP0 MOVLW B'00000' MOVWF TRISA BCF STATUS,RP0 CLRF PORTA LUPHR CLRF PORTA MOVLW B'10101010' MOVWF TX HC595 TX,COUNTSPI CALL DELAY1s CLRF PORTA MOVLW B'01010101' MOVWF TX HC595 TX,COUNTSPI CALL DELAY1s GOTO LUPHR END
And the HC595.inc library
Code - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;HC595.inc;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; ;Thanks to Nebojsa Matic of mikroElektronika for idea ;Var variable whose contents is transferred to outputs of shift register. ;Var1 loop counter ;Here 8bit data is used, so VAR1 gets decimal 8 to continue the loop for 8 times HC595 MACRO VAR,VAR1 LOCAL LOOP MOVLW .8 MOVWF VAR1 LOOP RLF VAR,F BTFSS STATUS,C BCF DATA1 BTFSC STATUS,C BSF DATA1 BSF CLOCK NOP BCF CLOCK DECFSZ VAR1,F GOTO LOOP BSF LATCH NOP BCF LATCH ENDM