九游娱乐-礣*bg炻刐0BH?W?6處焇N拁鏢W兑I

田径赛事 8℃ 3

  要使用PIC的 TIMER0,首先需要看数据手册,熟悉寄存器配置

  这里需要用到OPTION,九游娱乐INTCON的配置,还有TMR0计数值的预置。

  

礣*bg炻刐0BH?W?6處焇N拁鏢W兑I<炷€xm5墂	婆帐脀x欉o萏6騇?$%

  

  

  典型应用程序:利用定时中断实现发光管一闪一闪功能。

  源程序:

  #include <pic.h>

  #define uchar unsigned char

  #define uint unsigned int

  #define LED1 RC0

  ///////////////////////初始化设置程序////////////////////////////////

  void Init(void)

  {

  PORTA = 0B00000000;

  PORTB = 0B00000000;

  PORTC = 0B00000000;

  TRISA = 0B00000000;//设置PORTA口为输出

  TRISB = 0B00000001;//设置RB0为输入,作为按键口

  TRISC = 0B00000000;//设置RC输出

  ADCON1=0B11111111;//设置为数字I/O

  counter=0;

  OPTION=0B01010011;//配置中断和定时器0

  TMR0=5;

  T0IE=1;//使能定时器中断0

  GIE=1; //全局中断使能

  }

  ///////////////////////定时中断程序////////////////////////////////

  void interrupttimer0_int(void)

  {

  T0IF=0;//清除中断标志位

  TMR0=5; //重新设置定时器时间

  counter++;

  if(counter==250)

  {

  counter=0;

  LED1=!九游体育下载LED1;

  }

  }

  ///////////////////////主程序////////////////////////////////

  void main (void)

  {

  Init();//初始化程序

  PORTC=0XFF;

  PORTB=0XFF;

  while(1);

  }

  原文链接:https:九游体育官网//www.eeworld.com.cn/mcu/article_2016090529078.html

3 条评论

  1. 周敏远
    2024-11-02 04:40:09
    Great value for the price. Will definitely buy again. Fast shipping and great customer service. Very happy with my purchase.
  1. 郭莉豪
    2024-11-18 03:16:57
    已经多次购买了,一如既往的好,值得信赖的商家。 性价比很高,用了一段时间没有任何问题,点赞!
  1. 邓宇豪
    2024-11-27 15:44:59
    This is my third time ordering from this seller, and they never disappoint. Absolutely love this product! It's exactly what I needed and works perfect

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
*
*