#picaxe 20x2
#no_table
'=======================================================================================================================================================
'===[TITLE & DESCRIPTION]===============================================================================================================================
'=======================================================================================================================================================
'AS1115 Test Code
'This is test code to figure out how to use the AS1115 LED driver.
'The "counter" variable counts from 0 to 999 and the result is shown on a 3-digit 7-segment LED display with common cathode.
'
' PICAXE-20X2 (defaults to 8MHz internal operation)
' __________
'+5V (+V) -|1 20|- (0V) GROUND
'SERIAL IN (Serial In) -|2 19|- (A.0/Serial Out/16) SERIAL OUT
' (ADC3/C.7/15) -|3 18|- (B.0/ADC1/hint1/0)
' (C.6/input only/14) -|4 17|- (B.1/ADC2/hint2/SRQ/1)
' (hpwm A/pwm C.5/C.5/13) -|5 16|- (B.2/ADC4/C2+/2)
' (hpwm B/SRNQ/C.4/12) -|6 15|- (B.3/ADC5/C2-/3)
' (hpwm C/ADC7/C.3/11) -|7 14|- (B.4/ADC6/hpwm D/C1-/4)
' kb clk/ADC8/C.2/10) -|8 13|- (B.5/ADC10/hi2c sda/hspi sdi/5) I2C SDA
' (hspi sdo/kb data/adc9/C.1/9) -|9 12|- (B.6/ADC11/hserin/6)
' (hserout/C.0/8) -|10 11|- (B.7/hi2c scl/hspi sck/7) I2C SCL
' ----------
'=======================================================================================================================================================
'===[PIN DEFINITIONS]===================================================================================================================================
'=======================================================================================================================================================
'inputs:
'(none)
'outputs:
SYMBOL SCL = b.7
SYMBOL SDA = b.5
'=======================================================================================================================================================
'===[CONSTANTS]=========================================================================================================================================
'=======================================================================================================================================================
SYMBOL TENTHSDIG = %00000001
SYMBOL ONESDIG = %00000010
SYMBOL TENSDIG = %00000011
SYMBOL AS1115_ADDRESS = %00000001 'Bit0 is ignored, and must be 1 for the PICAXE to function
'=======================================================================================================================================================
'===[VARIABLES]=========================================================================================================================================
'=======================================================================================================================================================
SYMBOL TENTHSDIGVAL = b1
SYMBOL ONESDIGVAL = b2
SYMBOL TENSDIGVAL = b3
SYMBOL BRIGHTNESS = b8 'a vaule of 0 to 15 stored in b8 gives minimum to maximum brightness
SYMBOL counter = W9
'=======================================================================================================================================================
'===[INITIALIZATION]====================================================================================================================================
'=======================================================================================================================================================
'prepare for data transfer with LED controller:
hi2csetup i2cmaster, SYMBOL AS1115_ADDRESS, i2cslow_8, i2cbyte 'prepare for data transfer with LED controller.
'reset the registers of the AS1115:
hi2cout 0x0C, (0x01)
'decode mode:
hi2cout %00001001, (0x07)
'set AS1115 LED controller to max brightness:
BRIGHTNESS = 15: hi2cout %00001010, (BRIGHTNESS)
'set AS1115 LED controller to display 8 of the 8 digits even though this code only uses 3 digits:
hi2cout %00001011, (0x07)
'=======================================================================================================================================================
'===[MAIN ROUTINE]======================================================================================================================================
'=======================================================================================================================================================
do
for counter = 0 to 999
TENTHSDIGVAL = counter dig 0 'get the tenths digit of the counter variable
ONESDIGVAL = counter dig 1 'get the ones digit of the counter variable
TENSDIGVAL = counter dig 2 'get the tens digit of the counter variable
if counter <10 THEN LET ONESDIGVAL = 0: endif
if counter <100 THEN LET TENSDIGVAL = 15: endif
SETBIT ONESDIGVAL, 7 'turns on the decimal point between the ones digit and the tenths digit
hi2cout TENTHSDIG, (TENTHSDIGVAL)
hi2cout ONESDIG, (ONESDIGVAL)
hi2cout TENSDIG, (TENSDIGVAL)
pause 100 'this delay can be changed to make the counter go faster or slower.
next
loop