#include "STC15F2K60S2.h"
#include "onewire.h"
#include "absacc.h"
#include "intrins.h"
typedef unsigned char uchar;
typedef unsigned int uint;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//duan ma
uchar dspbuf[8]={10,10,10,10,10,10,10,10};//huan cong qu
bit temp_flag = 0;//wen du
void Enable(uchar yc);
void cls_buzz();
void cls_led();
void display(void);
void main()
{
char temperature;
cls_buzz();cls_led();
TMOD &= 0xF0; //???????
TL0 = 0xCD; //1ms
TH0 = 0xD4; //??????
TF0 = 0; //??TF0??
TR0 = 1; //???0????
ET0 = 1;
EA = 1;
while(1)
{
if(temp_flag)
{
temp_flag = 0;
temperature = rd_temperature();
}
(temperature > 10) ? (dspbuf[6] = temperature/10) : (dspbuf[6] = 10);
dspbuf[7] = temperature % 10;
}
}
void timer0() interrupt 1
{
static uchar ms=0;
if(++ms == 50)
{
ms = 0;
temp_flag = 1;
}
display();
}
void Enable(uchar yc)
{
switch (yc)
{
case 4:
P2 = (P2 & 0x1f) | 0x80;break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;break;
case 6:
P2 = (P2 & 0x1f) | 0xc0;break;
case 7:
P2 = (P2 & 0x1f) | 0xe0;break;
}
}
void cls_buzz()
{
Enable(5);
P0 = 0x00;
P2 &= 0x1f;
}
void cls_led()
{
Enable(4);
P0 = 0xff;
P2 &= 0x1f;
}
void display(void)
{
static uchar dspcom = 0;
Enable(7);
P0 = 0xff;//xiao yin
P2 &= 0x1f;
P0 = 1<<dspcom;
Enable(6);//wei xuan
P2 &= 0x1f;
Enable(7);//duan xuan
P0 = tab[dspbuf[dspcom]];
P2 &= 0x1f;
if(++dspcom == 8)
dspcom = 0;
}
初學,如有錯誤 請大家多多指教,代碼下載:
my.rar
(80.53 KB, 下載次數: 11)
2021-7-31 10:37 上傳
點擊文件名下載附件
源代碼 下載積分: 黑幣 -5
|