Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

using rtcc in pic18f66k22

Status
Not open for further replies.

shreyas_patel21

Full Member level 3
Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
Hi all,

I am using pic18f66k22 and I want to display time on LCD using inbuilt RTCC module.

below is my code I tried but there is no update in seconds on LCD..


Code:
#include <stdio.h>
#include <p18f66k22.h>
#include "lcd.h"
#include "font.h"
#include "rtcc.h"
#include "functions.h"

/***************************configuration bits***************************/
#pragma config SOSCSEL = DIG
#pragma config XINST = OFF
#pragma config FOSC = INTIO2, FCMEN = OFF,IESO = OFF,PLLCFG = ON
#pragma config PWRTEN = ON, WDTEN = OFF,BOREN = OFF
#pragma config MCLRE = ON
#pragma config CP0=OFF, CP1=OFF,CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF
#pragma config WRTC=OFF, WRTB=OFF,WRTD=OFF
#pragma config EBRT0=OFF , EBRT1=OFF , EBRT2=OFF , EBRT3=OFF , EBRTB=OFF
#pragma config STVREN = ON

//---Function Prototypes---
void RTCC_configure(void);


//---Global structures used in deep sleep library---
rtccTimeDate RtccTimeDate ,RtccAlrmTimeDate, Rtcc_read_TimeDate ;


unsigned int background=0xf800, font=0xffff, red=0xf800;
unsigned int violet=0x3191, blue=0x0457, yellow=0xf661, green=0x4EC4, black=0x18c3;

//***********main function***********
void main (void)
{
	unsigned char x = 1, y = 2;
	unsigned char test[2] = {0,0}; 
	unsigned int second = 0;
	OSCCONbits.IRCF0 = 1;	//HFINTOSC 16MHz with PLLEN
	OSCCONbits.IRCF1 = 1;
	OSCCONbits.IRCF2 = 1;
	OSCTUNEbits.PLLEN = 1;
	
	ANCON0 = 0x00;
	ANCON1 = 0x00;
	ANCON2 = 0x00;
	ADCON0 = 0X00;
    ADCON1 = 0X00;
    ADCON2 = 0X00;
	
	TRISA = 0x00;
	TRISB = 0X00;	//output
    TRISC = 0X00;	//output
    TRISD = 0X00;	//output
    TRISE = 0X00;	//output
	TRISF =  0Xff;	//input
	
	PORTCbits.RC0 = 0;//lcd reset
	delay_ms(5);
	PORTCbits.RC0 = 1;
	PORTCbits.RC0 = 1;
	PORTAbits.RA5 = 1;
	
	LCD_init();
	font_init();
	setfont((void *)font_Calibri_10);	
	LCD_paint_block(x+0, y+0, x+159, y+127, font);
	
	RTCC_configure();
	
	while(1)
	{
		RtccReadTimeDate(&RtccTimeDate);
		second = RtccTimeDate.f.sec;
		test[0] = second | 0x30;
		test[1] = second | 0x30;
		LCD_OutText(40,67,test,black);			
		
	}	
	
	
}	

void RTCC_configure(void)
{
unsigned int i=0,j=0;


   RtccInitClock();                                       //turn on clock source
   RtccWrOn();                                            //write enable the rtcc registers
   mRtccSetClockOe(1);                                    //enable RTCC output on RTCC output pin
  // PIE3bits.RTCCIE=1;
   //Set Date and time using global structures defined in libraries
   RtccTimeDate.f.hour = 1;                                //Set Hour
   RtccTimeDate.f.min =  0;                                //Set minute
   RtccTimeDate.f.sec =  2;                                //Set second
   RtccTimeDate.f.mday = 4;                            //Set day
   RtccTimeDate.f.mon =  4;                            //Se month
   RtccTimeDate.f.year = 09;                             //set year
   RtccTimeDate.f.wday = 6;                              //Set which day of the week for the corrsponding date

 
   RtccWriteTimeDate(&RtccTimeDate,1);                    //write into registers
 
   mRtccOn();                                            //enable the rtcc
  
}
void delay_ms(unsigned int ms)
{
	unsigned int x;

	for(x = 0; x < 8*ms; x++)
		{
			TMR1L = 0x00;
			TMR1H = 0x00;
			T1CON = 0x31;			//turn on timer1 1:8 PRESCALE 
			while(TMR1L < 0xFA);	//125uS
			T1CON = 0x30;
		}
}
void delay(unsigned int i)
{

	for(;i>1;i--);
}

any suggestion would be helpful..

thank you!
Regards,
shreyas.
 

Hello again..

I have found the problem in upper code, I configured the rtcc clock properly and it done,

but now I have problem that how to enter into sleep mode?
and the RTCC is in-built so if we turn off the pic it will reset the RTC..
 

Hi,

Don't do C but the 66K22 looks an interesting chip with is RTCC.

You should just be able to put the chip to 'Sleep' when you have power applied - this tutorial shows you how.

www.gooligum.com.au/tutorials/baseline/PIC_Base_C_3.pdf


Seems there are no separate power lines for the RTC so if your main power is off you will have to use a battery backup to allow the RTC to function in Sleep mode.
That chip is optimised for very low power while in Sleep mode so a small battery, even a button cell should last a long time.

In case of total power loss in a real time situation you could always write the RTC registers to EEPROM every minute or 5 minutes and restore them at Power on / program Start, then you only loose the time that the power was lost.
 
Thank you wp100!

my problem is that i have used 3.3v supply for LCd and pic also from the same source,
If I connect battery than my LCD will also be turn ON?
where should I connect the small battery to operate only RTC module?
 

Hi,

Two simple methods show below.

The first way means the pic is running at 3.1v to the 3.3v lcd , but that should work .

The second way ensures all voltage levels are the same - all 4 diodes must be the same standard or schottky types.
 

Attachments

  • ScreenShot003.jpg
    ScreenShot003.jpg
    40.6 KB · Views: 88

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top