⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_rtc.c

📁 PIC30F系列单片机定时器1程序开发实例
💻 C
字号:

/**********************************************************************
* ?2005 Microchip Technology Inc.
*
* FileName:        main_rtc.c
* Dependencies:    p30fxxxx.h
* Processor:       dsPIC30Fxxxx
* Compiler:        MPLAB?C30 v1.31.00 or higher
*
* SOFTWARE LICENSE AGREEMENT:
* Microchip Technology Inc. (揗icrochip? licenses this software to you
* solely for use with Microchip dsPIC?digital signal controller
* products. The software is owned by Microchip and is protected under
* applicable copyright laws.  All rights reserved.
*
* SOFTWARE IS PROVIDED 揂S IS.? MICROCHIP EXPRESSLY DISCLAIMS ANY
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
* BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
*
* REVISION HISTORY:
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Author            Date      Comments on this revision
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Richard Fischer   07/18/05  Real-Time Clock example using Timer 1
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* ADDITIONAL NOTES:  This is an example program demonstrating a Real-Time
* Clock implementation using the Timer 1 peripheral and a 32.768 KHz crystal
* as the clock source. The key two files are init_timer1 and isr_timer1.
*
* The remaining files provide the support to show the TOD of the dsPIDEM 1.1
* LCD. Setting of the TOD is accomplished via the isr_INTpin.c file.
*
* This code has been tested to run at 14.756 MIPs (7.3728MHz & x8PLL). If
* the x16PLL mode is used the LCD controller SPI bit rate will need to 
* be adjusted and tested.
*
* C30 Optimization Level: -O1
*
**********************************************************************/

#include <p30fxxxx.h>
#include "LCD Display.h"
#include "common.h"


void Update_LCD( void );



int main ( void )
{
	/* Initialize some general use variables */
	hours, minutes, seconds = 0;
	rtc_lcd_update = 0;

	/* set LED0 pins as outputs */
	TRISDbits.TRISD0 = 0; 
 	
	/* Initialize SPI and LCD Display */
	//Display_Setup();	
	LCD_HomeClear();

	/* position LCD cursor at column, row */
    LCD_CharPos(0,0);
    Display_String(" RTC with dsPIC30F  ");
    /* position LCD cursor at column, row */
    LCD_CharPos(0,2);
    Display_String("Time> 00 : 00 : 00  ");
    /* position LCD cursor at column, row */
    LCD_CharPos(0,3);
    Display_String("      Hrs  Min  Sec ");


  	/* Initialize Timer 1 for 32KHz real-time clock operation */
    Init_Timer1();
    /* Initialize INT1 pin used for setting Time-of-Day */
    Init_INTpin();

     
    while ( 1 ) { 
      if ( rtc_lcd_update ) 
	  {
           Update_LCD();
           rtc_lcd_update = 0;
      }	 	
	};
	
	return 0;
}


/*---------------------------------------------------------------------
  Function Name: Update_LCD
  Description:   Update LCD for real-time clock data
  Inputs:        None
  Returns:       None
-----------------------------------------------------------------------*/
void Update_LCD( void )
{

   	hexdec( hours );
   	/* position LCD cursor at column, row */
	LCD_CharPos(6,2);
	LCD_WriteNext(tens + 0x30)
	LCD_WriteNext(ones + 0x30)
    
    hexdec( minutes );
    /* position LCD cursor at column, row */
	LCD_CharPos(11,2);
	LCD_WriteNext(tens + 0x30)
	LCD_WriteNext(ones + 0x30)
	 
  	hexdec( seconds );
	/* position LCD cursor at column, row */
	LCD_CharPos(16,2);
	LCD_WriteNext(tens + 0x30)
	LCD_WriteNext(ones + 0x30)
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -