' LARRY GAMINDE TEMPATURE DISPLAY USING ' LEDs AND THE MAX-7219 LED DRIVER CHIP ' _____________________________________________________________________________ ' _____________________________________________________________________________ DEFINE OSC 10 CLEAR ' Program: MAX7219.BS2 ' This program controls the MAX7219 LED ' display driver. It demonstrates the basics of communicating with ' the 7219, and shows a convenient method for storing setup ' data in tables. To demonstrate practical application of the 7219, ' the program drives a 5-digit display to show the current ' value of a 16-bit counter (0-65535). The subroutines are not ' specialized for counting; they can display _any_ 16-bit ' value on the LCDs. (A specialized counting routine would be faster, ' since it would only update the digits necessary to maintain the ' count; however, it wouldn't be usable for displaying arbitrary ' 16-bit values, like the results of Pot, Pulsin, or an A-to-D ' conversion). PAUSE 700 ' Hardware interface with the 7219: DATA_n VAR PORTB.0 ' Bits are shifted out this pin # to 7219. CLK VAR PORTB.1 ' Data valid on rising edge of this clock pin. Load VAR PORTB.2 ' Tells 7219 to transfer data to LEDs. ' Register addresses for the MAX7219. To control a given attribute ' of the display, for instance its brightness or the number shown ' in a particular digit, you write the register address followed ' by the data. For example, to set the brightness, you'd send ' 'brite' followed by a number from 0 (off) to 15 (100% bright). decode con 9 ' Decode register; a 1 turns on BCD decoding. brite con 10 ' " " " intensity register. scan con 11 ' " " " scan-limit register. switch con 12 ' " " " on/off register. test con 15 ' Activates test mode (all digits on, 100% bright) ' Variables used in the program. max_dat Var word ' Word to be sent to MAX7219. index var BYTE ' Index into setup table. temp var BYTE ' Temporary variable used in outputting digits. NUMBER var BIT ' Flag used in blanking leading zeros. dispVal var word ' Value to be displayed on the LEDs. odd var index.bit0 ' Lsb of index. ' Next, it initializes the MAX7219. A lookup table is convenient way ' to organize the setup data; each register address is paired with ' its setting data. The table sets the scan limit to 4 (5 digits, ' numbered 0-4); brightness to 3; BCD decoding to the lower 5 digits ' (the only ones we're displaying), and switches the display on. The ' MAX7219 expects data in 16-bit packets, but our lookup table holds ' a series of 8-bit values. That's why the loop below is designed to ' pulse the Load line _every_other_ byte transmitted. TestLED: for index = 0 to 10 ' Retrieve 8 items from table. lookup index,[test,1,switch,1,scan,2,brite,5,decode,$0f],max_dat shiftout DATA_n,CLK,1,[max_dat] pulsout Load,5 pause 50 next for index = 0 to 1 ' Retrieve 8 items from table. lookup index,[switch,1],max_dat shiftout DATA_n,CLK,1,[max_dat] pulsout Load,5 PAUSE 50 NEXT ' Get next item from table. '************************************************************************ ' ====================== MAIN PROGRAM LOOP '========================= '************************************************************************ '* Basic Stamp Activity Board Sample Program DS1620 * '* 9 September, 1997 (BS-2) * '* * '* This program demonstrates the use of the Dallas DS1620 Digital * '* Thermometer/Thermostat chip. Simply place the DS1620 in the B * '* Socket and remove all jumpers on 'X4'. Please see the diagram * '* provided in the Basic Stamp Activity Board Notes for connection * '* information regarding the thermostat outputs. * '************************************************************************ DQ VAR PORTA.0 CLK1 VAR PORTA.1 RST VAR PORTA.2 Rconfig con $AC Wconfig con $0C CPU con %10 NoCPU con %00 OneShot con %01 Cont con %00 StartC con $EE StopC con $22 Rtemp con $AA Rhit con $A1 Whit con $01 Rlot con $A2 Wlot con $02 DSdata var word Sign var DSdata.bit8 T_sign var bit INIT: low RST high CLK pause 50 high RST shiftout DQ,CLK1,0,[Wconfig,CPU+Cont] low RST pause 50 high RST shiftout DQ,CLK1,0,[StartC] low RST START: SEROUT2 PORTB.7, $4054,10,[254,1] pause 50 high RST shiftout DQ,CLK1,0,[Rtemp] shiftin DQ,CLK1,1,[DSdata\9] low RST DSdata = ((DSdata * 9) + 320) / 10 DISPVAL = DSDATA GOTO MAXDISPLAY ' *********************************************************************** ' Now that the MAX7219 is properly initialized, we're ready to send it ' data. The loop below increments a 16-bit counter and displays it on ' the LEDs connected to the MAX. Subroutines below handle the details ' of converting binary values to binary-coded decimal (BCD) digits and ' sending them to the MAX. ' ========================= SUBROUTINES '=========================== ' The MAX7219 won't accept a number like "2742" and display it on ' the LEDs. Instead, it expects the program to send it individual ' digits preceded by their position on the display. For example, ' "2742" on a five-digit display would be expressed as: ' "digit 5: blank; digit 4: 2; digit 3: 7; digit 2: 4; digit 1: 2" ' The routine MaxDisplay below does just that, separating a value ' into individual digits and sending them to the MAX7219. If the ' lefthand digits are zero (as in a number like "102") the ' routine sends blanks, not zeros until it encounters the first ' non-zero digit. This is called "leading-zero blanking." MaxDisplay: SEROUT2 PORTB.7, $4054,10,[254,135, DEC3 DSDATA] shiftout DATA_n,CLK,1,[2] shiftout DATA_n,CLK,1,[dsdata dig 1] pulsout Load,2 shiftout DATA_n,CLK,1,[1] shiftout DATA_n,CLK,1,[dsdata dig 0] pulsout Load,2 pause 3000 goto START