It will be easier to do this
Better still, have you considered using the SHIFTOUT command? It's made for applications like these.Code:for i = 1 to 16 x = y & 1 ' take the lowest bit ' put it out here y = y >> 1 ' shift right by 1 place next
It will be easier to do this
Better still, have you considered using the SHIFTOUT command? It's made for applications like these.Code:for i = 1 to 16 x = y & 1 ' take the lowest bit ' put it out here y = y >> 1 ' shift right by 1 place next
I am indeed using shiftout. I don't think I filly understand it though...I am a little inexperienced with these things.
I basically receive two numbers serially from my PC and using shiftout send them as a word to the serial latches. All is good. With my test LEDs if I send the number 45 to the latches the leds all light as expected like this: 101101
However I want to switch each LED on sequentially with a pause rather than in 1 go so the sequence would be like this:
000001
000101
001101
101101
After learning about bitwise AND I thought I could do it in a loop but so far I have failed.
I appreciate your help!
Last edited by jimseng; - 25th September 2009 at 15:13.
Can we see your code?
Dave
Always wear safety glasses while programming.
yes you may :
I think I'm nearly there with this method (DCD)Code:Main: serin portc.7,6,lowbyte 'sit and wait for an input serin portc.7,6,highbyte 'sit and wait for an input outdata.lowbyte = lowbyte outdata.highbyte = highbyte if outdata = 0 then ' pause time according to turning on or off Tptime = 0 else Tptime = ptime 'from eprom endif FOR LoopCount = 1 to 16 bitmask = (outdata & ((DCD loopcount) - 1)) 'find the dec number corresponding to the first pin to switch on If (outdata & (DCD loopcount) - 1) <> (outdata & (DCD (loopcount - 1)) - 1) Then ' If we sent it just now don't bother again GOSUB SyncSend ; send the data pause TPtime 'pause for a bit endif NEXT LoopCount GOTO Main ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ;----[Send synchronous data]------------------------------------------------ SyncSend: SHIFTOUT SDout, SClk, 1,[bitmask\16] HIGH Strobe ; strobe the shift registers latches @ NOP ; hold Strobe for 1uS LOW Strobe ; Strobe idles LOW RETURN
I would love to know if there is a more efficient way of doing it.
Jerson, could you expand on what your method does?
I can see what you are trying to do. Basically, you have an integer that you want to put on 2 x 8 bit shift registers. The integer will change based on the pattern you want displayed. This is straightforward like you're doing it now. But, if you wish to light each LED one by one depending on the input word, this will do it
this line will let you light 1 led at a time (dot mode)Code:outputword var word ' this goes to the shift registers bitpos var word ' roll the bit you wish to mask out Main: serin portc.7,6,lowbyte 'sit and wait for an input serin portc.7,6,highbyte 'sit and wait for an input outdata.lowbyte = lowbyte outdata.highbyte = highbyte if outdata = 0 then ' pause time according to turning on or off Tptime = 0 else Tptime = ptime 'from eprom endif bitpos = 1 FOR LoopCount = 1 to 16 ' for each bit of the input OutputWord = bitmask & bitpos gosub SyncSend bitpos = bitpos << 1 ' move the bit 1 place to the left ' so that we can read the next bit pause TPtime ' wait for the pause time you want next GOTO Main ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ;----[Send synchronous data]------------------------------------------------ SyncSend: SHIFTOUT SDout, SClk, 1,[OutputWord\16] HIGH Strobe ; strobe the shift registers latches @ NOP ; hold Strobe for 1uS LOW Strobe ; Strobe idles LOW RETURN
bitpos = bitpos << 1 ' move the bit 1 place to the left so that we can read the next bit
But this will let you retain the ones that are already lit (bar mode)
bitpos = bitpos << 1 +1 ' move the bit 1 place to the left so that we can read the next bit and retain the one that was on previously
Hey thanks.
I managed to do it with dcd a bit like my previous post with a few tweaks to get it right but it is not nearly as efficient as yours. I think I almost get what is going on now.
Bookmarks