Demo entry 6349696

c

   

Submitted by anonymous on Feb 26, 2017 at 17:10
Language: C. Code size: 763 Bytes.

#include <reg52.h> //包含头文件
unsigned char code dis_code[8]={0x90,0xF9,0xB0,0xB0,0xF9,0xF8,0x80,0x92};//段码
int count=0,k=0;//定义计数器变量和指针变量
void main(void) 
{
   P2=0xFF;	//数码管初始状态,不显示数字
   TMOD = 0x01;  //设置定时器0工作模式1
   TH0 = 0x3C; 	//定闹钟,50ms响一次
   TL0 = 0x0B0; 
   EX0=1;	//开启外部中断INT0使能
   IT0=1;	//开启INT0下降沿触发
   EA = 1;	//开启总中断				
   ET0 = 1; 	//开启定时器中断
   TR0 = 1; 	//开启定时器
   while(1){ 
   }
} 
//外部中断函数
void outItrpt() interrupt 0
{
   TR0=~TR0;	//当外部中断被触发,定时器开关状态取反
}
//定时器中断函数
void Timer0Interrupt() interrupt 1 
{
	TH0 = 0x3C; 	//重新定闹钟 
	TL0 = 0x0B0;
	count++; 	//记一次数
	if(count==10){ 	//判断是否到了500ms
	   P2=dis_code[k];	//显示当前k指向的段码
	   k++;		//k指向下一位
	   if (k==8){	//当k>7时,k清零
	   k=0;
	   }
	  count=0;	//重新计数
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).