老师一枚,服务于学生,制作了电子时钟融合温度检测的系统。
首先在焊接式前一定要仿真,更要注意仿真引脚和实际引脚的不同。
个人中心里面有常用元器件实物引脚图和解释。
参考代码:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit sounder=P3^7;
sbit qiehuan=P1^5;
sbit jia=P1^6;
sbit jian=P3^0;
sbit DS=P3^6;
sbit LED1 = P3^4;
sbit LED2 = P3^5;
sbit LED3 = P1^2;
sbit LED4 = P1^4;
sbit anjian=P1^0;
uint temp;
uchar flag1;
uint a,b;
uchar d=0; // 切换标志位
uchar hour0,minu0,sec0,hour1,minu1,sec1,h1,h2,m1,m2,s1,s2,k,s;
unsigned char code select[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳极数码管
unsigned char code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02, //带小数点数字
0x78,0x00,0x10};
void DDDD(void);
void keyscan();
void init();
void delay(uchar z);
void display(uchar,uchar,uchar);
void sounde();
void delay1(unsigned int count);
void dsreset(void);
void tmpwritebyte(unsigned char dat);
void tmpchange(void);
void dis(unsigned int temp);
void AAAA(void);
void main()
{
init();
while(1)
{
if(anjian==0)
{
delay(10);
while(anjian==0);
DDDD();
}
keyscan();
while(s==1)
{
keyscan();
display(hour1,minu1,sec1);
}
display(hour0,minu0,sec0);
}
}
void init()
{
a=0;
b=0;
s=0;
hour0=0;
minu0=0;
sec0=0;
hour1=0;
minu1=0;
sec1=0;
TMOD=0x11;
TH1=(65536-50000)/256; //50ms
TL1=(65536-50000)%256;
EA=1;
EX1=1;
E