<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pic dsPIC Arm7 Arm Cortex Programlama ve Projeler &#187; RTC</title>
	<atom:link href="http://www.uicroarm.com/tag/rtc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.uicroarm.com</link>
	<description>ds-pic arm-7 cortex nxp proje uygulama</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:41:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PIC24F-RTC</title>
		<link>http://www.uicroarm.com/pic24f-rtc</link>
		<comments>http://www.uicroarm.com/pic24f-rtc#comments</comments>
		<pubDate>Fri, 19 Feb 2010 22:42:25 +0000</pubDate>
		<dc:creator>Aykut</dc:creator>
				<category><![CDATA[PIC24F dsPIC30F dsPIC33F Uygulamaları]]></category>
		<category><![CDATA[16Bit]]></category>
		<category><![CDATA[c30]]></category>
		<category><![CDATA[PIC24F]]></category>
		<category><![CDATA[RTC]]></category>

		<guid isPermaLink="false">http://www.uicroarm.com/?p=115</guid>
		<description><![CDATA[
PIC24F &#8211; RTC Modülü Kullanımı :
PIC24F serisinin bir çok modülünün kullanımını buraya ekliyeceğim, birazda farklı sırada olabilecek yani RTC&#8217;den sonra port kullanımı veya adc vs. gibi. Program içinde modülün kullanımını bilmeyenler öğrenebilecektir.

/*
====================== Aykut ULUSAN         ====================
====================== Elektronik Mühendisi ====================
====================== IZMIR         [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.uicroarm.com/wp-content/dosyalar/2010/02/main_k.jpg" alt="main_k" title="main_k" width="295" height="221" class="alignnone size-full wp-image-116" /><span id="more-115"></span></p>
<p>PIC24F &#8211; RTC Modülü Kullanımı :<br />
PIC24F serisinin bir çok modülünün kullanımını buraya ekliyeceğim, birazda farklı sırada olabilecek yani RTC&#8217;den sonra port kullanımı veya adc vs. gibi. Program içinde modülün kullanımını bilmeyenler öğrenebilecektir.</p>
<pre class="brush: cpp; title: ; notranslate">
/*
====================== Aykut ULUSAN         ====================
====================== Elektronik Mühendisi ====================
====================== IZMIR                ====================
====================== www.uicroarm.com     ==================== 

Board: EX16L-A (PIC24/dsPIC33 development board) 

www.expkits.com 'dan temin edebilirsiniz
Board ayarları :
SWDIP6 'da 32768 ve Xtal uçları ON diğerleri OFF 

*/

#include &lt;p24Fxxxx.h&gt;

_CONFIG1(0x3F20)  	// JTAG, WDF, flash memory'ye yazma kullanılmayacak
_CONFIG2(0x7BAE)	// 10mhz xtal (HS), HSPLL enable, 

#define	LCD_RS		LATBbits.LATB8		// lcd için register select pin
//#define	LCD_RS		LATBbits.LATB8		// lcd için register select pin
#define	LCD_E		LATBbits.LATB5		// lcd enable pin
#define	LCD_PORT		LATB
#define	LCD_TRIS		TRISB
#define	d			1				// lcd'ye data/karakter yazılacak
#define	c			0				// lcd'ye komut yazılacak
#define	D			d				// lcd'ye data/karakter yazılacak
#define	C			c				// lcd'ye komut yazılacak

typedef unsigned char 	u8;

#define NOP() 		{__asm__ volatile (&quot;nop&quot;);}
#define CLRWDT() 	{__asm__ volatile (&quot;clrwdt&quot;);}
#define SLEEP() 	        {__asm__ volatile (&quot;pwrsav #0&quot;);}
#define IDLE() 		{__asm__ volatile (&quot;pwrsav #1&quot;);}

#define	LINE_1	0x80
#define	LINE_2	0xC0
#define	LINE_3	0x94
#define	LINE_4	0xD4
/*
LCD			PIC24
D4			PORTBbits.RB0
D5			PORTBbits.RB1
D6			PORTBbits.RB2
D7			PORTBbits.RB3
*/

// hex olarak yazılır
// haftanın günleri pazartesi 1, salı 2 ....... pazar 7
// 18.08.2009 , salı , 23:13:00
//  yıl     ay.gün   hgün.saat	  dak_san	

union zaman_uni {
  volatile unsigned int  time16bit[4];
  volatile unsigned char time8bit[8];
} RTCregs;

//volatile unsigned int zaman[]={0x2009,  0x0717,  0x0223, 0x1300};

#define yil_sbt			0x2009
#define ay_ve_gun_sbt		0x0717
#define hgunu_ve_saat		0x0223
#define dak_ve_san_sbt	0x1300	

volatile unsigned char sonuc[]={4,7,6,2,3,0};

void DLY_10US(unsigned int us);
void DLY_MS(unsigned int ms);
void LCD_ENABLE(void);
void LCD_WRITE(unsigned char da_ta, unsigned char D_C);
void LCD_SETUP(void);
void LCD_STRING(/*const*/ char *str);
void LCD_GOTO(unsigned char satir,unsigned char adres);

volatile unsigned char g; 

int
main(void){
        while(OSCCONbits.COSC!=3);
        while(!OSCCONbits.LOCK);		// PLL kitleninceye kadar bekle
	AD1PCFG=0xFFFF;			// portlar dijital
	PMCON=0;
	LATB=0;
	PORTB=0;					// latch'leri temizle
	TRISB=0; asm(&quot;NOP&quot;);		        // B portu çıkış

	LCD_SETUP();

	LCD_GOTO(LINE_1,0);
	LCD_STRING(&quot;SAAT:&quot;);
	LCD_GOTO(LINE_2,0);
	LCD_STRING(&quot;TARIH:&quot;);

	RTCregs.time16bit[0]=yil_sbt;			// zamanı yükle
	RTCregs.time16bit[1]=ay_ve_gun_sbt;
	RTCregs.time16bit[2]=hgunu_ve_saat;
	RTCregs.time16bit[3]=dak_ve_san_sbt;
	__builtin_write_OSCCONL(0x02);		// RTC osc enable
// RTCWREN 'e yazma unlock
        asm(&quot;MOV #0x55,W0&quot;);				// flash'a yazmak için unlock yapılmalı
	asm(&quot;MOV W0,NVMKEY&quot;);                      // flash key'i yükle
	asm(&quot;MOV #0xAA,W1&quot;);
	asm(&quot;MOV W1,NVMKEY&quot;);			//
	RCFGCALbits.RTCWREN=1;			// RTC'ye yazma enbale
	RCFGCALbits.RTCEN=0;				// RTC disable
        PADCFG1bits.RTSECSEL=1;			// saniye çıkışı
        RCFGCALbits.RTCOE=1;				// RB15 üzerinde saniye pulsi alacağız

    RCFGCALbits.RTCPTR = 3;				// yıldan itibaren zamanı yükle

	for(g=0;g&lt;4;g++) 					// zamanı yükle
		RTCVAL=RTCregs.time16bit[g];								

	RCFGCALbits.CAL=0;					// kalibrasyon yapılmayacak
	RCFGCALbits.RTCEN=1;				// rtc enable
	RCFGCALbits.RTCWREN=0;				// RTC yazmayı kilitle

	while(1) {
		while(RCFGCALbits.RTCSYNC);      // RTCSYNC=1 iken bekle
		RCFGCALbits.RTCPTR=3;
		for(g=0;g&lt;4;g++)
			RTCregs.time16bit[g]=RTCVAL;

		LCD_GOTO(LINE_1,5);
		for(g=0;g&lt;3;g++) {
			LCD_WRITE((RTCregs.time8bit[sonuc[g]]&gt;&gt;4)+0x30,d);
			LCD_WRITE((RTCregs.time8bit[sonuc[g]]&amp;0xF)+0x30,d);
			if(g!=2) LCD_STRING(&quot;:&quot;);
		}
		LCD_GOTO(LINE_2,6);
		for(g=3;g&lt;6;g++) {
			LCD_WRITE((RTCregs.time8bit[sonuc[g]]&gt;&gt;4)+0x30,d);
			LCD_WRITE((RTCregs.time8bit[sonuc[g]]&amp;0xF)+0x30,d);
			if(g!=5) LCD_STRING(&quot;.&quot;);
		}
        DLY_MS(250);
	}

}

// X*10US
void
DLY_10US(unsigned int us){
	while(us--) {
		__asm__ volatile (&quot;repeat #165&quot;);
		__asm__ volatile (&quot;nop&quot;);
	}
}

// 65536ms'ye kadar
void
DLY_MS(unsigned int ms){
	while(ms--){
		DLY_10US(100);
	}
}

void
LCD_ENABLE(void){
	LCD_E=1;asm(&quot;nop&quot;);asm(&quot;nop&quot;);asm(&quot;nop&quot;);asm(&quot;nop&quot;);LCD_E=0;
}

void
LCD_WRITE(unsigned char da_ta, unsigned char D_C){
	if(D_C) LCD_RS=1;					// data modu
	else	LCD_RS=0;					// komut modu
	LCD_PORT&amp;=0x3F0;
	LCD_PORT|=da_ta&gt;&gt;4;					// lcd'ye gönder, RS ve E bozulmamalı
	LCD_ENABLE();						// enable
	LCD_PORT&amp;=0x3F0;
	LCD_PORT|=da_ta&amp;0x0F;				// lcd'ye gönder
	LCD_ENABLE();						// enable
	DLY_10US(50);						// 50us delay
	LCD_RS=0;
}

void
LCD_SETUP(void){
	DLY_MS(100);			// lcd'nin kendini hazırlaması için 100ms
	LCD_PORT=0x3;
	LCD_ENABLE();
	DLY_MS(10);
	LCD_ENABLE();
	DLY_MS(10);
	LCD_ENABLE();
	DLY_MS(10);
	LCD_PORT=0x2;
	LCD_ENABLE();
	DLY_MS(10);
	LCD_WRITE(0x28,c);		// disp on, cursor off
	LCD_WRITE(0x0c,c);		//
        LCD_WRITE(0x06,c);		//
	LCD_WRITE(0x01,c);		// clear display
	LCD_WRITE(0x02,c);		//
	DLY_MS(2);		

}

void
LCD_STRING(char *str){
	while(*str)
		LCD_WRITE(*str++,d);
} 

void
LCD_GOTO(unsigned char satir,unsigned char adres){
	LCD_WRITE(satir+adres,c);
}
</pre>
<p><a href="http://www.uicroarm.com/wp-content/dosyalar/2010/02/lcd_10001.jpg" rel="lightbox[115]"><img src="http://www.uicroarm.com/wp-content/dosyalar/2010/02/lcd_10001-150x150.jpg" alt="lcd_1000" title="lcd_1000" width="150" height="150" class="alignnone size-thumbnail wp-image-119" /></a><a href="http://www.uicroarm.com/wp-content/dosyalar/2010/02/kart10001.jpg" rel="lightbox[115]"><img src="http://www.uicroarm.com/wp-content/dosyalar/2010/02/kart10001-150x150.jpg" alt="kart1000" title="kart1000" width="150" height="150" class="alignnone size-thumbnail wp-image-120" /></a><a href="http://www.uicroarm.com/wp-content/dosyalar/2010/02/card800.jpg" rel="lightbox[115]"><img src="http://www.uicroarm.com/wp-content/dosyalar/2010/02/card800-150x150.jpg" alt="card800" title="card800" width="150" height="150" class="alignnone size-thumbnail wp-image-121" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.uicroarm.com/pic24f-rtc/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

