蓝桥杯赛前总结

考完了,底层什么的都还ok,就是碰到了没碰过的NE555 哭死,功能就写了一半,还有一半没法写,其实还挺简单的,虽然我没写完。。。


明天就要比赛了
不要急,目的不是比赛,目的是学知识,紧张状态下学习效率更高
再总结一下
1.准备三部曲
建立文件夹建立project,source,output
以管理员身份打开keil,设置输出和模式
写config配置文件,main.c

2.关于keyboard.c

  1. void KeyScan()两个static

在这里插入图片描述
慢慢写不要写错在这里插入图片描述

  1. void KeyDriver()
    在这里插入图片描述
    别忘了!!
    3.关于led.c
    段码再背一次{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}
    在这里插入图片描述
    再写个ShowNumber()检验数码管

4.main函数
先把主要框架搭起来
定时器配置
在这里插入图片描述
5.iic底层
官方驱动改过了可以使用
直接拖官方驱动改名字就行了

6.eeprom底层
两个函数
eepromwrite()和eepromread()
在这里插入图片描述
在这里插入图片描述

eeprom的写指令是0xA0
读指令是0xA1
eeprom写完数据之后要延时10ms
在iic里加入延时程序调用
void delayms(unsigned int t)
{
unsigned int i,j;
for(i=t;i>0;i–)
for(j=123;j>0;j–);
}
11.0592是 114

7.pcf8591底层
void PCF8591_init(u8 channel)
{
I2C_Start(); //启动IIC
I2C_SendByte(0x90); //激活该器件写操作
I2C_WaitAck(); //等待应答
I2C_SendByte(channel); //发送通道
I2C_WaitAck(); //等待应答
I2C_Stop(); //关闭IIC
Delay10ms();

}

u8 ReadADCValue()
{
u8 vo;
I2C_Start(); //启动IIC
I2C_SendByte(0x91); //激活该器件读操作
I2C_WaitAck(); //等待应答
vo = I2C_RecByte(); //读取该值
I2C_Ack(0); //应答0
I2C_Stop();
return vo;
}
pcf8591器件写是0x90
读是0x91
8.DS1302
single写是reg<<1|0x80
读是reg<<1|0x81

brust写是0xbe
读是0xbf

#include "config.h"
#include "ds1302.h"

void DS1302ByteWrite(u8 dat)
{
	u8 mask;
	for(mask=0x01;mask!=0;mask<<=1)
	{
		if((mask&dat)!=0)
			DS1302_IO=1;
		else
			DS1302_IO=0;
		DS1302_CK=1;
		DS1302_CK=0;
	}
	DS1302_IO=1;//释放引脚
	
}

u8 DS1302ByteRead()
{
	u8 mask;
	u8 dat=0;

	for(mask=0x01;mask!=0;mask<<=1)
	{
		if(DS1302_IO!=0)
			dat|=mask;
		DS1302_CK=1;
		DS1302_CK=0;
	}
	return dat;
		
}

void DS1302SingleWrite(u8 reg,u8 dat)
{
	DS1302_CE=1;
	DS1302ByteWrite((reg<<1)|0x80);
	DS1302ByteWrite(dat);
	DS1302_CE=0;
		
}

u8 DS1302SingleRead(u8 reg)
{
	u8 dat=0;
	DS1302_CE=1;
	DS1302ByteWrite((reg<<1)|0x81);
	DS1302ByteWrite(dat);
	DS1302_CE=0;
	DS1302_IO=1;//软件调整,必写

	return dat;

}

void Brust_Write(u8* dat)
{
	u8 i;
	DS1302_CE=1;
	DS1302ByteWrite(0xbe);
	for(i=0;i<8;i++)
	{
		DS1302ByteWrite(*dat++);	
	}
	DS1302_CE=0;
	

} 

void Brust_Read(u8 *dat)
{
	u8 i;
	DS1302_CE=1;
	DS1302ByteWrite(0xbf);
	for(i=0;i<8;i++)
	{
		dat[i]=DS1302ByteRead();	
	}
	DS1302_CE=0;
} 

void GetRealTime(struct sTime *Time)
{
	u8 buff[8];

	Brust_Read(buff);
	Time->year  = buff[6];
	Time->month = buff[4];
	Time->day   = buff[3];
	Time->hour  = buff[2];
	Time->min   = buff[1];
	Time->sec   = buff[0];
	Time->week  = buff[5];
}

void SetRealTime(struct sTime *Time)
{
	u8 buff[8];

	buff[7]=0;
	buff[6]=Time->year;
	buff[4]=Time->month;
	buff[3]=Time->day;
	buff[2]=Time->hour;
	buff[1]=Time->min;
	buff[0]=Time->sec;
	buff[5]=Time->week;
	Brust_Write(buff);

}

void DS1302_Init()
{
	struct sTime InitTime={
	0x19,0x02,0x16,0x08,0x30,0x00,0x06};

	DS1302_CE = 0;
	DS1302_CK = 0;
	DS1302SingleWrite(7,0x00);
	SetRealTime(&InitTime);

}

9.DS18b20

#include "config.h"


#include <intrins.h>


void Delayus(u8 us)
{
	do{
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	}while(--us);
}

bit GetDs18b20Ack()
{
	bit Ack;
	EA=0;
	IO_18B20=0;
	Delayus(250);
	Delayus(250);
	IO_18B20=1;
	Delayus(60);
	Ack=IO_18B20;
	while(!IO_18B20);
	EA=1;

	return Ack;
}

void Write_18b20(u8 dat)
{
	u8 mask;

	EA=0;
	
	for(mask=0x01;mask!=0;mask<<=1)
	{
		IO_18B20=0;
		Delayus(2);
		if((dat&mask)==0)
			IO_18B20=0;
		else
			IO_18B20=1;
		Delayus(60);
		IO_18B20=1;
				
	}
	EA=1;
	
}

u8 Read_18b20()
{
	u8 dat=0;
	u8 mask;

	EA=0;
	for(mask=0x01;mask!=0;mask<<=1)
	{
		IO_18B20=0;
		Delayus(2);
		IO_18B20=1;
		Delayus(2);
		if(IO_18B20)
		{	
			dat|=mask;
		}
		Delayus(60);
	}
	EA=1;

	return dat;
}

bit Start18b20()
{
	bit ack;

   	ack=GetDs18b20Ack();
	
	if(ack==0)
	{
		
		Write_18b20(0xcc);
		
		Write_18b20(0x44);
			
	}
	
	
	
	return ~ack;
	
}

bit Get18b20Temp(int *temp)
{
	bit ack;
	u8 LSB,MSB;
	
	ack=GetDs18b20Ack();
	
	if(ack==0)
	{
		Write_18b20(0xcc);
		Write_18b20(0xbe);
		LSB=Read_18b20();
		MSB=Read_18b20();
		*temp=((int)MSB<<8)+LSB;
	}

	return ~ack;

	
}

猜你喜欢

转载自blog.csdn.net/qq_41262681/article/details/88768029