標(biāo)題:
TX-1C開發(fā)板--Proteus平臺(tái)下單片機(jī)動(dòng)態(tài)數(shù)碼管掃描之計(jì)數(shù)器程序
[打印本頁]
作者:
颯颯颯颯
時(shí)間:
2020-3-5 17:03
標(biāo)題:
TX-1C開發(fā)板--Proteus平臺(tái)下單片機(jī)動(dòng)態(tài)數(shù)碼管掃描之計(jì)數(shù)器程序
教材上面的程序好像不能實(shí)現(xiàn)數(shù)碼管59s計(jì)數(shù)的功能,經(jīng)過一些資料查詢,修改了教材上的程序,比較好的實(shí)現(xiàn)數(shù)碼管的計(jì)數(shù)。(消影。。。
程序自己寫的。因?yàn)榉抡嫫脚_(tái)不是我自己搭的,所以不能分享出來哈(不能侵權(quán)嘻嘻。
希望幫助到有需要的人哈!!
1583398897(1).jpg
(8.92 KB, 下載次數(shù): 40)
下載附件
2020-3-5 17:02 上傳
單片機(jī)源程序如下:
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit DULA = P2^6;
sbit WELA = P2^7;
sbit Led1 = P1^0;
/*字符編碼0-F共16個(gè)*/
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
/*數(shù)碼管位編碼*/
uchar code tablewe[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf
};
/*變量聲明和初始化*/
uint shi,ge,num0,num1,num;
/*延時(shí)函數(shù)聲明*/
void delay_ms(uint xms); // 實(shí)現(xiàn)延時(shí)xms毫秒
/*數(shù)碼管顯示函數(shù)*/
void display(uint shi,uint ge);
void main(void)
{
/*寄存器初始化*/
TMOD = 0x11; // 設(shè)置定時(shí)器0/1的工作方式
TH0 = (65536-45872)/256; // 計(jì)數(shù)器的初值
TL0 = (65536-45872)%256;
TH1 = (65536-45872)/256;
TL1 = (65536-45872)%256;
EA = 1; // 使能總中斷
ET0 = 1; // 開啟定時(shí)器中斷
ET1 = 1;
TR0 = 1; // 啟動(dòng)定時(shí)器
TR1 = 1;
// WELA=1;
// P0=0xfc;
// WELA=0;
// DULA=1;
// P0=0x3f;
// DULA=0;
while(1)
{
// WELA=1;
// P0=0xfe;
// WELA=0;
//
// P0=0xff;
//
// DULA=1;
// P0=0x3f;
// DULA=0;
//
// P0=0xff;
//
// delay_ms(1);
//
// WELA=1;
// P0=0xfd;
// WELA=0;
//
// P0=0xff;
//
// DULA=1;
// P0=table[ge];
// DULA=0;
//
// P0=0xff;
// delay_ms(1);
display(shi,ge);
}
}
void delay_ms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--); // 通過斷點(diǎn)測(cè)試,該語句執(zhí)行完約1ms
}
void display(uint shi,uint ge)
{
/*第一個(gè)數(shù)碼管顯示十位*/
WELA = 1;
P0 = tablewe[0];
WELA = 0;
P0 = 0xff; // “消影”
DULA = 1;
P0 = table[shi];
DULA = 0;
P0 = 0xff; // “消影”
delay_ms(5);
/*第一個(gè)數(shù)碼管顯示個(gè)位*/
WELA = 1;
P0 = tablewe[1];
WELA = 0;
P0 = 0xff; // “消影”
DULA = 1;
P0 = table[ge];
DULA = 0;
P0 = 0xff; // “消影”
delay_ms(5);
}
void Tim0() interrupt 1
{
TH0 = (65536-45872)/256; // 重裝初值
TL0 = (65536-45872)%256;
num0++;
if(num0 == 4)
{
num0 = 0;
Led1 = ~Led1;
}
}
void Tim1() interrupt 3
{
TH1 = (65536-45872)/256; // 重裝初值
TL1 = (65536-45872)%256;
num1++;
if(num1 == 20)
{
num1 = 0;
num++;
if(num == 60)
num = 0;
shi = num/10;
ge = num%10;
}
}
復(fù)制代碼
所有資料51hei提供下載:
text_TimerAndInterrupt.rar
(28.02 KB, 下載次數(shù): 5)
2020-3-5 17:02 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1