DCF77 ile saat yapan varmı ?

Başlatan AYKIRI, 11 Eylül 2013, 21:54:21

AYKIRI

merhaba arkadaşlar
dcf77 modülü kullanarak saat yapmak istiyorum fakat uzman arkadaşlardan fikirlerini almak istiyorum
arama yaptığımda daha önce benzer konular işlenmiş fakat hiç denenmemiş
sorularımda yardımcı olacak arkadaşlara şimdiden teşekkürler

1.) istanbuldan sinyal alındığı söyleniyor kapalı alan yada açık alan farkediyormu ?
2.) dcf77 modülünü istanbulda satan biryer varmı ? yada en kolay ulaşım imkanı nedir ?

saat çalışsada çalışmasada ben bunu deneyeceğim arkadaşlar.
şuan bir kaç arkadaşın aklına şu sorular gelebilir " ne gereği var ? GPS var internet var ne diye radyo sinyali.." haklı olabilirsiniz ama ben bunu yinede deneyeceğim.

teşekkürler

AYKIRI

#1
yokmu önerisi olanlar ?
en azından bilen arkadaşlar dcf77 modülünü TRden nereden alabilirim onu söylerlerse çok sevinirim
almanyadan getirtmek ne şekilde olabilir ?

edit: internetten sipariş ettim ingiltereden gelecek 10 günde gelir sanırım duruma göre yazacağım
selamlar

AYKIRI

modül geldi arkadaşlar şuan enerji verdim sinyal aldığını düşünüyorum gelişmelerle ilgili bilgilendirme yapacağım. eski rtcli saati modifiye edip dcf üzerinde çalışır hale getirmek için uğraşıyorum. bitince resim ve videolarını çekip koyarım
saygılar

cetinkaya

Benim de aklimda var bu proje sen yap senin örneklere Göre bende yaparim. Kaca aldin dcf modülünü?

AYKIRI

Alıntı yapılan: rck8942 - 19 Eylül 2013, 18:14:23
Benim de aklimda var bu proje sen yap senin örneklere Göre bende yaparim. Kaca aldin dcf modülünü?
shipping falan hepsi içinde 38 TL ye geldi ve 6 günde geldi

sadogan

Alıntı yapılan: AYKIRI - 19 Eylül 2013, 18:24:08
shipping falan hepsi içinde 38 TL ye geldi ve 6 günde geldi
Nerden aldınız link verebilirmisiniz ?


OptimusPrime

bu yöntemle yaptığımız saatlerin sapmasını ölçerdik. almanyada funkuhr olarak satılan saatlerden almıştık. kapsama alanının sınırlarına yakın olduğumuzdan (istanbul) ancak cam kenarlarında veya açık alanda cihaz senkron olabiliyordu...
https://donanimveyazilim.wordpress.com || Cihân-ârâ cihân içredir ârâyı bilmezler, O mâhîler ki deryâ içredir deryâyı bilmezler ||

AYKIRI

#8
1302 ile yaptığım saatin osilatörü kararlı çalışmadı günde 8 saniye ileri gidiyordu keyfimi kaçırdı o yüzden dcf ile saat yapıp onuda 1302 ile yedeklemeyi planlıyorum ama henüz dcfyi decode edecek sample kod bulamadım daha doğrusu bulduklarım işe yaramadı. aşağıdaki kodu 16f877a ya modifiye ettim ama çalışmadı data 1 ve 0 ledleri aynı anda yanıyor bu olmamalıydı . yardım bekliyorum

16f877a ve lcd 2x16 display  radio sinyal girişi c1

#include "18F2620.h"

#FUSES NOWDT                   //No Watch Dog Timer
#FUSES WDT128                  //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                      //High speed Osc (> 4mhz)
#FUSES NOPROTECT               //Code not protected from reading
#FUSES IESO                    //Internal External Switch Over mode enabled
#FUSES BROWNOUT                //Reset when brownout detected
#FUSES BORV21                  //Brownout reset at 2.1V
#FUSES PUT                     //Power Up Timer
#FUSES NOCPD                   //No EE protection
#FUSES STVREN                  //Stack full/underflow will cause reset
#FUSES NODEBUG                 //No Debug mode for ICD
#FUSES NOLVP                   //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                   //Program memory not write protected
#FUSES NOWRTD                  //Data EEPROM not write protected
#FUSES NOEBTR                  //Memory not protected from table reads
#FUSES NOCPB                   //No Boot Block code protection
#FUSES NOEBTRB                 //Boot block not protected from table reads
#FUSES NOWRTC                  //configuration not registers write protected
#FUSES NOWRTB                  //Boot block not write protected
#FUSES FCMEN                   //Fail-safe clock monitor enabled
//#FUSES XINST                   //Extended set extension and Indexed Addressing mode enabled
#FUSES NOPBADEN                //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC                 //Timer1 configured for low-power operation
#FUSES MCLR                    //Master Clear pin enabled

//------------------- FOR EASY ZERO DRIFT TIMER -------------------
#define FOSC                 20000000   // used for setup delay and calculate the zero drift timmer
#define DCF77TimerDepth      65536      // for 16 bit timer
#define DCF77TimerPrescaler  1          // for prescaler div by 1
//------------------- FOR EASY ZERO DRIFT TIMER -------------------
 
#use delay(clock=FOSC)



#define LCD_TX     PIN_C6
#define LCD_RX     PIN_C6
#define LCD_BAUD   4800

#define RADIO_PORT     PIN_C2   // input from DCF77 receiver
#define LED_Error      PIN_A2   // led indicating DCF77 error
#define LED_ZERO       PIN_A3   // led indicating a zero from DCF77
#define LED_ONE        PIN_A4   // led indicating a one from DCF77

#define RADIO_PORT_HIGH  input(RADIO_PORT)
#define RADIO_PORT_LOW  !input(RADIO_PORT)

#use RS232(baud=LCD_BAUD, xmit=LCD_TX , rcv=LCD_RX )

#define VT100LF      "%c[B", 27   // "%c%c",13,10
#define VT100CLS     "%c[2J", 27  //"%c",12
#define VT100HOME    "%c[H", 27

// --RTC--
#define RadioLength0         10    // not used - length of pulse for a zero
#define RadioLength1         15    // 150 ms minimum (normalement 160 minimum 200 tipicaly)
#define RadioLengthStart     100   // normaly, 1 sec then 100

#define RadioStartMinute     21    // position of first bit of minute in dcf77 scheme
#define RadioParityMinute    28    // same story for next element
#define RadioStartHeure      29    //    "
#define RadioParityHeure     35    //    "
#define RadioStartDay        36    //    "
#define RadioStartDayOfWeek  42    //    "
#define RadioStartMonth      45    //    "
#define RadioStartYear       50    //    "
#define RadioParity3         58    //    "

#define DCF77ValuesMinute     0    // element number is scheme
#define DCF77ValuesHour       2    // same story for next element
#define DCF77ValuesDay        4    //    "
#define DCF77ValuesDayOfWeek  5    //    "
#define DCF77ValuesMonth      6    //    "
#define DCF77ValuesYear       7    //    "

//------------------- FOR EASY ZERO DRIFT TIMER -------------------
#define DCF77InteruptTime    0.01   // sec
#define DCF77SetTimer   (int16)( DCF77TimerDepth * DCF77TimerPrescaler ) - (int16)( DCF77InteruptTime * (FOSC / 4) )
//------------------- FOR EASY ZERO DRIFT TIMER -------------------

// --------- GLOBAL DECLARATION --------------
int8       DCF77Bits[9] = {0} ;   // table for put all DCF77 bits for one cycle
int8 const DCF77BitWeight[8] = {1,2,4,8,10,20,40,80};
char const DOW[7][8] = { {"Mon\0"}, {"Tues\0"}, {"Wednes\0"}, {"Thurs\0"}, {"Fri\0"}, {"Satur\0"}, {"Sun\0"} } ;

                           // | 128 for set the bit 7  for indicate that it is a parity bit
int8 const DCF77Scheme[9]= { RadioStartMinute, RadioParityMinute | 128, RadioStartHeure, RadioParityHeure | 128,
                             RadioStartDay, RadioStartDayOfWeek, RadioStartMonth, RadioStartYear, RadioParity3 | 128 } ;                       
                             
int8       DCF77Values[9] = {0} ;
int8       DCF77Sec ;
int8       DCF77LastDate = 0 ;
short      DCF77TimeOk = false, DCF77CycleOK = false ;
int8       LastRadioTime = 0 ;
int8       DCF77Pulse = 0 ;                // lenght of pulse is hundredth (sec/100) of Sec
short      RadioBit , RadioParity ;
int8       DCF77BitNbr = 0, DCF77ByteNbr = 0 ;
short      RadioWaitStart = true, RadioWaitHight, RadioHightMesure ;
int8       heure = 0, Minute = 0, Seconde = 0 ;
int8       day = 0, dayOfWeek = 0, month = 0, year = 0 ;
int8       Sec100 ;
short      SecondeFlag = 0, MinuteFlag = 0 ;
short      RadioError = false ;


#int_timer0
void timer0_isr() {
//------------------- FOR EASY ZERO DRIFT TIMER -------------------
  set_Timer0( get_timer0() + DCF77SetTimer ); // for exactly 100 mSec
//------------------- FOR EASY ZERO DRIFT TIMER -------------------

  // -- autonomous clock --
  if (++Sec100 == 100) {
    Sec100 = 0 ;
    SecondeFlag = 1 ;
   
    if (++DCF77Sec == 60) DCF77Sec = 0 ; // count hundredth (1/100) of second  for DCF77
   
    if (++Seconde == 60) {            // hours
      Seconde = 0;
      MinuteFlag = 1;
      if (++Minute == 60) {           // hours
        Minute = 0 ;
        if (++heure == 24) heure = 0 ; // days
      }
    }
  }
  // --------------------

  if (++DCF77Pulse >= RadioLengthStart) {   //if low for at least 1 sec then start or error. Assume start
    RadioWaitStart = true ;
    RadioWaitHight = false ;
    RadioHightMesure = false ;
  }

  if (RadioWaitStart) { // wait for starting cycle. the length is at least 1 second
    if ( RADIO_PORT_HIGH ) {
      DCF77Pulse = 0 ; // reset if in high pulse ( after an error ) for mesure from start of zero     
    }
    if (DCF77Pulse >= RadioLengthStart) { // starting cycle
      RadioError = false ;
      output_high(LED_ZERO);   //
      output_high(LED_ONE);    // At start, the two led (one and zero) are blinking together
      DCF77Pulse =0 ;          // reset hundredth count
      RadioWaitStart = false ;
      RadioWaitHight = true ;  // past to next step wait for begin of hight pulse
      DCF77ByteNbr = 0 ;
      DCF77BitNbr = 0 ;
      DCF77Sec = 59 ;          // init secondes
    }
  }

  if (RadioWaitHight) { // wait for start of hight pulse
    if ( RADIO_PORT_HIGH ) {
      DCF77Pulse = 0 ;
      RadioWaitHight = false ;
      RadioHightMesure = true ;
      output_low(LED_ZERO);
      output_low(LED_ONE);
    }
  }

  if (RadioHightMesure) {   // mesure the lengh of higth pulse
    if ( RADIO_PORT_LOW ) { // end of high pulse, now DCF77Pulse contain the length of high pulse
      RadioBit = (DCF77Pulse >= RadioLength1) ;   // if DCF77 high pulse is greater than 160mS is 1 else is 0
      if ( DCF77Pulse > 25 || DCF77Pulse < 8 ) {  // if DCF77 high pulse is greater than 210mS or smaller 90mS then error
        RadioError = true ;
        RadioWaitStart = true ;                   // restart the waiting for start pulse (no signal for 1 sec)
      }

      DCF77Pulse = 0 ;                            // reset counter for pulse length
      bit_clear(DCF77Bits[DCF77ByteNbr],DCF77BitNbr); 
      DCF77Bits[DCF77ByteNbr] |= RadioBit<<DCF77BitNbr ;         // put bit into table

      if (++DCF77BitNbr == 8) {
        DCF77BitNbr = 0 ;
        ++DCF77ByteNbr ;
      }
      if (DCF77ByteNbr == 7 && DCF77BitNbr == 3) {  // if end of cycle (7*8) + 3 = 59
        RadioWaitStart = true ;
        DCF77CycleOK = true ;
      }
      RadioHightMesure = false ;
      RadioWaitHight = !RadioWaitStart  ;         // back to wait for next hight pulse if cycle not finished and no error

      // --- can be deleted --- juste for monitoring
      output_bit(LED_ZERO, !RadioBit ) ;         
      output_bit(LED_ONE,   RadioBit ) ;
      // ----------------------

    }
  }
}

#include <calcDCF77-8.c>


void StartTimer() {
  Sec100 = 0 ;
  set_Timer0( DCF77SetTimer );
  enable_interrupts(INT_TIMER0);
}

void StopTimer() {
  DISABLE_INTERRUPTS(INT_TIMER0);
}

int DCF77DateInt() { 
  return(DCF77Values[DCF77ValuesDay]+DCF77Values[DCF77ValuesMonth]+DCF77Values[DCF77ValuesYear]);
}

void fAffTime() {
  output_bit(LED_Error, RadioError);
  printf("\r");
  printf("%2u:%02u:%02u ", Heure , Minute, Seconde );
}

void fAffDate() {
    printf("\n\r");  // next line
    printf( "%sday", DOW[dayOfWeek-1] );
    printf(" %02u/%02u/%02u",  day,  month,  year  );
    DCF77LastDate = DCF77DateInt();
   
    printf(VT100HOME); // home
}


void main() {

  // --INIT RTC--
  set_timer0(0) ;
  setup_timer_0(RTCC_INTERNAL);
  setup_timer_2(T2_DIV_BY_16,196,16);
  // ------------

  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_CLOCK_DIV_2);
  setup_spi(FALSE);
  setup_timer_1(T1_DISABLED);
  setup_ccp1(CCP_OFF);
  setup_ccp2(CCP_OFF);

  delay_ms(100) ;


  printf(VT100CLS) ;
  printf("DCF77 Clock(c)IS");
  delay_ms(1000);

  // initialise time for test
  Heure = 10;
  Minute = 26 ;
  Seconde = 0 ;

  enable_interrupts(GLOBAL);
  StartTimer() ;
 
  printf(VT100CLS);  // Clear screen

  while (true) {   

    if ( DCF77CycleOK ) {      // a complete cycles  is finished

      DCF77Decoding( DCF77ValuesMinute, DCF77ValuesYear );  // it is possible to ask decoding of a part of received data
                                                            // after testing of DCF77BitNbr
                                                            // if DCF77BitNbr is >= DCF77ValuesDay then you
                                                            // can already decode minutes and hours
                                                           
      DCF77CycleOK = false ;   // for decoding DCF77 only one time when a cycle is finished

      if ( DCF77TimeOk ) {     // if no parity errors
        DCF77TimeOk = false ;

        Seconde =   DCF77Sec ;
        Minute =    DCF77Values[DCF77ValuesMinute] ;
        Heure =     DCF77Values[DCF77ValuesHour] ;
        day =       DCF77Values[DCF77ValuesDay] ;
        dayOfWeek = DCF77Values[DCF77ValuesDayOfWeek] ;
        month =     DCF77Values[DCF77ValuesMonth] ;
        year  =     DCF77Values[DCF77ValuesYear] ;

        if ( DCF77LastDate != DCF77DateInt() ) fAffDate() ;  //
       
      }
    }

    if ( SecondeFlag ) {  // refresh time each seconds
      fAffTime();
      SecondeFlag = 0;
    }

  }

}




buda include dosyası calcDCF77-8.c


void calcIndices(int8 indice, int8 *ByteNbr, int8 *BitNbr) {
  *ByteNbr= indice / 8 ;
  *BitNbr = indice - ( *ByteNbr * 8 ) ;
}

void DCF77Decoding( int first, int last ) {
 int8   i,j, DCF77BitWeightSubscr ;
 int8   calcStart, calcEnd ;
 short  parityTest ;
 int8   ByteNbr, BitNbr ;

  RadioParity = 0 ;
  RadioError = false ;

  for( j=first; j <= last; j++ ) {
    DCF77Values[j] = 0 ;
    calcStart = DCF77Scheme[j] ;
    calcEnd   = DCF77Scheme[j+1] ;

     parityTest = bit_test( calcEnd, 7 ) ;
     bit_clear(calcEnd, 7 );

    DCF77BitWeightSubscr = 0 ;
    for( i=calcStart; i < calcEnd; i++ ) {
      calcIndices( i, &ByteNbr, &BitNbr ) ;
      if ( bit_test( DCF77Bits[ByteNbr], BitNbr ) ) {
        DCF77Values[j] += DCF77BitWeight[DCF77BitWeightSubscr] ;
        RadioParity = !RadioParity ;
      }
      ++DCF77BitWeightSubscr ;
    }

    if ( parityTest ) {
      calcIndices( calcEnd, &ByteNbr, &BitNbr ) ;
      RadioError = ( RadioParity != bit_test( DCF77Bits[ByteNbr], BitNbr ) ) ;
      RadioParity = 0 ;
      j++ ;
    }
    if ( RadioError ) break ;
  }

  // -- The  autonomous clock  will add a minute because second is just set at 0 then minute - 1 ---
  //    not necessary without autonomous clock
  if ( !RadioError ) { 
    if (!DCF77Values[DCF77ValuesMinute]--) {
      DCF77Values[DCF77ValuesMinute] = 59;
      if(!DCF77Values[DCF77ValuesHour]--) DCF77Values[DCF77ValuesHour] = 23 ;
    }
  }
  // --------------------------------------------------------------------------------------

  DCF77TimeOk = !RadioError ;

}

arm-beginner

Hevesinizi kırmak istemem ama ben şahsen mesafe nedeniyle Türkiye'de DCF77 ile bir çalışma yapmazdım.
http://de.wikipedia.org/wiki/Datei:Dcf_weite.jpg

AYKIRI

#10
Alıntı yapılan: arm-beginner - 20 Eylül 2013, 21:32:49
Hevesinizi kırmak istemem ama ben şahsen mesafe nedeniyle Türkiye'de DCF77 ile bir çalışma yapmazdım.
http://de.wikipedia.org/wiki/Datei:Dcf_weite.jpg

mesafe ile ilgili sorunum yok sinyal alabiliyorum. eninde sonunda çalıştıracağım. sinyal olmasa uğraşmazdım ama sinyal var

OG

Forumlardan alıntı

@ DEVICE PIC16F819,INTRC_OSC
		@ DEVICE PIC16F819,MCLR_OFF
		'@ DEVICE CCPMX_ON
		@ DEVICE PIC16F819,BOD_OFF
		@ DEVICE PIC16F819,LVP_OFF
		@ DEVICE PIC16F819,CPD_OFF
		@ DEVICE PIC16F819,PROTECT_ON
		
		DEFINE	OSC	4
		DEFINE	ADC_BITS		10
		DEFINE	ADC_CLOCK		3
		DEFINE	ADC_SAMPLEUS	50
		'DEFINE	CCP1_REG PORTB
		'DEFINE	CCP1_BIT 3
		DEFINE	LCD_DREG PORTB
		DEFINE	LCD_DBIT 0
		DEFINE	LCD_RSREG PORTB
		DEFINE 	LCD_RSBIT 4
		DEFINE	LCD_EREG PORTB
		DEFINE	LCD_EBIT 5	
		DEFINE	LCD_BITS 4
		DEFINE	LCD_LINES 2
		DEFINE	LCD_COMMANDUS 2000
		DEFINE	LCD_DATAUS 50
		
		
	
	
		
		
		OSCCON =$60
		ADCON1 = 7
		OPTION_REG.7 = 0
		TRISA	=	%11111111
		TRISB	=	%00000000
		
		
	
		'CCP1CON = 	%00001100
		'ADCON1	=	%00001110
		'INTCON  =   $A0
		
		TRISA	=	%11111111
		TRISB	=	%00000000
		
		ANAIN		VAR	PORTA.0
		DCFIN		VAR	PORTA.2
		SK1			VAR	PORTA.3
		SK2			VAR	PORTA.4
		
		RELAIS		VAR	PORTB.6
		
		
		FIRSTTIME		VAR	BIT
		ONTVBIT			VAR	BIT
		STARTBYTE		VAR	BYTE
		ONTVBYTE		VAR	BYTE
		SEC				VAR	BYTE
		MINUUT			VAR	BYTE
		UUR				VAR	BYTE
		DAG				VAR	BYTE
		WEEK			VAR	BYTE
		MAAND			VAR	BYTE
		JAAR			VAR	BYTE
		I				VAR	BYTE
		N				VAR	BYTE
		TELLER			VAR	BYTE
		TOTAALTLR		VAR	BYTE
		
		
		
		Clear
		FIRSTTIME = 1
		Pause 1000
		
		
BEGIN:
		IF FIRSTTIME = 1 Then
			LCDOut $fe,1,"WACHT OP STARTBIT"
		EndIF
		SEC = 0
		GoSub WACHTENSTRTBIT
		SEC = SEC + 1
		IF SEC = 60 Then SEC = 0
		LCDOut $FE,$90,DEC2 SEC	
				
		IF STARTBYTE = 1 Then
			IF FIRSTTIME = 1 Then
			LCDOut $FE,1
			EndIF
			
			For I = 0 TO 20			'0-14 RESERVE BITS 15 TOT 20 OVERSLAAN
				GoSub EENBITONTV
			Next	
				
			
			N = 7
			GoSub BYTESONTV			'21-27 MINUUT
			MINUUT = ONTVBYTE
				
			GoSub EENBITONTV		'28 PARITY
			
			N = 6
			GoSub BYTESONTV			'29-34 UUR
			UUR = ONTVBYTE	
			
			GoSub EENBITONTV		'35 PARITY
			
			N = 6
			GoSub BYTESONTV			'36-41 DAG
			DAG = ONTVBYTE		
			
			N = 3
			GoSub BYTESONTV			'42-44 WEEK
			WEEK = ONTVBYTE
			
			N = 5
			GoSub BYTESONTV			'45-49 MAAND
			MAAND = ONTVBYTE
			
			N = 8
			GoSub BYTESONTV			'50-57 JAAR
			JAAR = ONTVBYTE
			
			GoSub EENBITONTV		'58 PARITY
			
			LCDOut $FE,$8D,DEC2 MINUUT,"."
			LCDOut $FE,$8A,DEC2 UUR,"."
			LCDOut $FE,$C0,DEC2 DAG
			
			IF WEEK = 1 Then LCDOut $FE,$80,"MAANDAG  " 
			IF WEEK = 2 Then LCDOut $FE,$80,"DINSDAG  "
			IF WEEK = 3 Then LCDOut $FE,$80,"WOENSDAG "
			IF WEEK = 4 Then LCDOut $FE,$80,"DONDERDAG"
			IF WEEK = 5 Then LCDOut $FE,$80,"VRYDAG   "
			IF WEEK = 6 Then LCDOut $FE,$80,"ZATERDAG "
			IF WEEK = 7 Then LCDOut $FE,$80,"ZONDAG   "
			
			IF MAAND = 1 Then LCDOut $FE,$C3,"JANUARI  "
			IF MAAND = 2 Then LCDOut $FE,$C3,"FEBRUARI "
			IF MAAND = 3 Then LCDOut $FE,$C3,"MAART    "
			IF MAAND = 4 Then LCDOut $FE,$C3,"APRIL    "
			IF MAAND = 5 Then LCDOut $FE,$C3,"MEI      "
			IF MAAND = 6 Then LCDOut $FE,$C3,"JUNI     "
			IF MAAND = 7 Then LCDOut $FE,$C3,"JULI     "
			IF MAAND = 8 Then LCDOut $FE,$C3,"AUGUSTUS "
			IF MAAND = 9 Then LCDOut $FE,$C3,"SEPTEMBER"
			IF MAAND = 10 Then LCDOut $FE,$C3,"OKTOBER  "
			IF MAAND = 11 Then LCDOut $FE,$C3,"NOVEMBER "
			IF MAAND = 12 Then LCDOut $FE,$C3,"DECEMBER "
			
			LCDOut $FE,$CE,"20", DEC2 JAAR
			
			FIRSTTIME = 0
		Else
			LCDOut $FE,1,"GEEN SIGNAAL"
		EndIF
		
		GoTo BEGIN
		
		
WACHTENSTRTBIT:
		STARTBYTE = 0
		TELLER = 0
		While STARTBYTE = 0
			TOTAALTLR = 0
			While DCFIN = 1
			Wend
			While DCFIN = 0
			TOTAALTLR =TOTAALTLR + 1
			Pause 10
			Wend
			IF TOTAALTLR > 100 Then STARTBYTE = 1
			IF TELLER > 120 Then STARTBYTE = 2
			TELLER = TELLER + 1
			IF FIRSTTIME = 1 Then LCDOut $FE,$C0,DEC3 TELLER
		Wend
							
		Return		
		
EENBITONTV:
		TOTAALTLR = 0
		While DCFIN = 0
		Wend
		While DCFIN = 1
			TOTAALTLR = TOTAALTLR + 1
			Pause 10
		Wend
		IF TOTAALTLR > 16 Then
			ONTVBIT = 1
		Else
			ONTVBIT = 0
		EndIF
		SEC = SEC + 1
		IF SEC = 60 Then SEC = 0
		LCDOut $FE,$90,DEC2 SEC			
		Return
		
BYTESONTV:
		
		ONTVBYTE = 0
		For I = 0 TO N - 1
			GoSub EENBITONTV
			IF ONTVBIT = 1 Then ONTVBYTE.0(I) = 1
		Next I
		ONTVBYTE = ((ONTVBYTE >> 4) * 10)+ (ONTVBYTE & 15) 		
		Return



'-------------------------------------------------------------------------------
' Receives DCF77 data from a standard DCF module
' with a PIC16F877A
' and show the date/time on a 16x2 chars LCD
'
' Written by Wauters Kris - august, 14th - 2004
'-------------------------------------------------------------------------------
											 
'-------------------------------------------------------------------------------
'--- PIC related                                                             ---
'-------------------------------------------------------------------------------
		Device = 16F877					'use the 16F877A PIC
        Xtal = 20						'at 20 Mhz
		All_Digital = true				'all pins ar digital

'-------------------------------------------------------------------------------
'--- LCD related                                                             ---
'-------------------------------------------------------------------------------
		Declare LCD_DTPin PORTB.4		'use B4-B7 	(PIC) for D4-D7 	(LCD)
		Declare LCD_ENPin PORTB.0 		'use BO  	(PIC) for enable 	(LCD)
		Declare LCD_RSPin PORTB.1 		'use B1 	(PIC) for R/S	 	(LCD)
		Declare LCD_Interface 4			'use LCD in 4bit mode
		Declare LCD_Lines 2				'use a 2-line LCD
		Declare LCD_Type 0				'0 = alphanumeric

'-------------------------------------------------------------------------------
'--- Sound related                                                           ---
'-------------------------------------------------------------------------------
		Symbol  R	=	0
		Symbol	C	=	82
		Symbol  Db0	=	85
		Symbol	D	=	87
		Symbol  Eb	=	89
		Symbol  E	=	92
		Symbol  F	=	94
		Symbol  Gb	=	95
		Symbol  G	=	97
		Symbol	Ab1	=	99
		Symbol  A1	=	73
		Symbol  Bb1	=	76
		Symbol  BE1	=	79
		Symbol	C1	=	82
		Symbol  Db1	=	85
		Symbol	D1	=	87
		Symbol  Eb1	=	89
		Symbol  E1	=	92
		Symbol  F1	=	94
		Symbol  Gb1	=	95
		Symbol  G1	=	97
		Symbol	Ab2	=	99
		Symbol	A2	=	101
		Symbol	Bb2	=	102
		Symbol	BE2	=	104
		Symbol	C2	=	105
		Symbol	Db2	=	106
		Symbol	D2	=	108
		Symbol	E2	=	110
		Symbol	F2	=	111
		Symbol	Gb2	=	112
		Symbol	G2	=	113
		Symbol	Bb3	=	115
		Symbol	Bm3	=	116
		Symbol	C3	=	117
		Symbol	D3	=	118
		Symbol PIN = PORTA.0
		
'-------------------------------------------------------------------------------
'--- DCF77 related                                                           ---
'-------------------------------------------------------------------------------
		Symbol Signal = PORTE.1
		Input PORTE.1
		'--- variable declarations ---
		Dim Bitcounter As Byte
		Dim ReceiveBit As Bit
		Dim ReceiveByte As Byte
     	Dim StartByte As Byte
		Dim Year As Byte
		Dim Month As Byte
		Dim Day As Byte
		Dim WeekDay As Byte
		Dim Hour As Byte
		Dim Minute As Byte
		Dim Second As Byte
		Dim i As Byte
	    Dim CountIt As Byte
	    Dim GeneralCounter As Byte
		Dim FirstTimeRun As Bit
		Dim LowBytePart As Byte
		Dim HighBytePart As Byte
							
'-------------------------------------------------------------------------------
'--- give PIC time to startup                                                ---
'--- and initialise screen	                                                 ---
'-------------------------------------------------------------------------------
DelayMS 200
Cls
FirstTimeRun = 1
'-------------------------------------------------------------------------------
'--- main loop                                                               ---
'-------------------------------------------------------------------------------
MainLoop:
		 If FirstTimeRun = 1 Then
		 	Print At 1,1, "Startbit wacht !"
		 EndIf
		 Second = 0
		 GoSub WaitForStartSequence 
		 Second = Second + 1
		 Print At 1,15,Dec2 Second
 
 		 '-------------------------------------------------
		 'Startbit succesfull, start filling data
		 '-------------------------------------------------		 
		 If StartByte = 1 Then
		 	If FirstTimeRun = 1 Then 
		 	   Print At 1,1, "                "
		 	   Print At 2,1, "                "
			EndIf
			
			'--- 0 .. 14 - first 15 bits are reserved   ---
			For i = 0 To 14			         
		 		GoSub ReceiveOneBit
			Next i
			
			'--- 15 - which antenna is used ?           ---
			GoSub ReceiveOneBit
			If ReceiveBit = 0 Then
			   Print At 1,1,"A"
			Else
			   Print At 1,1,"B"
			EndIf
			
			'--- 16 - switch summer/winter next hour ?  ---
			GoSub ReceiveOneBit
			If ReceiveBit = 1 Then
			   Print At 1,2,"*"
			Else
			   Print At 1,2," "
			EndIf
			
			'--- 17 - Daylight Savings Time ?   	    ---
			GoSub ReceiveOneBit
			If ReceiveBit = 1 Then
			   Print At 2,16,"Z"
			Else
			   Print At 2,16,"W"
			EndIf
			
			'--- 18 .. 20 - skip bits                   ---
			For i = 18 To 20
				GoSub ReceiveOneBit
			Next i
			
			'--- 21 .. 27 - receive minute   			---
			GoSub ReceiveByteWith7Bits			
			Minute = ReceiveByte
			
			'--- 28 - skip parity bit					---
			GoSub ReceiveOneBit
			
			'--- 29 .. 34 - receive hour				---
			GoSub ReceiveByteWith6Bits
			Hour = ReceiveByte
			
			'--- 35 - skip parity bit					---
			GoSub ReceiveOneBit

			'--- 36 .. 41 - receive day    				---
			GoSub ReceiveByteWith6Bits
			Day = ReceiveByte
			
			'--- 42 .. 44 - receive weekday				---
			GoSub ReceiveByteWith3Bits
			WeekDay = ReceiveByte
			
			'--- 45 .. 49 - receive month	 			---
			GoSub ReceiveByteWith5Bits
			Month = ReceiveByte
						
			'--- 50 .. 57 - receive year  				---
			GoSub ReceiveByteWith8Bits
			Year = ReceiveByte
			
			'--- 58 - skip parity bit					---
			GoSub ReceiveOneBit
			
			Print At 1,12,Dec2 Minute,":"
			Print At 1,9,Dec2 Hour,":"
			Print At 2,5, Dec2 Day
			If WeekDay = 1 Then Print At 2,1,"Maa"
			If WeekDay = 2 Then Print At 2,1,"Din"
			If WeekDay = 3 Then Print At 2,1,"Woe"
			If WeekDay = 4 Then Print At 2,1,"Don"
			If WeekDay = 5 Then Print At 2,1,"Vry"
			If WeekDay = 6 Then Print At 2,1,"Zat"
			If WeekDay = 7 Then Print At 2,1,"Zon"
			Print At 2,7,"-",Dec2 Month
			Print At 2,10,"-20",Dec2 Year

			FirstTimeRun = 0
		 Else
 		 '-------------------------------------------------
		 'Startbit not found, nog signal ?
 		 '-------------------------------------------------
		 	 Print At 1,1, "Signaal fout !  "
		 	 Print At 2,1, "                "
			 DelayMS 1000			 
		 EndIf
GoTo MainLoop:

'-------------------------------------------------------------------------------
'--- Wait for startsequence 		                                         ---
'--- We need to find 2 empty seconds                                         ---
'--- if startbyte = 1 when we return, we have a startbit                     ---
'--- if startbyte = 2 when we return, an error occured                       ---
'-------------------------------------------------------------------------------
WaitForStartSequence:	 	 
	 StartByte = 0
	 GeneralCounter = 0
	 While StartByte = 0
	 	   CountIt = 0
	 	   High PORTB.2
	 	   While Signal = 1	           '--- wait until signal becomes low
		   Wend	 
		   Low PORTB.2
	 	   While Signal = 0            '--- start counting time between pulses
				 CountIt = CountIt + 1
				 DelayMS 10   		 
		   Wend
		   If CountIt > 100 Then       '--- we count per 10 mS, so we need at
		   	  StartByte = 1            '--- least 100 x 10 mS for finding the
		   EndIf	                   '--- startsequence
		   If GeneralCounter > 120 Then'--- if more then 120 seconds counted
		   	  StartByte = 2	   	       '--- then we have a problem
		   EndIf
		   GeneralCounter = GeneralCounter + 1
		   If FirstTimeRun = 1 Then
		   	  Print At 2,1,Dec3 GeneralCounter
	 	   EndIf
	 Wend
Return
'-------------------------------------------------------------------------------
'--- Receive a bit and store it in ReceiveBit                                ---
'-------------------------------------------------------------------------------
ReceiveOneBit:
		   CountIt = 0
	 	   While Signal = 0     
		   Wend
		   While Signal = 1
		   		 CountIt = CountIt + 1
				 DelayMS 10
		   Wend
		   If CountIt > 16 Then
		   	  ReceiveBit = 1
		   Else
		      ReceiveBit = 0
		   EndIf
		   Second = Second + 1
		   Print At 1,15,Dec2 Second
Return

'-------------------------------------------------------------------------------
'--- Receive a full byte, only 3 last bits needed                            ---
'-------------------------------------------------------------------------------
ReceiveByteWith3Bits:
		   Bitcounter = 3
		   GoSub ReceiveCountedBits
Return

'-------------------------------------------------------------------------------
'--- Receive a full byte, only 5 last bits needed                            ---
'-------------------------------------------------------------------------------
ReceiveByteWith5Bits:
		   Bitcounter = 5
		   GoSub ReceiveCountedBits
Return

'-------------------------------------------------------------------------------
'--- Receive a full byte, only 6 last bits needed                            ---
'-------------------------------------------------------------------------------
ReceiveByteWith6Bits:
		   Bitcounter = 6
		   GoSub ReceiveCountedBits
Return

'-------------------------------------------------------------------------------
'--- Receive a full byte, only 7 last bits needed                            ---
'-------------------------------------------------------------------------------
ReceiveByteWith7Bits:
		   Bitcounter = 7
		   GoSub ReceiveCountedBits
Return

'-------------------------------------------------------------------------------
'--- Receive a full byte, only 8 last bits needed                            ---
'-------------------------------------------------------------------------------
ReceiveByteWith8Bits:
		   Bitcounter = 8
		   GoSub ReceiveCountedBits
Return

'-------------------------------------------------------------------------------
'--- fill the receivebyte with the requested amount of bits                  ---
'-------------------------------------------------------------------------------
ReceiveCountedBits:
		   
		   LowBytePart = 0
		   HighBytePart = 0
		   ReceiveByte = 0
		   For i = 0 To Bitcounter - 1
		   	   GoSub ReceiveOneBit
		   	   If ReceiveBit = 1 Then
				  If i < 4 Then
				  	 SetBit LowBytePart,i
				  Else
				  	 SetBit HighBytePart,i-4
				  EndIf
			   EndIf
		   Next i
		   ReceiveByte = (HighBytePart * 10) + LowBytePart
Return

'-------------------------------------------------------------------------------
'--- Play a nice sound every hour                  							 ---
'-------------------------------------------------------------------------------
HourSong:
		High PORTB.2
		Cls
		Sound PIN,[C2,30,R,10,C2,30,R,10,C2,80,R,3,C2,20,BE2,30,A2,20,BE2,30,C2,20,D2,30,R,5,C2,10,E2,30,R,15,E2,30,R,15,E2,80]
		Low PORTB.2
Return
FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.

AYKIRI

OG hocam yardımınız için teşekkür ederim. saati çalıştırdım 1 saat geriden geliyor ama onu x=x+1 şeklinde hallettim.
şimdiki amacım 1302 ye senkron etmek.

muhendisbey

Zulmü alkışlayamam, zalimi asla sevemem; Gelenin keyfi için geçmişe kalkıp sövemem.

OG

FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.