REM >BCDClock REM Simple example in BBC BASIC for RISC OS, of reading the time REM and pushing it to a MAX7219 driving a binary-coded-decimal REM clock shield. REM REM Kris Adcock March 2020 REM REM http://www.danceswithferrets.org/geekblog/?page_id=1034 REM ON ERROR REPORT:PRINT " at line ";ERL:END PROCinit PROCgo END DEF PROCinit maxReg_NoOp%=0 maxReg_Digit0%=1 maxReg_Digit1%=2 maxReg_Digit2%=3 maxReg_Digit3%=4 maxReg_Digit4%=5 maxReg_Digit5%=6 maxReg_Digit6%=7 maxReg_Digit7%=8 maxReg_DecodeMode%=9 maxReg_Intensity%=10 maxReg_ScanLimit%=11 maxReg_Shutdown%=12 maxReg_DisplayTest%=15 datapin%=17:REM GPIO 17 (pin 11) clockpin%=18:REM GPIO 18 (pin 12) selectpin%=27:REM GPIO 27 (pin 13) REM Set those GPIO pins as outputs ... SYS "GPIO_WriteMode",datapin%,1 SYS "GPIO_WriteMode",clockpin%,1 SYS "GPIO_WriteMode",selectpin%,1 REM And set them high to begin with ... SYS "GPIO_WriteData",datapin%,1 SYS "GPIO_WriteData",clockpin%,1 SYS "GPIO_WriteData",selectpin%,1 PROCsetupbasics(15) ENDPROC DEF PROCgo LOCAL t$,oldt$,h_upper%,h_lower%,m_upper%,m_lower%,s_upper%,s_lower% oldt$="" REPEAT REM Repeatedly grab the time until it differs from the LAST time we REM displayed. That way, we're sure we're changing the display right REM at the beginning of the second ... REPEAT t$=TIME$ UNTIL t$<>oldt$ h_upper%=VAL(MID$(t$,17,1)) h_lower%=VAL(MID$(t$,18,1)) m_upper%=VAL(MID$(t$,20,1)) m_lower%=VAL(MID$(t$,21,1)) s_upper%=VAL(MID$(t$,23,1)) s_lower%=VAL(MID$(t$,24,1)) PROCsetdigit(5, h_upper%) PROCsetdigit(4, h_lower%) PROCsetdigit(3, m_upper%) PROCsetdigit(2, m_lower%) PROCsetdigit(1, s_upper%) PROCsetdigit(0, s_lower%) PRINT ;h_upper%;h_lower%;":";m_upper%;m_lower%;":";s_upper%;s_lower% oldt$=t$ UNTIL FALSE ENDPROC DEF PROCsetupbasics(brightness%) PROCwrite(maxReg_ScanLimit%, 5) PROCwrite(maxReg_DecodeMode%, 0):REM Using IC in matrix mode, not seven-segment mode PROCwrite(maxReg_Shutdown%, 1):REM Not in shutdown mode PROCwrite(maxReg_DisplayTest%, 0):REM No display test, thanks PROCwrite(maxReg_Intensity%, brightness%) ENDPROC DEF PROCsetdigit(digit%, val%) PROCwrite(maxReg_Digit0% + digit%, val%) ENDPROC DEF PROCwrite(reg%, val%) SYS "GPIO_WriteData",selectpin%,0 PROCsendbyte(reg%) PROCsendbyte(val%) SYS "GPIO_WriteData",selectpin%,1 ENDPROC DEF PROCsendbyte(val%) LOCAL x%,bit% REM Send byte out on data pin, one bit at a time (highest bit first) FOR x%=7 TO 0 STEP -1 IF val% AND (1<