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

📄 runtime.c

📁 里面给出了ATmega103单片机编程的C语言实例程序
💻 C
字号:
/* ATmega103 runtime.c file

   Author : Robert Stuart
   Company : PDL Industries Ltd
   Date of Creation : 21 July 1999
   Tested : not yet

   Function :
*/

/* include */
#include "runtime.h"

void RuntimeInitialise( void )
{
  TCCR1B = 0; 			/* Stop T1 */
  TCNT1 = 0;			/* Clear T1 */
  OCR1A = _1MS_INTERRUPT;		/* Set Compare A - 1ms */
  TIMSK = BIT(OCIE1A);		/* Compare A interrupt enabled */
  TCCR1B = BIT(CS10) | BIT(CTC1);
}

void RuntimeInterrupt( void )
{
  ReadButtons();
  
  RefreshImportantRegisters();
  
  DelayLCDStartup();

  CheckPower();
  
  WriteLCDMessage();
  
  SampleADC();
  
  WDR;
}

void SampleADC( void )
{
  unsigned int ADCValue[8];
  unsigned char Channel;
  
  for ( Channel=0; Channel<8; Channel++ )
  {
    ADMUX = Channel;	      	/* select channel */
    ADCSR |= BIT(ADSC);
    while ( ADCSR & BIT(ADSC) );	/* wait until conversion is finished */

    ADCValue[Channel] = ADCL;  	/* read lower bytes first */
    ADCValue[Channel] += ADCH << 8;	/* sample at 10-bit resolution */
  }
}

void WriteLCDMessage( void )
{
  static unsigned int Counter;
  char str1[17], str2[17];
  
  if ( Counter++ > _500MS )
  {
    Counter = 0;
    
    sprintf( str1, "Time %02d:%02d:%02d", Time.Hour, Time.Minute, Time.Second );
    sprintf( str2, "Date %02d-%s-%04d", Time.Day, Calender[Time.Month], Time.Year );
    
    LCDPrintf( str1, str2 );
  }
}

void RefreshImportantRegisters( void )
{
  DDRD = CONFIGURE_PORTD;
  DDRE = CONFIGURE_PORTE; 
}


⌨️ 快捷键说明

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