$regfile = "m8def.dat"
$crystal = 1000000                                          'Quarz:
3.6864 MHz
$baud = 4800                                                'Baudrate
der UART: 9600 Baud
'LCD config
Dim I As Byte
Config Lcdpin = Pin , Db4 = Portb.7 , Db5 = Portd.5 , Db6 = Portd.6 ,
Db7 = Portd.7 , E = Portb.6 , Rs = Portd.4       ' Natürlich so wie es
wirklich angeschlossen ist (4-Bit-Modus)
Dim A As Byte
Config Lcd = 20 * 4                                         'configure
lcd screen
'WR portconfig
Config Pinb.1 = Input
Config Pinc.3 = Output
'7-Seg Port Conf
Config Pinb.2 = Output
Config Pinb.3 = Output
Config Pinb.5 = Output
Disp_en Alias Portb.2                                       '
chip-select for display driVer
Ser_clk Alias Portb.5                                       ' clk for
display driver
Ser_data Alias Portb.3
'Var
Dim Wr1 As Integer                                          'Integer
Dim W As Byte
Dim Insgesamt As Integer
Dim Kw As Integer
Dim D1 As Integer
Dim D2 As Integer
Dim D3 As Integer
'Var 7 Seg
Dim Disp_num1 As Byte
Dim Disp_data1 As Byte
Dim Disp_num2 As Byte
Dim Disp_data2 As Byte
Dim Disp_num3 As Byte
Dim Disp_data3 As Byte
Dim Seg1 As Integer
Dim Seg2 As Integer
Dim Seg3 As Integer
Dim Seg4 As Integer
Dim Seg5 As Integer
Dim Seg6 As Integer
Dim Seg7 As Integer
'SUB Progs
Declare Sub Status
Declare Sub Wr1status
Declare Sub 
RS232
Declare Sub Kw
Declare Sub Störung
Declare Sub 7seg
'Display Init
Cls
Locate 1 , 1
Lcd "Iliocontrol"
Locate 2 , 1
Lcd "Wechselrichter1"
Locate 3 , 18
Lcd "kW"
Wr1 = 1
'WR1-Portabfrage
Do
    If Pinb.1 = 0 Then
      Call Wr1status
    'Else
     'Call Störung
    End If
    Call 
RS232
    Call 7seg
    'Insgesamt:= WR1+WR2..
    Insgesamt = Wr1
Loop
Sub Wr1status
   Wr1 = Wr1 + 1
   Call Status
End Sub
Sub Status
   Call Kw
   Locate 3 , 1
   Lcd Kw
End Sub
Sub Kw
   Kw = Wr1                                                 ' / 1000
End Sub
Sub Störung
Locate 3 , 1
Lcd "Stoerrung!!!"
End Sub
Sub 
RS232
  If Usr.rxc = 1 Then
  I = Udr                                                   'turn
display on
   Select Case I
      Case "1"
         Print "Wechselrichter1   " ; Wr1
      Case "2"
         Print "Wechselrichter2 ist nicht vorhanden!"
      Case "I"
         Print "Gesamtertrag   " ; Insgesamt
      Case "S"
      Do
         Portc.3 = 0
      Return
      Loop
   End Select
   End If
   Return
End Sub
Sub 7seg
Seg1 = Wr1 / 100 'digit3
Seg2 = Wr1 / 10 
Seg3 = Seg2 * 10
Seg4 = Seg1 * 100
Seg5 = Wr1 - Seg4
Seg6 = Seg5 / 10  'digit2
Seg7 = Wr1 - Seg3 'digit1
D1 = Seg7
D2 = Seg6
D3 = Seg1
 Gosub Max7219_setup
   Main:
   Disp_num3 = 3                               '  ( 0 - 7 ) digit#
   Disp_data3 = D3
   Disp_num2 = 2                               '  ( 0 - 7 ) digit#
   Disp_data2 = D2
                                     '  (0 - 15 ) number to display.
   Disp_num1 = 1                                   '  ( 0 - 7 )
digit#
   Disp_data1 = D1
   Gosub Disp_write
     'setup max7219 config. registers
   Max7219_setup:
      Disp_num1 = &H0C : Disp_data1 = 0                ' Shutdown On
      Gosub Disp_write
      Disp_num1 = 9 : Disp_data1 = &B0011_0111  ' Decode "B" For 1st
6
      Gosub Disp_write
      Disp_num1 = &H0A : Disp_data1 = &H0F      ' Brightness Full
      Gosub Disp_write
      Disp_num1 = &H0B : Disp_data1 = 7             ' # Digits 8
      Gosub Disp_write
      Disp_num1 = &H0F : Disp_data1 = 0              ' Test Off
      Gosub Disp_write
      Disp_num1 = &H0C : Disp_data1 = 1          ' Shutdown Off
      Gosub Disp_write
      Disp_num2 = &H0C : Disp_data2 = 0         ' Shutdown On
      Gosub Disp_write
      Disp_num2 = 9 : Disp_data2 = &B0011_0111  ' Decode "B" For 1st
6
      Gosub Disp_write
      Disp_num2 = &H0A : Disp_data2 = &H0F      ' Brightness Full
      Gosub Disp_write
      Disp_num2 = &H0B : Disp_data2 = 7           ' # Digits 8
      Gosub Disp_write
      Disp_num2 = &H0F : Disp_data2 = 0          ' Test Off
      Gosub Disp_write
      Disp_num2 = &H0C : Disp_data2 = 1     ' Shutdown Off
      Gosub Disp_write
      Disp_num3 = &H0C : Disp_data3 = 0           ' Shutdown On
      Gosub Disp_write
      Disp_num3 = 9 : Disp_data3 = &B0011   ' Decode "B" For 1st 6
      Gosub Disp_write
      Disp_num3 = &H0A : Disp_data3 = &H0F    ' Brightness Full
      Gosub Disp_write
      Disp_num3 = &H0B : Disp_data3 = 7        ' # Digits 8
      Gosub Disp_write
      Disp_num3 = &H0F : Disp_data3 = 0       ' Test Off
      Gosub Disp_write
      Disp_num3 = &H0C : Disp_data3 = 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_num1 , 1
      Shiftout Ser_data , Ser_clk , Disp_data1 , 1
      'Disable Interrupts
      'Reset Ser_data
      'Reset Ser_clk
      'Reset Disp_en
      Shiftout Ser_data , Ser_clk , Disp_num2 , 1
      Shiftout Ser_data , Ser_clk , Disp_data2 , 1
      'Disable Interrupts
      'Reset Ser_data
      'Reset Ser_clk
      'Reset Disp_en
      Shiftout Ser_data , Ser_clk , Disp_num3 , 1
      Shiftout Ser_data , Ser_clk , Disp_data3 , 1
      Set Disp_en
      Enable Interrupts
   Return
End Sub
End
			
		
 
	
Lesezeichen