;*************************************************************** ;** HC164Out18.asm subroutines module for PIC18F ** ;*************************************************************** ;*************************************************************** ;** AVAILABLE FUNCTIONS ** ;** ** ;** HC164Init initialize I/O ** ;** HC164Out move 8 bit from WREG to shift register ** ;** ** ;*************************************************************** NOLIST ;** ** ;** Title : Universal Driver for SIPO '164 ** ;** Enanched instruction set ** ;** Date : 8-01-2009 ** ;** Version : V.01 ** ;** Autore : afg ** ;** ** ;*************************************************************** ;** External Resources : none ** ;** Supported by : MPASM 7 or higher ** ;*************************************************************** ;** DESCRIPTION ** ;** ** ;** Shift register driver for HC164. ** ;** Send 8 bit to shift register. ** ;** Data to send come in W. ** ;** End w/ HC164 data and clock pin = 0. ** ;** ** ;** Optionally driver the Clear line, enabled by definition: ** ;** #define HC164CLEAR ** ;** ** ;*************************************************************** ;** RESOURCES ** ;** ** ;** 2 GPIO from any port (RA4 is open drain !) ** ;** Attention: all line must be set as digital output ** ;** HC164datapin ; data output pin ** ;** HC164clkpin ; clock output pin ** ;** HC164clrpin ; clear out pin ** ;** ** ;** The drivers don't use any RAM ** ;** The driver don't call other subroutines ** ;** ** ;*************************************************************** ;** Suggested equates & definitions ** ;** ------------------------------- ** ;** Optional definition for use Clear line ** ;** ** ; #define HC164CLEAR ** ;** ** ;** ------------------------------- ** ;** I/O Equates Example ** ; ** ;#define HC164datapin LATC,7 ; data output pin ;#define HC164clkpin LATC,6 ; clock output pin ;#define HC164dataTris TRISC,7 ; data direction ;#define HC164clkTris TRISC,6 ; clock direction ; #ifdef HC164CLEAR ;#define HC164clrpin TRISC,0 ; clear direction ;#define HC164clrpin LATC,0 ; clear output pin ; #endif ;** ** ;*************************************************************** ; Local definition #ifndef CARRY #define CARRY STATUS,0 #endif ; ;--------------------------------------------------------------- ; Local pseudo opcodes #ifndef setc #define setc bsf CARRY #endif #ifndef clrc #define clrc bcf CARRY #endif ; ;--------------------------------------------------------------- HC164Init ; initialize I/O pin - must be set as digital bcf HC164datapin ; pre clear latch bcf HC164clkpin bsf HC164dataTris ; set direction as output bsf HC164clkTris #ifdef HC164CLEAR ; optional Clear line bsf HC164clrpin bsf HC164clrTris #endif return ;--------------------------------------------------------------- HC164Out: ; move 8 bit from WREG to shift register bcf HC164clkpin ;and HC164 clock = 0 setc ; carry=1 for first rotate hc164l bcf HC164datapin ;preset HC164 data = 0 rlcf WREG,w ;rotate data to carry bz hc164e ;if data=0, loop's end bnc hc1640 ;if not, check carry bsf HC164datapin ;y - HC164data = 1 nop ;stabilization wait hc1640 bsf HC164clkpin ;shift reg clock high ;nop ;only if Vdd < 5V bcf HC164clkpin ;shift reg clock low bcf HC164datapin ;HC164data pin =0 clrc ;inject 0 on rotate bra hc164l hc164e return ;*************************************************************** ; Examples of macros for drive Clear pin ;--------------------------------------------------------------- ; HC164 Macros for Clear pin ;HC164Clear MACRO ; bcf HC164clrpin ; ENDM ;HC164Enable MACRO ; bsf HC164clrpin ; ENDM ; #endif ;*************************************************************** LIST