第六届的试题涉及到ds1302,ds18b20,led,数码管和独立按键。大致题目如下
我用了两个定时器,一个用于提示符的闪烁,一个用于采集温度传感器的值(其实用一个也可以),其他也...没啥难点吧,主要是会用这些模块。
#include <reg52.h>
#include "iic.h"
#include "ds1302.h"
#include "onewire.h"
#define uchar unsigned char
sfr AUXR=0x8e;
sbit beep=P0^6;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar a[10]={0,0,0,0,0,0,0,0,0,0};
uchar write[]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
uchar read[]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar time[]={0x50,0x59,0x23,0x17,0x02,0x06,0x18};
uchar t=0,t1,t2=0;
uchar num=0,num1=0,jici=0,jici1=0;
void delay(int x)
{
while(x--);
}
void delay10ms(uchar x)
{
unsigned char i, j;
while(x--)
{
i = 117;
j = 184;
do
{
while (--j);
} while (--i);
}
}
void Timer0Init(void) //5毫秒@12.000MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD = 0x00; //设置定时器模式
TL1 = 0xA0; //设置定时初值
TH1 = 0x15; //设置定时初值
TL0 = 0xA0; //设置定时初值
TH0 = 0x15; //设置定时初值
TF0 = 0; //清除TF0标志
TF1=0;
TR0 = 1; //定时器0开始计时
TR1= 1;
ET0=0;
ET1=0;
EA=1;
}
void cls_buzz()
{
P2=(P2&0x1f)|0xa0;
beep=0;
P2&=0X