avatar_ete

Alarm Saat (picbasic pro, pic16f877, pcf8583)

Başlatan ete, 28 Ağustos 2011, 14:02:42

ete

Pls. explain what is wrong on the year may be I can find a solution.

Ete

Cesar35

#16
Hello Good morning here the video
https://www.youtube.com/watch?v=tsfJUmR07P0

ete

Cesar,
The program is working right. Most probably you use different program having an error on year calculation. Pls.put your program here to inspect.

Ete

Cesar35

#18
AQUIVOS

ete

Cesar,
The error is on the communication pins of PCF8583,
Pls check the following pins over the circuit or PCB.
SCL pin of PCF8583, should be connected to the PORTB.0
SDA pin of PCF 8583 should be connected to the PORTB.1

I look to the program and see them as follows,
Symbol SCL=PORTB.1
SYMBOL SDA=PORTB.0 
this is wrong should be,
Symbol SCL=PORTB.0
SYMBOL SDA=PORTB.1

Ete

Cesar35

#20
 Hello Good morning I had already done this fix two pins Portb.0 and Portb1 . I'll send another video When I press the Set button and release it already changes the Year Thank you for helping me. Peace

If I get stoned he jumps for the right year just the yes

One thing I noticed and when I squeeze the gate set the year keeps jumping at 17 out of 17 number. Examples 22 it jumps to 38.from 38 it jumps to 54.from to 70, from to 86.from to 07.from to 18.from to 34.from to 50.from to 66.from to 82 etc..


https://www.youtube.com/watch?v=DnqAkZQ0RUk

ete

Cesar,

You use different program and you give us another program to check. I need to look your program.
I look to the video in the setup mode the [00] section is flashing and buttons are giving also beep. Normaly these fonctions are not exist in the program you give us to check.
There is something wrong but in your program not the program in this site.
The difference is always 16 something is adding 16 when you increase the YEAR value.
This PCF8583 is old RTC and can not keep the year value. It keeps 2 bit value for the year and you have to add the difference. The year value is kept on date (day of the month) register in 6 and 7 bits. As you know two bits can keep only the figures 0-3 . For that reason there is a litle bit complicated calculation in the program for keeping year value. The masteer part of the year is kept on eeprom adress-0 this is TAMYIL (means full year) . On the screen you can see the year for instance as 22 is (TAMYIL+Y_YIL) Y_YIL is the value you change. For to show 22 we use TAMYIL=20 and Y_YIL=2 all together you see 22. On this organisation the value of 2 is kept in PCF8583 as the year and the value of 20 is kept in eeprom as TAMYIL.
There is soemthing wrong in your program on year arrangement.
The year arangement is done on following lines;
YEAR:  IF MODE=0 THEN GUNA
       IF SET=0 THEN SONA
       
       IF UP=0 THEN
       Y_YIL=Y_YIL+1    
       IF Y_YIL=100 THEN  Y_YIL=0
       ENDIF            
       
       IF DOWN=0 THEN
       Y_YIL=Y_YIL-1    
       IF Y_YIL=0 THEN  Y_YIL=99
       ENDIF 
       
       GOSUB EKRAN1:LCDOUT $FE,$C7
       PAUSE SURE 
       GOTO YEAR
You see you increase 1 by 1 the value of Y_YIL . EKRAN1 sub program is showing the vaule as follows,
LCDOUT $FE,192,dec2(Y_GUN),"-",dec2(Y_AY),"-",dec2(Y_YIL+TAMYIL),$FE,$0E
When you finish and came to the SAVE (KAYIT) section, program is re-calculating the value (Y_YIL) which will be written to the PCF8583 and also the value of the TAMYIL.
 TEMP=Y_YIL+TAMYIL  
       TAMYIL=4*(TEMP/4 ) 
       Y_YIL=TEMP-TAMYIL  
       WRITE 0,TAMYIL     

Finally when you read the time form PCF, you read the day of the month and take the year value from it as follows,
      YIL.1=GUN.7
      YIL.0=GUN.6
      IF ESKYIL=3 AND YIL=0 THEN
      TAMYIL=TAMYIL+4
      WRITE 0,TAMYIL
      ENDIF 

This system can work without any problem. I used this system in some projects about 15 years ago.
Today I use DS3231 as RTC which is much much better than PCF. First of all it has inside crystal and no need to connect any crystal to it. Most important thing is the type of the crystal. It is TCO type (Temperature Compensated Ocillator) and having only +/- 2 ppm tollerance. I have some clocks working since 5 years I never touch the clocks they work properly and precision.

Ete

Cesar35

#22
I'm sorry for insisting on this project. Here is my program.

'****************************************************************
'*  Name    : ALARM-SAAT.BAS                                      *
'*  Author  : [Erol Tahir Erdal]                                *
'*  Notice  : Copyright (c) 2005 [ETE]                          *
'*          : All Rights Reserved                              *
'*  Date    : 11.05.2005                                        *
'*  Version : 1.0                                              *
'*  Notes  :                                                  *
'*          :                                                  *
'****************************************************************
#header
  errorlevel -306  ; Crossing page boundry
#ENDHEADER
'__________________SÝGORTA AYARLARIM_____________________________
#CONFIG
  __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF & _BODEN_OFF
#ENDCONFIG
'------------------------------------------------------------------------------
DEFINE LCD_DREG PORTB      'LCD data bacaklarý hangi porta baðlý? 
DEFINE LCD_DBIT 4          'LCD data bacaklarý hangi bitten baþlýyor? 
DEFINE LCD_EREG PORTB      'LCD Enable Bacaðý Hangi Porta baðlý? 
DEFINE LCD_EBIT 3          'LCD Enable Bacaðý Hangi bite baðlý ? 
DEFINE LCD_RSREG PORTB    'LCD RS Bacaðý Hangi Porta baðlý ? 
DEFINE LCD_RSBIT 2        'LCD RS bacaðý Hangi Bite baðlý ? 
DEFINE LCD_BITS 4          'LCD 4 bit mi yoksa 8 bit olarak baðlý? 
DEFINE LCD_LINES 2        'LCD Kaç sýra yazabiliyor 
'------------------------------------------------------------------------------
Define OSC 10
ADCON1=7          'ADC GÝRÝÞLERÝ DÝGÝTAL 
OPTION_REG.7=1    'Dahili pull-up lar iptal edildi
PortA=0
TrisA=%01111111
PortB=0
TrisB=%00000010
PORTC=0

'------------------------------------------------------------------------------
SYMBOL SET=PORTA.0
SYMBOL MODE=PORTA.1

SYMBOL DOWN=PORTA.2
SYMBOL UP=PORTA.3

Symbol SCL=PORTB.1
SYMBOL SDA=PORTB.0

SIMDI  VAR  WORD
ZAMAN  VAR  WORD
SN    var  byte
Y_SN  VAR  BYTE
DAK    var  byte
Y_DAK  VAR  BYTE
ESKIDAK VAR BYTE
SAAT  var  byte
Y_SAAT VAR  BYTE
GUN    VAR  BYTE
Y_GUN  VAR  BYTE
HGUN  VAR  BYTE  'HAFTANIN GÜNÜ
Y_HGUN var  byte
AY    var  byte
Y_AY  VAR  BYTE
YIL    var  BYTE
Y_YIL  VAR  BYTE
ESKYIL VAR  BYTE
TAMYIL var  BYTE
TEMP  VAR  BYTE
ARA    VAR  BYTE
ONLAR  VAR  BYTE
BIRLER VAR  BYTE
SURE  VAR  BYTE
SIRA  VAR  BYTE
YER    VAR  BYTE
AKTIFA VAR  BYTE
AKTIFB VAR  BYTE
'------------------------------------------------------------------------------
LCDOUT $FE,$68,$0E,$11,$10,$10,$10,$15,$0E,$4  'Ç datalarý Numarasý 5
LCDOUT $FE,$70,$00,$0E,$10,$0E,$02,$1C,$0C,$00  'þ datalarý NUMARSI 6 DÝR
LCDOUT $FE,$78,$0,$0,$0C,$4,$4,$4,$e,$0        'ý datalarý NUMARSI 7 DÝR

lcdout $FE,1
PAUSE 200
SURE=180 

READ 0,TAMYIL
IF TAMYIL=255 THEN
  TAMYIL=4
  WRITE 0,TAMYIL
ENDIF  

READ 2,SIRA
IF SIRA=255 THEN
SIRA=1:WRITE 2,SIRA
ENDIF 

Y_SN=0
rEAD 5,AKTIFA
READ 6,AKTIFB

IF AKTIFA=255 THEN
  AKTIFA=0:WRITE 5,AKTIFA:PAUSE 10
ENDIF

'IF AKTIFB=255 THEN
'  AKTIFB=0:WRITE 6,AKTIFB:PAUSE 10
'ENDIF      
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------

BASLA: 'PAUSE 100
      GOSUB SAAT_OKU
      GOSUB EKRAN
      PAUSE 250
      IF SET = 0 THEN AYAR
      IF (ESKIDAK=DAK) THEN TEKRAR
      ESKIDAK=DAK
      GOSUB ALARM_KONTROL
      PORTC=AKTIFB
TEKRAR:
      GOTO BASLA
      
'-------------------------ALT PROGRAMLAR---------------------------------------
AYAR:  YER=0
      lcdout $FE,$0E
      GOSUB SAAT_OKU
      Y_DAK=DAK
      Y_SAAT=SAAT
      Y_GUN =GUN
      Y_HGUN=HGUN
      Y_AY  =AY
      Y_YIL =YIL
      GOSUB EKRAN1
      WHILE SET = 0 
      WEND
      PAUSE SURE

SIRA_BELIRLE:
      IF MODE = 0 THEN HOURA
      IF SET = 0 THEN SONA
      
      IF UP=0 THEN
      YER=YER+1
      IF YER=15 THEN YER=14
      ENDIF
      
      IF DOWN=0 THEN
      YER=YER-1
      IF YER=255 THEN YER=0      'ORDEM=0 SE O TEMPO REAL FOR REGISTRADO PARA 8583
      ENDIF
      
      IF YER>0 THEN GOSUB ALARM_OKU
      GOSUB EKRAN1:LCDOUT $FE,$82 'SIRA>0 ÝSE ALARM EEPROME KAYIT EDÝLECEK.
      PAUSE SURE
      GOTO SIRA_BELIRLE
        
HOURA: WHILE MODE=0
      WEND
HOUR:
      IF MODE=0 THEN MINA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_SAAT=Y_SAAT+1
      IF Y_SAAT=24 THEN Y_SAAT=0
      ENDIF        
      
      IF DOWN=0 THEN
      Y_SAAT=Y_SAAT-1
      IF Y_SAAT=255 THEN Y_SAAT=23
      ENDIF
      
      GOSUB EKRAN1:LCDOUT $FE,$86
      PAUSE SURE
      GOTO HOUR

MINA:  WHILE MODE=0
      WEND
            
MINUTE:IF MODE=0 THEN TAKA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_DAK=Y_DAK+1    
      IF Y_DAK=60 THEN  Y_DAK=0
      ENDIF 
      
      IF DOWN=0 THEN
      Y_DAK=Y_DAK-1
      IF Y_DAK=255 THEN Y_DAK=59
      ENDIF 
      
      GOSUB EKRAN1:LCDOUT $FE,$89
      PAUSE SURE
      GOTO MINUTE 

TAKA:  WHILE MODE=0
      WEND
TAKVIM:
      IF MODE=0 THEN AYA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_GUN=Y_GUN+1    
      IF Y_GUN=32 THEN  Y_GUN=1
      ENDIF            
      
      IF DOWN=0 THEN
      Y_GUN=Y_GUN-1    
      IF Y_GUN=0 THEN  Y_GUN=31
      ENDIF 
      
      GOSUB EKRAN1:LCDOUT $FE,$C1
      PAUSE SURE 
      GOTO TAKVIM

AYA:  WHILE MODE=0
      WEND
MONTH:      
      IF MODE=0 THEN YILA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_AY=Y_AY+1    
      IF Y_AY=13 THEN  Y_AY=1
      ENDIF            
      
      IF DOWN=0 THEN
      Y_AY=Y_AY-1    
      IF Y_AY=0 THEN  Y_AY=12
      ENDIF 
      
      GOSUB EKRAN1:LCDOUT $FE,$C4
      PAUSE SURE 
      GOTO MONTH

YILA:  WHILE MODE=0
      WEND
YEAR:  IF MODE=0 THEN GUNA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_YIL=Y_YIL+1    
      IF Y_YIL=100 THEN  Y_YIL=0
      ENDIF            
      
      IF DOWN=0 THEN
      Y_YIL=Y_YIL-1    
      IF Y_YIL=0 THEN  Y_YIL=99
      ENDIF 
      
      GOSUB EKRAN1:LCDOUT $FE,$C7
      PAUSE SURE 
      GOTO YEAR

GUNA: WHILE MODE=0
      WEND
HAFGUN:IF MODE=0 THEN SONA
      IF SET=0 THEN SONA
      
      IF UP=0 THEN
      Y_HGUN=Y_HGUN+1    
      IF Y_HGUN=7 THEN  Y_HGUN=0
      ENDIF            
      
      iF DOWN=0 THEN
      Y_HGUN=Y_HGUN-1    
      IF Y_HGUN=255 THEN  Y_HGUN=6
      ENDIF 
      
      GOSUB EKRAN1:LCDOUT $FE,$CA
      PAUSE SURE 
      GOTO HAFGUN

SONA:IF YER=0 THEN KAYIT
      GOSUB ALARM_KAYIT
      GOTO BASLA    
'-------------------------------------------------------------------------------
EKRAN: LCDOUT $FE,2,"    "
      LCDOUT DEC2(SAAT),":",DEC2(DAK),":", dec2(SN)
      LCDOUT $FE,192,dec2(GUN),"-",dec2(AY),"-",dec2(YIL+TAMYIL) 
      ARA=HGUN 

DORT: select case ARA
      case 0
      lcdout $fe,$c9,"[DOM]"
      case 1
      lcdout $fe,$c9,"[SEG]"                          
      case 2
      lcdout $fe,$c9,"[TER]"
      case 3
      lcdout $fe,$c9,"[QUA]"
      case 4
      lcdout $fe,$c9,"[QUI]"
      case 5
      lcdout $fe,$c9,"[SEX]"
      case 6
      lcdout $fe,$c9,"[SAB]"
      end select      
      RETURN            

EKRAN1: 'BU EKRAN SAAT AYARINDA KULLANILAN ÝLK EKRAN
      LCDOUT $FE,$0C,$FE,2,"[",dec2 YER,"] "
      LCDOUT DEC2(Y_SAAT),":",DEC2(Y_DAK),":", DEC2(SN)
      LCDOUT $FE,192,dec2(Y_GUN),"-",dec2(Y_AY),"-",dec2(Y_YIL+TAMYIL) ,$FE,$0E
      ARA=Y_HGUN
      GOTO DORT

'-------------------------------------------------------------------------------
KAYIT:WHILE set=0
      wend    
      LCDOUT $FE,$0C    'REG_2  'SANIYE <0:5>
      TEMP=Y_YIL+TAMYIL  'REG_3  'DAKÝKA <0:5>
      TAMYIL=4*(TEMP/4 ) 'REG_4  'SAAT  <0:5>
      Y_YIL=TEMP-TAMYIL  'REG_5  'GUN    <0:5> ; YIL  <6:7>  
      WRITE 0,TAMYIL    'REG_6  'AY    <0:4> ; HAFTANIN GUNU <5:7>      
                                                            
DAKHESAP:
      TEMP=Y_DAK:GOSUB HESAP
      Y_DAK=ONLAR+BIRLER
      
SAATHESAP:
      TEMP=Y_SAAT:GOSUB HESAP
      Y_SAAT=ONLAR+BIRLER
      IF TEMP>12 THEN Y_SAAT.6=1
      
GUNHESAP:
      TEMP=Y_GUN:GOSUB HESAP
      Y_YIL=Y_YIL<<6
      Y_GUN=Y_YIL+ONLAR+BIRLER
      
AYHESAP:
      TEMP=Y_AY:GOSUB HESAP
      Y_HGUN=Y_HGUN<<5
      Y_AY=Y_HGUN + ONLAR + BIRLER
                          
      I2CWRITE SDA,SCL,160,2,[Y_SN,Y_DAK,Y_SAAT,Y_GUN,Y_AY]
      GOSUB SAAT_OKU 
      lcdout $fe,1
      GOTO BASLA
HESAP:
      ARA=(TEMP/10)
      ONLAR=ARA<<4
      BIRLER=TEMP-(ara*10)
      RETURN
'-------------------------------------------------------------------------------      
SAAT_OKU:ESKYIL=YIL
      I2CREAD SDA,SCL,161,2,[SN,DAK,SAAT,GUN,AY]
      YIL.1=GUN.7
      YIL.0=GUN.6
      IF ESKYIL=3 AND YIL=0 THEN
      TAMYIL=TAMYIL+4
      WRITE 0,TAMYIL
      ENDIF  
      TEMP=AY
      HGUN=TEMP>>5
      SN=SN&%00111111
      TEMP=DAK:gosub BUL:DAK=TEMP
      TEMP=SAAT&%00111111:GOSUB BUL:SAAT=TEMP
      TEMP=GUN&%00111111:GOSUB CEVIR:GUN=TEMP
      TEMP=AY&%00011111:GOSUB IKI:AY=TEMP
      RETURN 

CEVIR:
      ONLAR=TEMP & 48
UC:    ONLAR=(ONLAR>>4)*10          
BIR:  BIRLER=TEMP & %1111
      TEMP=ONLAR+BIRLER
      RETURN
BUL:ONLAR=(TEMP>>4)*10
      GOTO BIR      
IKI:  ONLAR=ay & 16      
      GOTO UC

'------------------LIGAR O ALARME & PORTC---------------------------------------
ALARM_KONTROL:  
      SIMDI=YIL+AY+GUN+SAAT+DAK
      YER=1
      GOSUB ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00000001  
      YER=2
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00000010 
      YER=3  
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00000100
      YER=4
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00001000
      YER=5
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00010000
      YER=6
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %00100000
      YER=7
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %01000000

'--------------------DESLIGAR O ALARME & PORTC----------------------------------      
      YER=8
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC | %11111110    
      YER=09
      GOSUB ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %11111101
      YER=10
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %11111011  
      YER=11  
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %11110111
      YER=12
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %11101111
      YER=13
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %11011111
      YER=14
      gosub ALARM_OKU
      IF SIMDI=ZAMAN THEN PORTC=PORTC & %10111111
      IF (PORTC=AKTIFA)THEN CIK
      AKTIFA=PORTC
      WRITE 5,AKTIFA:PAUSE 10
CIK:  RETURN  

ALARM_KAYIT:
    IF YER>SIRA THEN
    WRITE 2,YER:PAUSE 10
    ENDIF
    temp=yer*8 
    WRITE TEMP,Y_SAAT:PAUSE 10
    WRITE TEMP+1,Y_DAK:PAUSE 10
    WRITE TEMP+2,Y_GUN:PAUSE 10
    WRITE TEMP+3,Y_AY :PAUSE 10
    WRITE TEMP+4,Y_YIL:PAUSE 10
    RETURN

ALARM_OKU:
    temp=yer*8
    READ TEMP,Y_SAAT:IF Y_SAAT>23 THEN Y_sAAT=0
    READ TEMP+1,Y_DAK:IF Y_DAK>59 THEN Y_DAK=0
    READ TEMP+2,Y_GUN:IF Y_GUN>31 THEN y_GUN=1
    READ TEMP+3,Y_AY :IF Y_AY>12 THEN Y_AY=1
    READ TEMP+4,Y_YIL:IF Y_YIL>99 THEN Y_YIL=0
    ZAMAN=Y_YIL+Y_AY+Y_GUN+Y_SAAT+Y_DAK
    RETURN
    end  
   

ete

#23
Cesar,

Symbol SCL=PORTB.1
SYMBOL SDA=PORTB.0
these are still wrong if you use the same schema (my schema).
I told you they will be as follows,
Symbol SCL=PORTB.0
SYMBOL SDA=PORTB.1

I checked all the program there is not any other mistake. It is working in simulation and your circuit must also work. You have to check your hardware. I have nothing to do more.


Ete

Cesar35

Hello my teacher, how are you?
Coming back to this clock project everything is working fine.
I just have one problem I can't cancel the triggered alames
I followed your manual with do not work.
----------------------------------------------------------------------------------------------------------
One-touch alarm cancellation: If there is an open alarm, pressing one of the Raise or Lower buttons on the normal watch screen turns off open alarms.
if you help me i will be very grateful
Caesar

Cesar35

Alarmların Tek Tuşla İptal Edilmesi: Açılmış alarm var ise normal saat ekranında, Arttır ya da azalt tuşlarından birine basılması açık olan alarmları kapatır.

ete

Change the lines from the label of "BASLA" until "TEKRAR" as follows,
BASLA: 
      GOSUB SAAT_OKU
      GOSUB EKRAN
      PAUSE 250
      IF SET = 0 THEN AYAR
      IF UP=0 OR DOWN=0 THEN
        AKTIFA=0:PORTC=0
      ENDIF  
      IF (ESKIDAK=DAK) THEN TEKRAR
      ESKIDAK=DAK
      GOSUB ALARM_KONTROL
      PORTC=AKTIFA
TEKRAR:
      GOTO BASLA
I added following command lines;
IF UP=0 OR DOWN=0 THEN
        AKTIFA=0:PORTC=0
      ENDIF
This lines close the open alarms and clear the AKTIFA variable and PORTC also. But do not cancel the alarms totally. The alarm still wait in the eeprom and when the time is arrived the alarm will be activated again.
I checked already it is not so easy to cancel all the alarms I can do delete all the alarms and clear the eeprom but I do not know if you want that or not.

Ete

Cesar35

HEY HOW IS EVERYTHING
AND HOW YOU SAID
IT STAYS IN EEPROM.
HOW TO DELETE EVERYTHING FROM EEPROM
THANKS

ete

Instead of above mentioned lines add the following lines there in order to delete everything for the alarms.
      IF UP=0 OR DOWN=0 THEN
        AKTIFA=0:PORTC=0:SIRA=0
        Y_SAAT=0:Y_DAK=0:Y_AY=0:Y_GUN=0:Y_YIL=0
        for YER=1 to 14
          GOSUB ALARM_KAYIT
        NEXT
        YER=1:WRITE 2,YER:PAUSE 10 
        WRITE 5,AKTIFA:PAUSE 10       
      ENDIF

Ete

Cesar35

THANK YOU SO MUCH
MY FRIEND
I WILL TEST HERE
THANK YOU FROM HEART

Powered by EzPortal