Testuje zegar na A2560 program główny wygląda tak
- $regfile = "m2560def.dat"
- $crystal = 16000000
- $hwstack = 255
- $swstack = 128
- $framesize = 128
- $baud = 9600
- $eeprom
- '****************************************************************
- 'Debug Off
- Debug On
- Const Max_nex_command_len = 50
- '-------------------------------------------------------------------------------------------
- '****************************************************************
- $projecttime = 127
- $version 0 , 0 , 154
- Config Submode = New
- Config Watchdog = 2048
- Enable Interrupts
- '****************************************************************
- '* CONFIG BUFFERED USART FOR DEBUG via USB *
- '****************************************************************
- Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
- Config Serialin0 = Buffered , Size = 100 'buforowoanie pierwszy uart
- Config Serialout0 = Buffered , Size = 100 'buforowoanie pierwszy uart
- Echo Off
- Open "COM1:" For Binary As #1
- Const Debug_ = 1
- '****************************************************************
- '* CONFIG BUFFERED USART FOR RS485_1 FULL DUPLEX *
- '****************************************************************
- Config Com2 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
- Config Serialin1 = Buffered , Size = 100 'buforowoanie drugi uart
- Config Serialout1 = Buffered , Size = 100 'buforowoanie drugi uart
- Open "COM2:" For Binary As #2
- Const RS485_1 = 2
- '****************************************************************
- '* CONFIG BUFFERED USART FOR LCD *
- '****************************************************************
- 'Config Com3 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
- 'Config Serialin2 = Buffered , Size = 100 'buforowoanie trzeci uart
- 'Config Serialout2 = Buffered , Size = 100 'buforowoanie trzeci uart
- 'Dim Cmd_timeout As Byte
- 'Open "COM3:" For Binary As #3
- 'Const Nex = 3
- '-------------------------------------------------------------------------------------------
- Config Com3 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 'Asynchroneous
- Dim Cmd_timeout As Byte , Got_str As Byte
- 'unnecessary
- Dim Command As String * Max_nex_command_len
- Config Serialin2 = Buffered , Size = Max_nex_command_len 'RX
- 'Config Serialout6 = Buffered , Size = 128
- Open "COM3:" For Binary As #3
- Const Nex = 3
- '****************************************************************
- '* CONFIG BUFFERED USART DEBUG *
- '****************************************************************
- Config Com4 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
- Config Serialin3 = Buffered , Size = 100 'buforowoanie czwarty uart
- Config Serialout3 = Buffered , Size = 100 'buforowoanie czwarty uart
- Open "COM4:" For Binary As #4
- Const Usb = 4
- '****************************************************************
- ' KONFIGURACJA TIMERA CONFIG TIMER'S *
- '****************************************************************
- Config Timer1 = Timer , Prescale = 8
- On Timer1 Przertimer1
- Enable Timer1
- Config Timer2 = Pwm , Compare_a_pwm = Clear_up , Prescale = 1024
- Enable timer2
- Enable Interrupts
- '****************************************************************
- '****************************************************************
- ' BIBLIOTEKI LIBRARY *
- '****************************************************************
- $lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
- '****************************************************************
- ' PODPROGRAMY INCLUD PROGRAMS *
- '****************************************************************
- $include "subs\clock.inc"
- $include "subs\Setdate.inc"
- $include "subs\Settime.inc"
- $include "subs\mruganie.inc"
- $include "subs\Uartrx0.inc"
- '****************************************************************
- '##########################################################
- ' ZMIENNE #
- '##########################################################
- ' ZMIENNE CZASU #
- '##########################################################
- Dim Timer_tikx10 As Byte 'zmienna liczaca przepełnienie timera
- Dim Timertikx100 As Byte 'zmienna liczaca przepełnienie timera x10
- Dim Timertikx200 As Byte 'zmienna liczaca przepełnienie timera x 20
- Dim Timertikx500 As Byte 'zmienna liczaca przepełnienie timera x 50
- Dim Timer_tik_flag As Byte
- Flaga10ms Alias Timer_tik_flag.0
- Flaga100ms Alias Timer_tik_flag.1
- Flaga500ms Alias Timer_tik_flag.2
- Flaga1s Alias Timer_tik_flag.3
- Flaga2s Alias Timer_tik_flag.4
- 'zostaly jeszce trzy wolne flagi
- ' a uzylem tylko jednego bajtu
- 'Pawer SP9DR
- '##########################################################
- ' ZMIENNE POBIERANIA CZASU I DATY DS3231 #
- '##########################################################
- Dim Sekundy As Byte
- Dim New_Sekundy As Byte
- Dim Minuty As Byte
- Dim New_Minuty As Byte
- Dim Godziny As Byte
- Dim New_Godziny As Byte
- Dim Dni As Byte
- Dim New_Dni As Byte
- Dim Dzien As Byte
- Dim New_Dzien As Byte
- Dim Miesiac As Byte
- Dim New_Miesiac As Byte
- Dim Rok As Byte
- Dim New_Rok As Byte
- Dim Sekundystr As String * 2
- Dim Minutystr As String * 2
- Dim Godzinystr As String * 2
- Dim Dzienstr As String * 2
- Dim Miesiacstr As String * 2
- Dim Rokstr As String * 2
- '##########################################################
- ' By NiveaSoft #
- Dim I2c_err As Bit
- Dim Temp_sec As Byte
- Dim Temp_min As Byte
- Dim Temp_hour As Byte
- Dim Weekday As Byte
- Dim Temp_day As Byte
- Dim Temp_month As Byte
- Dim Temp_year As Byte
- '##########################################################
- ' ZMIENNE UARTRX0 #
- '########################################################## '
- Dim Lcount_0 As Byte
- Dim Uart_command_0 As String * 20 'musi byc wystarczjaco dlugie
- Dim Getcommands_0(10) As String * 10 'tablica na pociete komendy
- Dim Komenda As String * 10
- '##########################################################
- ' ZMIENNA SKANERA I2C #
- '##########################################################
- Dim B As Byte
- '##########################################################
- 'I2C CONFIG
- Config Clock = User
- Config Date = dmy , Separator = -
- '--------------------------------------------------------------------
- Const Bmp180_read = &HEF 'Bmp180 Read Address
- Const Bmp180_write = &HD0 'Bmp180 Write Address
- '--------------------------------------------------------------------
- '****************************************************************
- ' KONFIGURACJA PORTÓW CONFIG PORT *
- '****************************************************************
- Config portB.7 = Output : Set portb.7 : Led_Live Alias Portb.7
- Config Scl = PortD.0 ' used i2c pins
- Config Sda = PortD.1
- Config Twi = 400000 ' i2c speed
- Const Ds3231w = &HD0 'B11010000
- Const Ds3231r = &HD1 'B11010001
- I2cinit
- '****************************************************************
- Print "Scan start I2C"
- Wait 2
- For B = 0 To 254 Step 2
- I2cstart
- I2cwbyte B
- If Err = 0 Then
- Print "I2C Adresse = " ; B
- Print "I2C Hex Adresse= " ; Hex(B)
- Print "I2C Bin Adresse= " ; Bin(B)
- End If
- Next
- Print "End Scan I2C"
- Wait 2
- '****************************************************************
- Call clock
- waitms 250
- 'Print #Debug_ , Godzinystr ; ":" ; Minutystr ; ":" ; Sekundystr
- Print #Debug_ , Godziny ; ":" ; Minuty ; ":" ; Sekundy
- '****************************************************************
- Do
- 'Call clock
- '=====================================================
- If Timer_tikx10 >= 10 Then 'jeśli uplyneło 100ms to
- Flaga100ms = 1 'ustaw flage upłyneło 100ms
- Incr Timertikx100 'zwiększaj Timertikx100
- Timer_tikx10 = 0 'zeruj liczenie
- End If 'koniec warunku
- If Timertikx100 >= 10 Then 'jeśli uplynela sekunda
- Flaga1s = 1 'ustaw flage upłyneła sekunda
- Incr Timertikx200 'zwiększaj Timertikx200
- Incr Timertikx500
- Timertikx100 = 0 'zeruj liczenie
- End If 'koniec warunku
- If Timertikx500 >= 5 Then
- Flaga500ms = 1
- Timertikx500 = 0
- End If
- If Timertikx200 >= 2 Then 'jeśli upłyneły dwie sekundy
- Flaga2s = 1 'ustaw flagę upłyneły dwie sekundy
- Timertikx200 = 0 'zeruj liczenie
- End If 'koniec warunku
- '=====================================================
- If Flaga10ms = 1 Then 'jeśli Flaga10ms jest równa 1
- Flaga10ms = 0 'wyzeruj Flaga10ms
- End If 'koniec warunku
- '-------------------------------------------------------------------------------------------
- If Flaga100ms = 1 Then 'jeśli Flaga100ms jest równa 1
- Call clock
- Flaga100ms = 0 'wyzeruj Flaga100ms
- End If 'koniec warunku
- '-------------------------------------------------------------------------------------------
- If Flaga500ms = 1 Then 'jeśli Flaga500ms jest równa 1
- Flaga500ms = 0 'wyzeruj Flaga500ms
- End If 'koniec warunku
- '-------------------------------------------------------------------------------------------
- If Flaga1s = 1 Then 'jeśli Flaga1s jest równa 1 ' 'wyzeruj Flaga1s
- 'Call clock
- Call Mruganie
- Print #Debug_ , "Czas " ; Godzinystr ; ":" ; Minutystr ; ":" ; Sekundystr
- Print #Debug_ , "Data " ; Dzienstr ; "/" ; Miesiacstr ; "/" ; Rokstr
- Flaga1s = 0
- End If 'koniec warunku
- '-------------------------------------------------------------------------------------------
- If Flaga2s = 1 Then 'jeśli Flaga2s jest równa 1
- Flaga2s = 0 'wyzeruj Flaga
- End If 'koniec warunku
- '****************************************************************
- 'ODBIÓR DANYCH UART0
- If Ischarwaiting(#DEBUG_) > 0 Then 'calls _gotchar and use URXC
- Lcount_0 = Inkey(#DEBUG_) 'pobierz znak z bufora
- If Lcount_0 = 13 Or Len(uart_command_0) > 20 Then '20 Then ' jeslii ENTER lub wiecej niz 20 znaków to call uartrx
- Call Uartrx0()
- 'Print #Debug_ , Prompt 'wywołaj podprogram Uartrx1
- 'Debug "czyszczenie bufora po odebranje komendzie" 'Using a constant will let us change the prompt
- 'clear serialin 'nie sprawdzone
- Uart_command_0 = "" ' koniecznie potrzenbe do czysczenia bufora
- Else 'inaczej
- Uart_command_0 = Uart_command_0 + Chr(Lcount_0) 'kluczowe budowanie bufora
- End If 'koniec warunku
- End If 'koniec warunku
- '****************************************************************
- Loop
- End
- '-------------------------------------------------------------------------------------------
- ' podprogram przerwań Timer1
- Przertimer1:
- Timer1 = 45536 'wstawienie do Timer1 wartości 45536
- Incr Timer_tikx10
- If Timer_tikx10 = 1 Then
- Set Flaga10ms
- End If
- Return 'powrót
- '-------------------------------------------------------------------------------------------
- $nocompile
- 'odbiór danych z uart0 DEBUG_
- Sub Uartrx0
- Lcount_0 = Split(uart_command_0 , Getcommands_0(1) , ",")
- Debug #Debug_ , "lcount_0= " ; Lcount_0
- Debug #Debug_ , "debug uart_command_0= " ; Uart_command_0
- Debug #Debug_ , "****************************"
- Debug #Debug_ , "debug Getcommands_0(1)=" ; Getcommands_0(1)
- Debug #Debug_ , "debug Getcommands_0(2)=" ; Getcommands_0(2)
- Debug #Debug_ , "debug Getcommands_0(3)=" ; Getcommands_0(3)
- Debug #Debug_ , "debug Getcommands_0(4)=" ; Getcommands_0(4)
- 'Debug #Debug_ , "debug Getcommands_1(5)=" ; Getcommands_1(5)
- Debug #Debug_ , "****************************"
- Komenda = Getcommands_0(1)
- If Komenda = "set_time" Then
- New_Godziny = Val(Getcommands_0(2))
- New_Minuty = Val(Getcommands_0(3))
- New_Sekundy = Val(Getcommands_0(4))
- Call Settime
- Debug #Debug_ , "System Reboot "
- Start Watchdog
- do
- loop
- Debug #Debug_ , "Komenda " ; Komenda
- Debug #Debug_ , "New_Godziny " ; Godziny
- Debug #Debug_ , "New_Minuty " ; Minuty
- Debug #Debug_ , "New_Sekundy " ; Sekundy
- ElseIf Komenda = "set_date" Then
- New_Dzien = Val(Getcommands_0(2))
- New_Miesiac = Val(Getcommands_0(3))
- New_Rok = Val(Getcommands_0(4))
- Call Setdate
- Debug #Debug_ , "System Reboot "
- Start Watchdog
- do
- loop
- Debug #Debug_ , "Komenda " ; Komenda
- Debug #Debug_ , "New_Dzien " ; New_Dzien
- Debug #Debug_ , "New_Miesiac " ; New_Miesiac
- Debug #Debug_ , "New_Rok " ; New_Rok
- Debug #Debug_ , "******************************"
- Debug #Debug_ , "Dzien " ; Dzien
- Debug #Debug_ , "Miesiac " ; Miesiac
- Debug #Debug_ , "Rok " ; Rok
- End If
- End Sub
pozdrawiam Jacek.