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

📄 jps_tb.c

📁 PIC12F629定时器1工作于异步方式,只要32.768KHz晶振误差5ppm,时间误差小于1秒/月.
💻 C
字号:
/////////////////////////////////////////////////////////////////////////
////                         EX_PATG.C                               ////
////                                                                 ////
////  This program will output multiple square waves from the pins   ////
////  of port b.  The waves can be differnt frequencies, and can be  ////
////  seen by hooking up a scope to any of the pins.                 ////
////                                                                 ////
////  Configure the CCS prototype card as follows:                   ////
////     Connect any of pins 47 through 53 to a scope.               ////
////     See additional connections below.                           ////
////                                                                 ////
////  This example will work with the PCM and PCH compilers.  The    ////
////  following conditional compilation lines are used to include a  ////
////  valid device for each compiler.  Change the device and clock   ////
////  for your hardware if needed.                                   ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////

#include <12f629.h>                   //包含头文件
#use delay(clock=32768)               //使用晶振32.768kHz
#fuses NOWDT,XT, PUT, PROTECT         //不使用看门狗,使用外部晶振,代码保护

#define TIME_LOAD 4000    //65536-(6*32768/4) 6S  定时器装载时间为6S
byte    sys01mincnt, last01mincnt;
//byte  sys10mscnt,sys1scnt,sys1mincnt,last01mincnt,sys01mincnt;
#define LED             PIN_A0
#define MOTOR_Control   PIN_A1
#define SPRING_SWITCH   PIN_A2

/*
#if defined(__PCM__)
#include <12F629.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif*/
/*
#define NUM_OUTPUTS  7

//NOTE:  periods MUST be multiples of 400
//Periods are in microseconds
#define  PERIOD_0 400
#define  PERIOD_1 800
#define  PERIOD_2 1600
#define  PERIOD_3 2000
#define  PERIOD_4 20000
#define  PERIOD_5 64000
#define  PERIOD_6 2000000


const long wave_period[NUM_OUTPUTS] = {
            PERIOD_0/400, PERIOD_1/400, PERIOD_2/400, PERIOD_3/400,
            PERIOD_4/400, PERIOD_5/400, PERIOD_6/400};

long counter[NUM_OUTPUTS] = {0,0,0,0,0,0,0};

int port_b_image;  */


// This interrupt is used to output the waveforms.  The interrupt
// is automatically called ever 200us.
#INT_TIMER1
void wave_timer() {
   int i;

  set_timer0(TIME_LOAD);  //6秒到,重装载Timer0 的值
  if(--sys01mincnt==0){   //sys01mincnt自减后为0吗?为0,则将10送给sys10mscnt
     sys01mincnt=10;       //执行到此,则为1分钟
     if(++last01mincnt>=6){   //last01mincnt自动加1后为6吗?为6,则将sys1scnt清0
        last01mincnt=0;       //执行到此,则为6分钟
        output_high(MOTOR_Control);//马达转动;
     }

  }
}


void main()   {

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);   // setup interrupts
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

  // port_b_image=0;                           // initialize variable
  // output_b(port_b_image);

   while(TRUE);                              // loop forever
}

⌨️ 快捷键说明

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