#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--);
}