Listing KlokDS1307_Alberto4 '**************************************************************** '* Name : KlokDS1307.BAS * '* Author : Henk Timmerman * '* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 18-01-2023 * '* Version : 1.0 * '* Notes : PIC 16F628A met klok DS1307 (Alberto3) * '**************************************************************** DEVICE = 16F628A CONFIG FOSC_HS, WDTE_OFF, PWRTE_ON, MCLRE_OFF, BOREN_ON, LVP_OFF, CPD_OFF, CP_OFF '------------------------------------------------------------------------------- DECLARE ALL_DIGITAL = True 'Allle ingangen digitaal DECLARE XTAL = 20 'Kristal 20 MHz DECLARE LCD_DTPIN = PORTB.4 ' LCD's Data lines (D4 to D7) DECLARE LCD_ENPIN = PORTA.3 ' LCD's EN line DECLARE LCD_RSPIN = PORTA.2 ' LCD's RS line DECLARE LCD_INTERFACE = 4 ' 4-bit interface to LCD DECLARE LCD_LINES = 2 ' LCD contains 2 lines DECLARE LCD_DATAUS = 50 ' Time to wait after print a data To LCD DECLARE LCD_COMMANDUS = 2000 ' Time to wait after print a command to LCD DECLARE LCD_TYPE = ALPHANUMERIC ' LCD type is alphanumeric SYMBOL LED = PORTB.3 'led licht na opstarten 0,5 sec op '/ PORTA.5 is only input. '/------------------------------------------------------------------------- '' Declare PORTB_Pullups On It is not necessary!!! Can cause problem for LCD. ;Logische constanten $DEFINE DS1307_SCL_Pin PORTA.0 'clock signaal voor DS1307 $DEFINE DS1307_SDA_Pin PORTA.1 'data signaal voor DS1307 INCLUDE "C:\PICPROGRAMMAS\DS1307.inc" ;Variabelen declareren ;Byte DIM Sec AS BYTE DIM Min AS BYTE DIM Uur AS BYTE DIM Dag AS BYTE DIM Datum AS BYTE DIM Maand AS BYTE DIM Jaar AS BYTE '******************************************************************************* VRCON = 0 CMCON = 7 '/ Already written by the compiler. CLS '/ At the top of main code. Necessary to configure the LCD. '/ Don't declare all pins. Make only pin to pin because you connect the LCD '/ in several PORTS '/ These lines delete the configuration of the LCD (BECAUSE THE FAULT) OUTPUT LED '/ Pin LED at output '/ Declare PORTB_Pullups On Misplaced. '/ It is not necessary to use the CLEAR. LED = 1 DELAYMS 500 LED = 0 'Register instellen DS1307_WriteRegister($07, %00010010); adres $07 bit1=1 en bit0=0, SQW=8.192 kHz OK DELAYUS 50 'Datum instellen Friday, 5 of May 2023 DS1307_WriteDate(4, 5, 5, 23); 1-dag van de week (1..7), 2-dag (0..31), 3-maand (1..12), 4-jaar (0..99) DELAYUS 50 'Tijd instellen ' 21H15 DS1307_WriteTime(21, 15, 10); Uur (0..23), Minuut (0..59), Seconde (0..59) DELAYUS 50 WHILE 1=1 'Tijd lezen DS1307_ReadTime() ;RTC_Second (0..59), RTC_Minute (0..59), RTC_Hour (0..23) Uur = RTC_Hour Min = RTC_Minute Sec = RTC_Second 'Datum lezen DS1307_ReadDate() ;RTC_DayOfWeek (1..7), RTC_Day (0..31), RTC_Month (1..12), RTC_Year (0..99) Datum = RTC_Day Maand = RTC_Month Jaar = RTC_Year 'Cls USING PRINT AT .... IT IS NOT NECESSARY TO WRITE CLS. PRINT AT 1,1,"TIME: ",DEC2 Uur, ":", DEC2 Min, ":", DEC2 Sec ' resultaat 00? PRINT AT 2,1,"DATE: ",DEC2 Datum, ":", DEC2 Maand, ":", DEC2 Jaar ' resultaat 00? DELAYMS 998 WEND END