0000 0000 0000 0010 == 0x0002
0000 0000 0000 0100 == 0x0004
0000 0000 0000 1000 == 0x0008
0000 0000 0001 0000 == 0x0010
0000 0000 0010 0000 == 0x0020
0000 0000 0100 0000 == 0x0040
0000 0000 1000 0000 == 0x0080
0000 0001 0000 0000 == 0x0100
0000 0010 0000 0000 == 0x0200
0000 0100 0000 0000 == 0x0400
0000 1000 0000 0000 == 0x0800
0001 0000 0000 0000 == 0x1000
0010 0000 0000 0000 == 0x2000
0100 0000 0000 0000 == 0x4000
1000 0000 0000 0000 == 0x8000
*/
;;;;;;;;;;;;;;;
;;;;;;
Optional LCD Module: $17.95
;;; ;;;
;;;; ;;;;;;;; ;;;; ;;;;;; ;;;;;; ;;;;;;;;;;
ASSEMBLED
uint8_t i = 0;
uint16_t ce[] = { 0x0001,
0x0002, 0x0004, 0x0008, 0x0010,
0x0020, 0x0040, 0x0080, 0x0100,
0x0200, 0x0400, 0x0800, 0x1000,
0x2000, 0x4000, 0x8000 };
;;; ;;;
;;;;;;;;
;;;;;;;;;;;
;;; ;;;
ASSEMBLED
// Sweep right to left
for (j=0; j<=15; j++)
{
// Clear slave select
// so data won’t show while
shifting
clear_ss();
// output 16 bits to the 595
for (i=0; i<=15; i++)
{
// Put bit on mosi_pin
if(is_bit_set(ce[j], i)
set_mosi_bit();
;;;;; ;;;; ;;;; ;;;;;;;;;;; ;;;;; ;;;; ;;;;;;
Assembled: $49.95
;;; ;;;;;;;;;;;;; ; ;;;;;;; ; ;;;;;; ;;;;;;;;;; ; ;;;;;; ;;;;;;;;;;;; ; ; ; ; ;; ;;;;;;; ;;;;;;;
;;; ;;;
;;;;;;
;;;;;;; ;;;; ;;;;;; ;;;;;;;;;;; ;;;;;
;;;;;;;;;; ;;;;;;;;;;;;;;; ;;;;;;;;;
;;;;;;
else
clear_mosi_bit()
// Toggle the clock to output it
toggle_clock();
}
// Set slave select to transfer // data
// from serial to parallel // registers
set_ss();
// Wait a while
_delay_ms(100);
}
To sweep the LED back, just run
the ‘for’ loop backwards as shown in
the source code.
Last Shift
Well, shift registers are a pretty
cool way to save microcontroller pins,
but in case you’ve forgotten, all this is
in preparation so we can learn
hardware SPI and use it to read
external Flash memory. We’ll continue
in that direction next month. In the
meantime, if you want to get a leg up
on this you can purchase my book C
Programming for Microcontrollers along
with a projects kit from Nuts & Volts. If
this seemed a bit dense, then you
might want to try my book An Arduino
Workshop, also available from Nuts &
Volts. NV
November 2010 65