Sub 7seg
D1 = Wr1 / 100
Seg2 = D1 * 100
Seg1 = Wr1 - Seg2
D2 = Seg1 / 10
Seg2 = D1 * 100
Seg3 = D2 * 10
Seg4 = Seg2 + Seg3
Seg1 = Wr1 - Seg4
D3 = Seg1
Gosub Max7219_setup
Main:
Disp_num = 3 ' ( 0 - 7 ) digit#
Disp_data = D3
Disp_num = 2 ' ( 0 - 7 ) digit#
Disp_data = D2
' (0 - 15 ) number to display.
Disp_num = 1 ' ( 0 - 7 ) digit#
Disp_data = D1
Gosub Disp_write
' setup max7219 config. registers
Max7219_setup:
Disp_num = &H0C : Disp_data = 0 ' Shutdown On
Gosub Disp_write
Disp_num = 9 : Disp_data = &B0011_0111 ' Decode "B" For 1st 6
Gosub Disp_write
Disp_num = &H0A : Disp_data = &H0F ' Brightness Full
Gosub Disp_write
Disp_num = &H0B : Disp_data = 7 ' # Digits 8
Gosub Disp_write
Disp_num = &H0F : Disp_data = 0 ' Test Off
Gosub Disp_write
Disp_num = &H0C : Disp_data = 1 ' Shutdown Off
Gosub Disp_write
Return
' Sends data to the Max7219 display driver
Disp_write:
Disable Interrupts
Reset Ser_data
Reset Ser_clk
Reset Disp_en
Shiftout Ser_data , Ser_clk , Disp_num , 1
Shiftout Ser_data , Ser_clk , Disp_data , 1
Set Disp_en
Enable Interrupts
Return
End Sub
Lesezeichen