I am trying to emulate a shift register.
This is the code I have so far:
Is there an easier way to implement a shift register function?Code:DEFINE OSC 8 ' 8 MHz. oscillator CMCON = 7 ' 16F628, all digital TRISA = %11111100 ' PORTA.0 and PORTA.1 are outputs TRISB = 0 ' PORTB = Output ClockPin var PORTA.2 ' Clock and Data line DataPin Var PORTA.3 wvar Var Byte ' Variable WVar = 0 ' Initialize to '0' MainLoop: While ClockPin = 0 : wend ' Wait for clock to go '1' wvar = wvar << 1 ' Shift value in wvar 1 Bit left if DataPin = 1 then ' Dataline = '1' wvar = wvar || 1 ' Increase value else ' Dataline = '0' wvar = wvar && 254 ' Last bit is zero endif PORTB = wvar ' Set PORTB to wvar while ClockPin = 1 : wend ' Wait for clock to go '0' goto MainLoop ' Loop for ever




Bookmarks