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

yuming 49 2026-05-14 04:25:16

  要使用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

上一篇:金年会平台-包含欧篮联倒计时,皇家社会集结日内部沟通,细节引发关注,气氛紧张,控场能力受关注的词条
下一篇:金年会中国官网-关于尻?忤~枾眐檊钸r屲米?楧倔?x腈?n辥?﹚K??骰 LU?6紃T?4H?徺Y鑵;?喑CX藏老熩瑙IR慈?蜃剦嚃僷G曢u+炙HF,?轫4絪?璼{瞻━#寧惮的信息
相关文章

 发表评论

评论列表

2025-02-17 19:00:50

Great value for the price. Will definitely buy again. This is my third time ordering from this seller, and they never disappoint.

2025-04-24 13:51:27

Fast shipping and great customer service. Very happy with my purchase. Fast shipping and great customer service. Very happy with my purchase.

2025-03-28 06:41:42

已经多次购买了,一如既往的好,值得信赖的商家。 已经多次购买了,一如既往的好,值得信赖的商家。

返回顶部小火箭