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

📄 lowfreqsg.c

📁 GCC 做的MOTOROLA 的单片机 振荡程序
💻 C
字号:
/** ###################################################################
**     Filename  : LowFreqSG.C
**     Project   : LowFreqSG
**     Processor : MC68HC908LV8CFA
**     Version   : Driver 01.15
**     Compiler  : CodeWarrior HC08 C Compiler
**     Date/Time : 2006-9-5, 17:47
**     Abstract  :
**         Main module.
**         Here is to be placed user's code.
**     Settings  :
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/
/* MODULE LowFreqSG */


/* Including used modules for compiling procedure */

#include "Cpu.h"
#include "LCD1.h"
#include "TO1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

const unsigned char segcode[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; 
const unsigned char th[10] = {0x9c, 0xff, 0xdf, 0xc3, 0xad, 0x9c, 0x8d, 0x82, 0x78, 0x6f};
const unsigned char tl[10] = {0x28, 0xfe, 0x15, 0x32, 0x82, 0x28, 0xf6, 0x21, 0x1f, 0x8a};
const unsigned int cv[10] = {0x9c28, 0xfffe, 0xdf15, 0xc332, 0xad82, 0x9c28, 0x8df6, 0x8221, 0x781f, 0x6f8a};
const unsigned char pv[10] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

extern bool Alt; 

void setfreq(unsigned char i) 
{
      /* T2SC: TOF=0,TOIE=0,TSTOP=1,TRST=1,??=0,PS2=0,PS1=0,PS0=0 */
  setReg8(T2SC, 0x30);                 /* Stop and reset counter */ 
  /* T2SC0: CH0F=0,CH0IE=0,MS0B=1,MS0A=0,ELS0B=0,ELS0A=0,TOV0=0,CH0MAX=0 */
  setReg8(T2SC0, 0x20);                /* Set output signal level to high */ 
  /* T2SC0: CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=0,ELS0A=1,TOV0=0,CH0MAX=0 */
  setReg8(T2SC0, 0x34);                 
  Alt = FALSE;                         /* Set up currently active channel flag */
  setReg8(T2CH0H, th[i]);               /* Store initial value to the duty-compare register */ 
  setReg8(T2CH0L, tl[i]);                
  SetCV((word)cv[i]);                 /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  SetPV((byte)pv[i]);                   /* Set prescaler register according to the selected high speed CPU mode */
  /* T2SC: TSTOP=0 */
  clrReg8Bits(T2SC, 0x20);             /* Run counter */  
}

void main(void)
{
  
  unsigned char ifreq = 0;
  unsigned char freq;
  unsigned char i;
  unsigned char klch = 0;
  unsigned char klst;
  unsigned char kdly = 100;
  unsigned char ksat = 0;
  unsigned char strbuf[9] = {0};
  unsigned char lcdbuf[9] = {0};
  unsigned char *ldat = &LDAT1;
  
  
  /* Write your local variable definition here */
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  for(;;) 
  {
      klst = klch;
      klch = ((PTA & 0x06) ^ 0x06) >> 1;
      
      if(klst != klch) kdly = 10;
      
      if(kdly > 1 ) --kdly;
      else if(kdly == 1)
      {
        ksat = klch;
        kdly = 0;   
      }
      
      if(ksat == 0x01) 
      {
        if(ifreq < 9) ++ifreq;
        setfreq(ifreq); 
        ksat = 0;  
      } 
      else if(ksat == 0x02) 
      {
        if(ifreq > 0) --ifreq;
        setfreq(ifreq);
        ksat = 0;
      }
        
              
      freq = ifreq * 10 + 50;
      lcdbuf[0] = 0x00;
      for(i = 0; i < 8; ++i) 
      {
        strbuf[7 - i] = segcode[freq % 10];
        freq /= 10;
        if((freq == 0) && (strbuf[7 - i] == segcode[0])) strbuf[7 - i] = 0x00;        
        lcdbuf[i] |= ((strbuf[i] & 0x10) << 1) | ((strbuf[i] & 0x20) << 1) | ((strbuf[i] & 0x01) << 7);
        lcdbuf[i + 1] = ((strbuf[i] & 0x08) >> 3) | ((strbuf[i] & 0x04) >> 1) | ((strbuf[i] & 0x40) >> 4) | ((strbuf[i] & 0x02) << 2);
      }
      for(i = 0; i < 9; ++i) 
      {
        ldat[i] = lcdbuf[i];   
      }
  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END LowFreqSG */
/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.98 [03.80]
**     for the Freescale HC08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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