PIC单片机定时器的使用(16F877)

/*******************************************/
//功能:60倒计时,蜂鸣器以及数码管的使用
//开发板:PIC16F877
/*******************************************/

include

define uchar unsigned char

define uint unsigned int

void delay(uchar a,uchar x);
uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x00};//数组
uchar LED[3];
void init();//初始化函数
void interrupt TMRO();//TMRO中断函数
uint counter;
uchar tmro_counter;
void LED_DISP();//数码管的显示函数
main()
{
init();
counter=60;
while(1)
{
//counter=60;
LED[1]=(uchar)(counter/10);
LED[2]=(uchar)(counter%10);
LED_DISP();
//counter–;
//if(counter==0)
//RE0=1;
}
}

void init()
{
TRISC=0X00;
TRISA=0X00;
TRISD=0X00;
PORTD=0XFF;
TRISE=0x00;
RC5=0;
OPTION_REG=0X07;//256分频
TMR0=61;
INTCON=0Xa0;
}
void interrupt TMRO()
{
TMR0IF=0;
//TMR0=158;
tmro_counter++;
if(tmro_counter==20)
{
tmro_counter=0;
tmro_counter++;
counter–;
if(counter==0)
RE0=1;
}
TMR0=61;
}
void LED_DISP()
{
uchar timer=0;
uchar temp=0x80;
RA3=0;
//for(k=0;k<=50;k++)
for(timer=1;timer<=2;timer++)
{
RC4=1;
PORTD=temp;
RC4=0;
RC3=1;
PORTD=table[LED[timer]];
RC3=0;
temp>>=1;
delay(10,10);
RC4=1;
PORTD=0X00;
RC4=0;
delay(1,10);
}
}
/***********************
/*延迟函数***
/************************
void delay(uchar a,uchar x)
{
while(–a)
while(–x);
}

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小刘同学要加油呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值