seg显示时间——51程序
生活随笔
收集整理的這篇文章主要介紹了
seg显示时间——51程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#include #define SEGPORT P0sbit bit_select = P2 ^ 0; //p2 ^ 0控制位選鎖存器,位選鎖存器選定 數(shù)碼管
sbit seg_select = P2 ^ 1; //p2 ^ 1控制段選鎖存器,段選鎖存器選定 數(shù)碼管的內(nèi)容(并顯示內(nèi)容)。 unsigned char segdata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char tempdata[8] = 0x0;
unsigned char shi = 23;
unsigned char fen = 59;
unsigned char miao = 50;
unsigned int count = 0;void display() //顯示刷新函數(shù)
{static unsigned char i = 0;SEGPORT = 0x0; //清屏操作,消除重影seg_select = 1;seg_select = 0;SEGPORT = 0xff;bit_select = 1;bit_select = 0;SEGPORT = bitdata[i]; //選定并顯示特定數(shù)碼管的內(nèi)容bit_select = 1;bit_select = 0;SEGPORT = tempdata[i];seg_select = 1;seg_select = 0;i++;if(i == 8){i = 0;}
}void timer0_init(void) //定時器中斷0,計算時間,優(yōu)先級大于中斷1
{EA = 1;TMOD = 0x01;TH0 = (65536 - 2000) / 256;TL0 = (65536 - 2000) % 256;ET0 = 1;TR0 = 1;
}void timer1_init(void) //定時器中斷1,顯示時間
{EA = 1;TMOD = 0x11;TH1 = (65536 - 2000) / 256;TL1 = (65536 - 2000) % 256;ET1 = 1;TR1 = 1;
}void main()
{timer0_init();timer1_init();while(1);
}void timer0_isr() interrupt 1
{ TH0 = (65536 - 2000) / 256;TL0 = (65536 - 2000) % 256;count++;if(500 == count){ count = 0;miao++;if(60 == miao){miao = 0;fen++;}if(60 == fen){fen = 0;shi++;}if(24 == shi){shi = 0;}}tempdata[0] = segdata[shi / 10];tempdata[1] = segdata[shi % 10];tempdata[2] = 0x40;tempdata[3] = segdata[fen / 10];tempdata[4] = segdata[fen % 10];tempdata[5] = 0x40;tempdata[6] = segdata[miao / 10];tempdata[7] = segdata[miao % 10];
}void timer1_isr() interrupt 3
{TH1 = (65536 - 2000) / 256;TL1 = (65536 - 2000) % 256;display();
}
總結(jié)
以上是生活随笔為你收集整理的seg显示时间——51程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 任务——μ/COS-II读书笔记
- 下一篇: 外部中断0——51程序