| /******************************************************************** 汇诚科技
 网址:http://www.ourhc.cn
 产品有售淘宝店:http://shop36330473.taobao.com
 *********************************************************************/
 #include<reg52.h>                 //库文件
 #define uchar unsigned char//宏定义无符号字符型
 #define uint unsigned int  //宏定义无符号整型
 /********************************************************************
 初始定义
 *********************************************************************/
 code uchar seg7code[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //显示段码 数码管字跟
 uchar wei[4]={0XEf,0XDf,0XBf,0X7f};  //位的控制端
 uchar dispcount=0; //计数初值
 /********************************************************************
 延时函数
 *********************************************************************/
 void delay(uchar t)
 {
 uchar i,j;
 for(i=0;i<t;i++)
 {
 for(j=13;j>0;j--);
 { ;
 }
 }
 }
 
 /********************************************************************
 显示函数
 *********************************************************************/
 void Led(int date) //显示函数
 {
 /*****************数据转换*****************************/
 uint z,x,c,v;
 z=date/1000;                         //求千位
 x=date%1000/100;                 //求百位
 c=date%100/10;                 //求十位
 v=date%10;                         //求个位
 
 P2=0XFF;
 P0=seg7code[z];
 P2=wei[0];
 delay(80);
 P2=0XFF;
 P0=seg7code[x];
 P2=wei[1];
 delay(80);
 P2=0XFF;
 P0=seg7code[c];
 P2=wei[2];
 delay(80);
 P2=0XFF;
 P0=seg7code[v];
 P2=wei[3];
 delay(80);
 P2=0XFF;
 }
 /********************************************************************
 中断服务函数
 *********************************************************************/
 void ExtInt0() interrupt 0 //中断服务程序
 {
 dispcount++; //每按一次中断按键,计数加一
 if (dispcount==255) //计数范围0-255
 {
 dispcount=0;
 }
 }
 /********************************************************************
 主函数
 *********************************************************************/
 void main()
 {
 TCON=0x01; //中断设置
 IE=0x81;
 while(1)
 {
 Led(dispcount);
 }
 }
 
 
 /********************************************************************
 结束
 *********************************************************************/
 
 
 
 
 |