mcb1700 lpc1768 RTC&TFT uygulaması

Başlatan haydarpasamikro, 03 Ocak 2012, 20:17:32

haydarpasamikro



main.c

#include "lpc17xx.h"
#include "type.h"
#include "rtc.h"
#include "GLCD.h"
#include <stdio.h>

#define __FI        1                       /* Font index 16x24               */
                                                                         

extern volatile uint32_t alarm_on;
RTCTime local_time, alarm_time, current_time;

char text[10];


/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{ 
	uint8_t 	*wofday[] = {"Pazartesi","Sali","Carsamba","Persembe","Cuma","Cumartesi","Pazar"};	
  /* SystemClockUpdate() updates the SystemFrequency variable */
  //SystemClockUpdate();

  /* Initialize RTC module */
  RTCInit();
  
  local_time.RTC_Sec = 5;
  local_time.RTC_Min = 23;
  local_time.RTC_Hour = 18;		/* current time 18:23:05 */
  local_time.RTC_Mday = 3;
  local_time.RTC_Wday = 1;
  local_time.RTC_Yday = 3;		/* current date 03/01/2012 */
  local_time.RTC_Mon = 1;
  local_time.RTC_Year = 2012;
  RTCSetTime( local_time );		/* Set local time */

//  alarm_time.RTC_Sec = 0;
//  alarm_time.RTC_Min = 0;
//  alarm_time.RTC_Hour = 0;
//  alarm_time.RTC_Mday = 5;
//  alarm_time.RTC_Wday = 1;
//  alarm_time.RTC_Yday = 5;		/* alarm date 01/01/2007 */
//  alarm_time.RTC_Mon = 1;
//  alarm_time.RTC_Year = 2012;
//  RTCSetAlarm( alarm_time );		/* set alarm time */

  NVIC_EnableIRQ(RTC_IRQn);

  /* mask off alarm mask, turn on IMYEAR in the counter increment interrupt
  register */
  //RTCSetAlarmMask(AMRMIN|AMRHOUR|AMRDOM|AMRDOW|AMRDOY|AMRMON|AMRYEAR);
  LPC_RTC->CIIR = IMSEC;
  
    
  RTCStart();

  LPC_GPIO1 -> FIODIR |= (1<<28);
  LPC_GPIO1 -> FIOCLR |= (1<<28);

  GLCD_Init();                               /* Initialize graphical LCD      */

  GLCD_Clear(White);                         /* Clear graphical LCD display   */
  
  GLCD_SetBackColor(Blue);
  GLCD_SetTextColor(White);

  
  GLCD_DisplayString(0, 0, __FI, "     HAYDARPASA     ");
  GLCD_DisplayString(1, 0, __FI, " TEKNiK Ve ENDUSTRi ");
  GLCD_DisplayString(2, 0, __FI, "  MESLEK ELEKTRONiK ");
  GLCD_SetBackColor(White);
  GLCD_SetTextColor(Blue);
  GLCD_DisplayString(4, 0, __FI, "Zaman:");
  GLCD_DisplayString(5, 0, __FI, "Tarih:");
  GLCD_DisplayString(6, 0, __FI, "H/gun:");
  GLCD_DisplayString(7, 0, __FI, "Y/gun:");
  GLCD_DisplayString(8, 0, __FI, "Gun  :");
  
  GLCD_SetBackColor(White);
  GLCD_SetTextColor(Red);

  while (1) 
  {					/* Loop forever */

	if ( alarm_on != 0 ) /* Get current time when alarm is on */
	{
		current_time = RTCGetTime();

		sprintf(text, "%02d", current_time.RTC_Hour);       /* format text for print out     */		
		GLCD_DisplayString(4,6, __FI,  (unsigned char *)text); 
		sprintf(text, ":%02d", current_time.RTC_Min);       /* format text for print out     */		
		GLCD_DisplayString(4,8, __FI,  (unsigned char *)text); 
		sprintf(text, ":%02d", current_time.RTC_Sec);       /* format text for print out     */		
      	GLCD_DisplayString(4,11, __FI,  (unsigned char *)text); 

		sprintf(text, "%02d", current_time.RTC_Mday);       /* format text for print out     */		
		GLCD_DisplayString(5,6, __FI,  (unsigned char *)text); 
		sprintf(text, ":%02d", current_time.RTC_Mon);       /* format text for print out     */		
		GLCD_DisplayString(5,8, __FI,  (unsigned char *)text); 
		sprintf(text, ":%02d", current_time.RTC_Year);       /* format text for print out     */		
      	GLCD_DisplayString(5,11, __FI,  (unsigned char *)text); 

		sprintf(text, "%02d", current_time.RTC_Wday+1);       /* format text for print out     */		
		GLCD_DisplayString(6,6, __FI,  (unsigned char *)text); 
		sprintf(text, "%02d", current_time.RTC_Yday);       /* format text for print out     */		
      	GLCD_DisplayString(7,6, __FI,  (unsigned char *)text); 
		
		GLCD_DisplayString(8,6, __FI,  wofday[current_time.RTC_Wday]); 		
		
	  alarm_on = 0;	  
	  
	  LPC_GPIO1 -> FIOPIN ^= (1<<28);	
	}
  }

}

/******************************************************************************
**                            End Of File
******************************************************************************/


Mikro Dünyası.Haydarpaşa Teknik ve Endüstri Meslek Lisesi Mikrodenetleyici Atl. Şefi

Okan AKÇA

driver dosyalarını paylaşsanız daha faydalı olurdu hocam ellerinize saglık

haydarpasamikro

GLCD için Keil mdk ile gelen kütüphaneler kullanılmıştır.(C:\Keil_ARM\ARM\Boards\Keil\MCB1700\Blinky içerisindeki)
RTC için NXP keil code bunddles kütüphaneleri kullanılmıştır.(nxp sitesindeki mcb1700.code.bundle.lpc17xx.keil.zip)

rtc.c

/****************************************************************************
 *   $Id:: rtc.c 5743 2010-11-30 23:18:58Z usb00423                         $
 *   Project: NXP LPC17xx RTC example
 *
 *   Description:
 *     This file contains RTC code example which include RTC initialization, 
 *     RTC interrupt handler, and APIs for RTC access.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#include "lpc17xx.h"
#include "type.h"
#include "rtc.h"

volatile uint32_t alarm_on = 0;

/*****************************************************************************
** Function name:		RTC_IRQHandler
**
** Descriptions:		RTC interrupt handler, it executes based on the
**						the alarm setting
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTC_IRQHandler (void) 
{  
  LPC_RTC->ILR |= ILR_RTCCIF;		/* clear interrupt flag */
  alarm_on = 1;
  return;
}

/*****************************************************************************
** Function name:		RTCInit
**
** Descriptions:		Initialize RTC timer
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTCInit( void )
{
  alarm_on = 0;

  /* Enable CLOCK into RTC */
  LPC_SC->PCONP |= (1 << 9);

  /* If RTC is stopped, clear STOP bit. */
  if ( LPC_RTC->RTC_AUX & (0x1<<4) )
  {
	LPC_RTC->RTC_AUX |= (0x1<<4);	
  }
  
  /*--- Initialize registers ---*/    
  LPC_RTC->AMR = 0;
  LPC_RTC->CIIR = 0;
  LPC_RTC->CCR = 0;
  return;
}

/*****************************************************************************
** Function name:		RTCStart
**
** Descriptions:		Start RTC timer
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTCStart( void ) 
{
  /*--- Start RTC counters ---*/
  LPC_RTC->CCR |= CCR_CLKEN;
  LPC_RTC->ILR = ILR_RTCCIF;
  return;
}

/*****************************************************************************
** Function name:		RTCStop
**
** Descriptions:		Stop RTC timer
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTCStop( void )
{   
  /*--- Stop RTC counters ---*/
  LPC_RTC->CCR &= ~CCR_CLKEN;
  return;
} 

/*****************************************************************************
** Function name:		RTC_CTCReset
**
** Descriptions:		Reset RTC clock tick counter
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTC_CTCReset( void )
{   
  /*--- Reset CTC ---*/
  LPC_RTC->CCR |= CCR_CTCRST;
  return;
}

/*****************************************************************************
** Function name:		RTCSetTime
**
** Descriptions:		Setup RTC timer value
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTCSetTime( RTCTime Time ) 
{
  LPC_RTC->SEC = Time.RTC_Sec;
  LPC_RTC->MIN = Time.RTC_Min;
  LPC_RTC->HOUR = Time.RTC_Hour;
  LPC_RTC->DOM = Time.RTC_Mday;
  LPC_RTC->DOW = Time.RTC_Wday;
  LPC_RTC->DOY = Time.RTC_Yday;
  LPC_RTC->MONTH = Time.RTC_Mon;
  LPC_RTC->YEAR = Time.RTC_Year;    
  return;
}

/*****************************************************************************
** Function name:		RTCSetAlarm
**
** Descriptions:		Initialize RTC timer
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTCSetAlarm( RTCTime Alarm ) 
{   
  LPC_RTC->ALSEC = Alarm.RTC_Sec;
  LPC_RTC->ALMIN = Alarm.RTC_Min;
  LPC_RTC->ALHOUR = Alarm.RTC_Hour;
  LPC_RTC->ALDOM = Alarm.RTC_Mday;
  LPC_RTC->ALDOW = Alarm.RTC_Wday;
  LPC_RTC->ALDOY = Alarm.RTC_Yday;
  LPC_RTC->ALMON = Alarm.RTC_Mon;
  LPC_RTC->ALYEAR = Alarm.RTC_Year;    
  return;
}

/*****************************************************************************
** Function name:		RTCGetTime
**
** Descriptions:		Get RTC timer value
**
** parameters:			None
** Returned value:		The data structure of the RTC time table
** 
*****************************************************************************/
RTCTime RTCGetTime( void ) 
{
  RTCTime LocalTime;
    
  LocalTime.RTC_Sec = LPC_RTC->SEC;
  LocalTime.RTC_Min = LPC_RTC->MIN;
  LocalTime.RTC_Hour = LPC_RTC->HOUR;
  LocalTime.RTC_Mday = LPC_RTC->DOM;
  LocalTime.RTC_Wday = LPC_RTC->DOW;
  LocalTime.RTC_Yday = LPC_RTC->DOY;
  LocalTime.RTC_Mon = LPC_RTC->MONTH;
  LocalTime.RTC_Year = LPC_RTC->YEAR;
  return ( LocalTime );    
}

/*****************************************************************************
** Function name:		RTCSetAlarmMask
**
** Descriptions:		Set RTC timer alarm mask
**
** parameters:			Alarm mask setting
** Returned value:		None
** 
*****************************************************************************/
void RTCSetAlarmMask( uint32_t AlarmMask ) 
{
  /*--- Set alarm mask ---*/    
  LPC_RTC->AMR = AlarmMask;
  return;
}

/*****************************************************************************
**                            End Of File
******************************************************************************/


rtc.h

/****************************************************************************
 *   $Id:: rtc.h 5743 2010-11-30 23:18:58Z usb00423                         $
 *   Project: NXP LPC17xx RTC example
 *
 *   Description:
 *     This file contains RTC code header definition.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#ifndef __RTC_H 
#define __RTC_H

typedef struct {
    uint32_t RTC_Sec;     /* Second value - [0,59] */
    uint32_t RTC_Min;     /* Minute value - [0,59] */
    uint32_t RTC_Hour;    /* Hour value - [0,23] */
    uint32_t RTC_Mday;    /* Day of the month value - [1,31] */
    uint32_t RTC_Mon;     /* Month value - [1,12] */
    uint32_t RTC_Year;    /* Year value - [0,4095] */
    uint32_t RTC_Wday;    /* Day of week value - [0,6] */
    uint32_t RTC_Yday;    /* Day of year value - [1,365] */
} RTCTime;

#define IMSEC		0x00000001
#define IMMIN		0x00000002
#define IMHOUR		0x00000004
#define IMDOM		0x00000008
#define IMDOW		0x00000010
#define IMDOY		0x00000020
#define IMMON		0x00000040
#define IMYEAR		0x00000080

#define AMRSEC		0x00000001  /* Alarm mask for Seconds */
#define AMRMIN		0x00000002  /* Alarm mask for Minutes */
#define AMRHOUR		0x00000004  /* Alarm mask for Hours */
#define AMRDOM		0x00000008  /* Alarm mask for Day of Month */
#define AMRDOW		0x00000010  /* Alarm mask for Day of Week */
#define AMRDOY		0x00000020  /* Alarm mask for Day of Year */
#define AMRMON		0x00000040  /* Alarm mask for Month */
#define AMRYEAR		0x00000080  /* Alarm mask for Year */

#define PREINT_RTC	0x000001C8  /* Prescaler value, integer portion, 
				    PCLK = 15Mhz */
#define PREFRAC_RTC	0x000061C0  /* Prescaler value, fraction portion, 
				    PCLK = 15Mhz */
#define ILR_RTCCIF	0x01
#define ILR_RTCALF	0x02

#define CCR_CLKEN	0x01
#define CCR_CTCRST	0x02
#define CCR_CLKSRC	0x10

extern void RTC_IRQHandler (void);
extern void RTCInit( void );
extern void RTCStart( void );
extern void RTCStop( void );
extern void RTC_CTCReset( void );
extern void RTCSetTime( RTCTime );
extern RTCTime RTCGetTime( void );
extern void RTCSetAlarm( RTCTime );
extern void RTCSetAlarmMask( uint32_t AlarmMask );

#endif /* end __RTC_H */
/*****************************************************************************
**                            End Of File
******************************************************************************/

Mikro Dünyası.Haydarpaşa Teknik ve Endüstri Meslek Lisesi Mikrodenetleyici Atl. Şefi