?? jishu-miao-0-9999999.9.c
字號:
/******************************************************************
* *
* ME500單片機開發系統演示程序 - 0-9999999.9 秒計時 *
* *
* 8位數碼管顯示 *
* *
* 版本: V1.0 (2006/11/20) *
* 作者: gguoqing (Email: gguoqing@willar.com) *
* 網站: www.willar.com(偉納電子) www.mcusj.com(偉納單片機世界) *
* 郵箱: support@willar.com *
* *
*【版權】Copyright(C)偉納電子 www.willar.com All Rights Reserved *
*【聲明】此程序僅用于學習與參考,引用請注明版權和作者信息! *
* *
*******************************************************************/
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar Count;
sbit DIN = P0^7; //小數點
uchar code LEDData[ ] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0xff};
uchar data display[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar code scan_bit[] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
/*********************************************************
延時函數
*********************************************************/
void Delay(uint num)//延時函數
{
while( --num );
}
/********************************************************
顯示函數
*********************************************************/
play()
{
uchar i;
for(i=0;i<8;i++)
{
P0=LEDData[display[i]]; //顯示個位
P2=scan_bit[i];
if(scan_bit[i]==0xbf)
DIN=0; //加小數點
Delay(50);
}
P2=0xff; //關閉顯示
}
/********************************************************
主函數
*********************************************************/
main()
{
P0=0xff;
P2=0xff;
Count=0x00;
TMOD=0x01;
TH0=0x4c; TL0=0x00; //50ms定時
EA=1; ET0=1; TR0=1;
while(1)
play();
}
/*********************************************************
Time0中斷函數
**********************************************************/
void Time0(void) interrupt 1 using 0
{
TH0=0x4c; //50ms定時
TL0=0x00;
Count++;
if(Count==2)
{
Count=0;
display[0]++; //0.1S
}
if(display[0]==10)
{
display[0]=0;
display[1]++; //個位
}
if(display[1]==10)
{
display[1]=0;
display[2]++; //十位
}
if(display[2]==10)
{
display[2]=0;
display[3]++; //百位
}
if(display[3]==10)
{
display[3]=0;
display[4]++; //千位
}
if(display[4]==10)
{
display[4]=0;
display[5]++; //萬位
}
if(display[5]==10)
{
display[5]=0;
display[6]++; //十萬位
}
if(display[6]==10)
{
display[6]=0;
display[7]++; //百萬位
}
if(display[7]==10)
{
display[7]=0;
}
}
/*********************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -