#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
typedef unsigned int INT16U;
#define MAIN_Fosc 11059200UL
sbit wela = P2^7;
sbit dula = P2^6;
sbit ds = P2^2;
void Display(INT16U Value);
uchar read_byte();
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x40,0x80,0x00};
void Delay_Ms(uint ms)
{
uint i;
do{
i = MAIN_Fosc / 96000;
while(--i); //96T per loop
}
while(--ms);
}
void Display(INT16U Value)
{
dula=0;
P0=table[Value/100];
dula=1;
//°Ùλ
dula=0;
wela=0;
P0=0xfe;
wela=1;
wela=0;
Delay_Ms(3);
dula=0;
P0=table[Value%100/10] | 0x80 ;
dula=1;
//ʮλ
dula=0;
wela=0;
P0=0xfd;
wela=1;
wela=0;
Delay_Ms(3);
dula=0;
P0=table[Value%10];
dula=1;
//¸öλ
dula=0;
wela=0;
P0=0xfb;
wela=1;
wela=0;
Delay_Ms(3);
}
void Delay_us(uchar us)
{
while(us--);
}
bit ds_init()
{
bit i;
ds=1;
_nop_();
ds = 0;
Delay_us(75);
ds = 1; //ÊÍ·Å×ÜÏß
Delay_us(4);
i=ds;
Delay_us(20);
ds=1;
_nop_();
return(i);
}
void Write_Byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
ds=0;
_nop_();
ds= dat & 0x01;
Delay_us(10);
ds=1;
_nop_();
dat >>= 1;
}
}
uchar read_byte()
{
uchar i,j,dat;
for(i=0;i<8;i++)
{
ds=0;
_nop_();
ds=1;
_nop_();
j=ds;
Delay_us(10);
ds=1;
_nop_();
dat =(j<<7) | (dat>>1);
}
return(dat);
}
void main()
{
uchar L,M;
uint i,t;
ds_init();
Write_Byte(0xcc); //ÌøÔ¾Ö¸Áî
Write_Byte(0x4e); //дÔÝ´æÆ÷Ö¸Áî
Write_Byte(0x7f); //ÉÏÏÞ
Write_Byte(0xf7); //ÏÂÏÞ
Write_Byte(0x1f); //ÅäÖþ«¶È
ds_init();
Write_Byte(0xcc);
Write_Byte(0x48);
while(1);
{
ds_init();
Write_Byte(0xcc);
Write_Byte(0x44);
ds_init();
Write_Byte(0xcc);
Write_Byte(0xbe);
L = read_byte();
M = read_byte();
i=M;
i<<=8;
t = i |L;
t = t * 0.0625 * 10 + 0.5;
Display(t);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>