蓝桥杯第十三届程序题

蓝桥杯第十三届程序题

赛题要求
可以见我另一个博客

赛题

程序主要代码

void main()
{
	ALL_Init();
	Timer1Init();
	parameter = 23;
	Set_time(23,59,50);
	rd_temperature();
	Delay800ms();
	rd_temperature();
	while(1)
	{
		Read_time();	
		rd_temperature();

		Key16_Proc();
		SHOW_VIEW();
		LED_CHOOSE();
		MODE_CHOOSE();
		DISPLAY_1SMG(zero, one);
		DISPLAY_2SMG(two, three);
		DISPLAY_3SMG(four, five);
		DISPLAY_4SMG(six, seven);
	}
}

数码管模块


void DISPLAY_1SMG(uchar zero, uchar one)
{
	P2 = 0xC0; P0 = weiduan[0];
	P2 = 0xFF; P0 = smgduan[zero];
	Delay1ms();
	P2 = 0xC0; P0 = weiduan[1];
	P2 = 0xFF; P0 = smgduan[one];
	Delay1ms();
}
void DISPLAY_2SMG(uchar two, uchar three)
{
	P2 = 0xC0; P0 = weiduan[2];
	P2 = 0xFF; P0 = smgduan[two];
	Delay1ms();
	P2 = 0xC0; P0 = weiduan[3];
	P2 = 0xFF; P0 = smgduan[three];
	Delay1ms();
}
void DISPLAY_3SMG(uchar four, uchar five)
{
	P2 = 0xC0; P0 = weiduan[4];
	P2 = 0xFF; P0 = smgduan[four];
	Delay1ms();
	P2 = 0xC0; P0 = weiduan[5];
	P2 = 0xFF; P0 = smgduan[five];
	Delay1ms();
}
void DISPLAY_4SMG(uchar six, uchar seven)
{
	P2 = 0xC0; P0 = weiduan[6];
	P2 = 0xFF; 
	if(dot==0)
		P0 = smgduan[six];
	else if(dot==1)
		P0 = smgduan[six]&0x7f;
	Delay1ms();
	P2 = 0xC0; P0 = weiduan[7];
	P2 = 0xFF; P0 = smgduan[seven];
	Delay1ms();
	P2 = 0xC0; P0 = 0xff;
	P2 = 0xff; P0 = 0xff;
}



void Delay1ms()		//@12.000MHz
{
	unsigned char i, j;

	i = 12;
	j = 169;
	do
	{
		while (--j);
	} while (--i);
}

ds18b20模块

#include "onewire.h"
unsigned char temp,xiaoshu;
//单总线内部延时函数
void Delay_OneWire(unsigned int t)  
{
	while(t--);
}

//单总线写操作
void Write_DS18B20(unsigned char dat)
{
	unsigned char i;
	for(i=0;i<8;i++)
	{
		DQ = 0;
		DQ = dat&0x01;
		Delay_OneWire(50);
		DQ = 1;
		dat >>= 1;
	}
	Delay_OneWire(50);
}

//单总线读操作
unsigned char Read_DS18B20(void)
{
	unsigned char i;
	unsigned char dat;
  
	for(i=0;i<8;i++)
	{
		DQ = 0;
		dat >>= 1;
		DQ = 1;
		if(DQ)
		{
			dat |= 0x80;
		}	    
		Delay_OneWire(50);
	}
	return dat;
}

//DS18B20初始化
bit init_ds18b20(void)
{
  	bit initflag = 0;
  	
  	DQ = 1;
  	Delay_OneWire(120);
  	DQ = 0;
  	Delay_OneWire(800);
  	DQ = 1;
  	Delay_OneWire(100); 
    initflag = DQ;     
  	Delay_OneWire(50);
  
  	return initflag;
}
void rd_temperature()
{
	unsigned char Htemp,Ltemp;

	init_ds18b20();
	Write_DS18B20(0xcc);
	Write_DS18B20(0x44);
	init_ds18b20();
	Write_DS18B20(0xcc);
	Write_DS18B20(0xBE);
	Ltemp = Read_DS18B20();
	Htemp = Read_DS18B20();

	temp = Htemp *16 + Ltemp/16;//问题2
	xiaoshu = (Ltemp&0x0f)*10/16;//问题3
}

ds1302模块

#include "ds1302.h"  									
unsigned char rhour,rmin,rsec;
void Set_time(unsigned char hour,unsigned char min,unsigned char sec)
{
	Write_Ds1302_Byte(0x8E,0x00);//问题4
	Write_Ds1302_Byte(0x80,sec);
	Write_Ds1302_Byte(0x82,min);
	Write_Ds1302_Byte(0x84,hour);
	Write_Ds1302_Byte(0x8E,0x80);
}
void Read_time()
{
	Write_Ds1302_Byte(0x8E,0x00);
	rsec = Read_Ds1302_Byte(0x81);
	rmin = Read_Ds1302_Byte(0x83);
	rhour = Read_Ds1302_Byte(0x85);
	Write_Ds1302_Byte(0x8E,0x80);
}

//写字节
void Write_Ds1302(unsigned  char temp) 
{
	unsigned char i;
	for (i=0;i<8;i++)     	
	{ 
		SCK = 0;
		SDA = temp&0x01;
		temp>>=1; 
		SCK=1;
	}
}   

//向DS1302寄存器写入数据
void Write_Ds1302_Byte( unsigned char address,unsigned char dat )     
{
	unsigned char num,dat1,dat2;
 	RST=0;	_nop_();
 	SCK=0;	_nop_();
 	RST=1; 	_nop_();  
 	Write_Ds1302(address);	
	dat1 = dat / 10;
	dat2 = dat % 10;      //问题5
	num = dat1 * 16 + dat2;
 	Write_Ds1302(num);//问题6
 	RST=0; 
}

//从DS1302寄存器读出数据
unsigned char Read_Ds1302_Byte ( unsigned char address )
{
 	unsigned char i,temp=0x00;
	unsigned char num,dat1,dat2;
 	RST=0;	_nop_();
 	SCK=0;	_nop_();
 	RST=1;	_nop_();
 	Write_Ds1302(address);
 	for (i=0;i<8;i++) 	
 	{		
		SCK=0;
		temp>>=1;	
 		if(SDA)
 		temp|=0x80;	
 		SCK=1;
	} 
 	RST=0;	_nop_();
 	SCK=0;	_nop_();
	SCK=1;	_nop_();
	SDA=0;	_nop_();
	SDA=1;	_nop_();
	dat1 = temp / 16;
	dat2 = temp % 16;
	num = dat1 * 10 + dat2;
	return (num);			
}

##总结
希望这代码可以帮助大家
想要源程序的可以打开这个链接
代码链接

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值