DHT11模块

LCD模块

LCD模块显示一个字符编程

#include "reg52.h"
#include "intrins.h"

#define databuffer P0  //注意不带分号
sbit RS  = P1^1;
sbit RW  = P1^2;
sbit EN  = P1^3;


void Delay15ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 27;
	j = 226;
	do
	{
		while (--j);
	} while (--i);
}

void Delay5ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 9;
	j = 244;
	do
	{
		while (--j);
	} while (--i);
}

void Check_Busy()
{
	
		 char tmp   = 0x80;
					databuffer = 0x80;
		
		 while(tmp & 0x80){
		 RS = 0;
		 RW = 1;
		 EN = 0;
		 _nop_();
		 EN = 1;
		 _nop_();
		 _nop_();
		 
		 tmp = databuffer;
		 _nop_();
		 
			EN = 0;  //状态2前面添加这两条语句即可。
			 _nop_(); //_nop_();
		 }
}





void Write_Cmd_Func(char Position)
{
	 Check_Busy();
   RS = 0;         //写指令即,数据a要显示的地址
	
	 RW = 0;
	 EN = 0;
	 _nop_();
	 
	databuffer = Position; //数据传输点。在写操作下,处于EN = 1前面。
	_nop_();
	
	 EN = 1;       //状态2前面添加这两条语句即可。
	_nop_();
	_nop_();
	 EN = 0;
	_nop_();

}

void Write_Data_Func(char ShowData)
{
	   Check_Busy();
		 RS = 1;              //写数据a
		
		 RW = 0;
		 EN = 0;
		 _nop_();
		 databuffer = ShowData; //数据传输点。在写操作下,处于EN = 1前面。
	   _nop_();
		 EN = 1;
		_nop_();
		_nop_();
		 EN = 0;
		_nop_();

}

void LCD_1602_Init()
{
	
		Delay15ms();
		Write_Cmd_Func(0x38);
		Delay5ms();
		Write_Cmd_Func(0x38);
		Write_Cmd_Func(0x08);
		Write_Cmd_Func(0x01);
		Write_Cmd_Func(0x06);
		Write_Cmd_Func(0x0c);  //0x0c
	
}

void main()
{
		 char Position = 0x80+0x04;
		 char ShowData = 'A';
		 LCD_1602_Init();
		 Write_Cmd_Func(Position);
		 Write_Data_Func(ShowData);	
	
}

LCD模块显示一个字符串

#include "reg52.h"
#include "intrins.h"

#define databuffer P0
//注意不带分号
sbit RS  = P1^1;
sbit RW  = P1^2;
sbit EN  = P1^3;


void Delay15ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 27;
	j = 226;
	do
	{
		while (--j);
	} while (--i);
}

void Delay5ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 9;
	j = 244;
	do
	{
		while (--j);
	} while (--i);
}

void Check_Busy()
{
	
		 char tmp   = 0x80;
					databuffer = 0x80;
		
		 while(tmp & 0x80){
		 RS = 0;
		 RW = 1;
		 EN = 0;
		 _nop_();
		 EN = 1;
		 _nop_();
		 _nop_();
		 
		 tmp = databuffer;
		 _nop_();
		 
			EN = 0;  //状态2前面添加这两条语句即可。
			 _nop_(); //_nop_();
		 }
}





void Write_Cmd_Func(char Position)
{
	 Check_Busy();
   RS = 0;         //写指令即,数据a要显示的地址
	
	 RW = 0;
	 EN = 0;
	 _nop_();
	 
	databuffer = Position; //数据传输点。在写操作下,处于EN = 1前面。
	_nop_();
	
	 EN = 1;       //状态2前面添加这两条语句即可。
	_nop_();
	_nop_();
	 EN = 0;
	_nop_();

}

void Write_Data_Func(char ShowData)
{
	   Check_Busy();
		 RS = 1;              //写数据a
		
		 RW = 0;
		 EN = 0;
		 _nop_();
		 databuffer = ShowData; //数据传输点。在写操作下,处于EN = 1前面。
	   _nop_();
		 EN = 1;
		_nop_();
		_nop_();
		 EN = 0;
		_nop_();

}

void LCD_1602_Init()
{
	
		Delay15ms();
		Write_Cmd_Func(0x38);
		Delay5ms();
		Write_Cmd_Func(0x38);
		Write_Cmd_Func(0x08);
		Write_Cmd_Func(0x01);
		Write_Cmd_Func(0x06);
		Write_Cmd_Func(0x0c);  //0x0c
	
}

 void LCD1602_ShowData_Line(int row,int col,char* string)
{
   switch(row){
		        

		case 1: 
			   Write_Cmd_Func(0x80+col);   //确定第一行的首字母位置,其他依次写入即可,即多次调用Write_Data_Func()函数即可。
		     while(*string){
            Write_Data_Func(*string);
            string++;					 
         }
		   break;
			
		case 2:
			  Write_Cmd_Func(0x80+0x40+col);
		     while(*string){
            Write_Data_Func(*string);
            string++;					 
         }
           break;
  }
}

void main()
{
		
		 LCD_1602_Init();
	   LCD1602_ShowData_Line(1,5,"Hello World!");
}

DHT11模块

1.检测DHT11是否存在的方法

方法一编程实现(不用看)

#include "reg52.h"
#include "intrins.h"

sbit LED1 = P3^6;
sbit DHT  = P1^0;

void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 85;
	j = 12;
	k = 155;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


void Delay30ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 2;
	j = 67;
	k = 183;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay40us()		//@11.0592MHz
{
	unsigned char i;

	i = 108;
	while (--i);
}



void 	Check_DHT11()
{
                     //a点DHT = 1;
	                   //ab区间  延时,但未说明具体延时时间
	                   //b点DHT = 0;
	                   //bc区间   延时至少18ms,可取30ms
	                   //c点DHT = 1;
	
	                   //Dp模块检测点,距离c点40us或者50us或者60us处
	                   //若Dp电平为低电平。说明模块存在,并将LED1灯点亮
	
   DHT = 1;
	 DHT = 0 ;
	 Delay30ms();
	 DHT =1;     //c点
	
	 Delay40us();//找到Dp点
	
	 if(DHT == 0){
       LED1 = 0;
   }
	 

}

void main()
{
                  // 1.模块上电稳定
	                // 2.LED初始保持熄灭状态
	                // 3.检测模块是否存在
	
  LED1 = 1;
	Delay2000ms();
	Check_DHT11();
  while(1);
}

方法二编程实现(推荐)

2.DHT11模块测温湿度的代码

#include "reg52.h"
#include "intrins.h"

sbit DHT = P1^0;

char flag ;
char tmp;
char datas[6];

void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay30ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 54;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
}


void Delay40us()		//@11.0592MHz
{
	unsigned char i;

	_nop_();
	i = 15;
	while (--i);
}


void  DHT11_Start()
{
   DHT = 1;
	 DHT = 0;
	 Delay30ms();	
   DHT = 1;
	
	 while(DHT);  //找到Dp点,模块存在
	 while(!DHT); //e点
	 while(DHT);  //找到f点
}


 void Read_Data_FromDHT11()
{
   int i ;
	 int j ;
	 DHT11_Start();   //每测量一次温湿度需调用一次该函数
	 for(i = 1;i<=5;i++){
		 for(j =1;j<=8;j++){
        while(!DHT);
			  Delay40us();  //单片机破译 01区分点,
			                 // 即由高电平持续时间不同代表逻辑01
			  if(DHT == 1){
             flag = 1 ;
             while(DHT);					
        }else{
             flag = 0;
      }
			tmp = tmp<<1;
			tmp = tmp|flag;
     }
		 datas[i] = tmp;
}

}

void main()
{
	              //1.DHT11模块上电稳定
                //2.DHT11模块初始化
	              //3.不断获取 单片机获取DHT11模块传来的温湿度数据
	              //与串口结合,将获取的数据上传到PC串口助手
	 Delay2000ms();
	
	 while(1){
	 Delay1000ms();
	 Read_Data_FromDHT11();	 
   }

}

3.单片机通过串口将温湿度上传到上位机

串口相关的编程实现

#include "reg52.h"
#include "intrins.h"

sfr AUXR = 0x8E;


void UartInit(void) //9600bps@11.0592MHz
{
AUXR = 0x01;
SCON = 0x50; //配置串口工作方式1,REN使能接收
TMOD &= 0x0F;
TMOD |= 0x20;//定时器1工作方式位8位自动重装
TH1 = 0xFD;
TL1 = 0xFD;//9600波特率的初值
TR1 = 1;//启动定时器
EA = 1;//开启总中断
ES = 1;//开启串口中断
}

void Delay1000ms() //@11.0592MHz
{
		unsigned char i, j, k;
		_nop_();
		i = 8;
		j = 1;
		k = 243;
		do
		{
		do
		{
		while (--k);
		} while (--j);
		} while (--i);
		}
void sendByte(char data_msg)
{
		SBUF = data_msg;
		while(!TI);
		TI = 0;
}

void sendString(char* str)
{
		while( *str != '\0'){
		sendByte(*str);
		str++;
   }
}



void main()
{
	
		UartInit();
		while(1){
		Delay1000ms();
		//往发送缓冲区写入数据,就完成数据的发送
		sendString("Hello world!\r\n");
		}
}

串口上传DHT11模块温湿度的数据编程实现

#include "reg52.h"
#include "intrins.h"

sfr AUXR = 0x8E;
sbit DHT = P1^0;

char flag ;
char tmp;
char datas[6];


void UartInit(void) //9600bps@11.0592MHz
{
AUXR = 0x01;
SCON = 0x50; //配置串口工作方式1,REN使能接收
TMOD &= 0x0F;
TMOD |= 0x20;//定时器1工作方式位8位自动重装
TH1 = 0xFD;
TL1 = 0xFD;//9600波特率的初值
TR1 = 1;//启动定时器
EA = 1;//开启总中断
ES = 1;//开启串口中断
}

void Delay1000ms() //@11.0592MHz
{
		unsigned char i, j, k;
		_nop_();
		i = 8;
		j = 1;
		k = 243;
		do
		{
		do
		{
		while (--k);
		} while (--j);
		} while (--i);
}
		
void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}



void Delay30ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 54;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
}


void Delay40us()		//@11.0592MHz
{
	unsigned char i;

	_nop_();
	i = 15;
	while (--i);
}



void sendByte(char data_msg)
{
		SBUF = data_msg;
		while(!TI);
		TI = 0;
}

void sendString(char* str)
{
		while( *str != '\0'){
		sendByte(*str);
		str++;
   }
}

void  DHT11_Start()
{
   DHT = 1;
	 DHT = 0;
	 Delay30ms();	
   DHT = 1;
	
	 while(DHT);  //找到Dp点,模块存在
	 while(!DHT); //e点
	 while(DHT);  //找到f点
}


void Read_Data_FromDHT11()
{
   int i ;
	 int j ;
	 DHT11_Start();   //每测量一次温湿度需调用一次该函数
	 for(i = 1;i<=5;i++){
		 for(j =1;j<=8;j++){
        while(!DHT);
			  Delay40us();  //单片机破译 01区分点,
			                 // 即由高电平持续时间不同代表逻辑01
			  if(DHT == 1){
             flag = 1 ;
             while(DHT);					
        }else{
             flag = 0;
      }
			tmp = tmp<<1;
			tmp = tmp|flag;
     }
		 datas[i] = tmp;
}

}



void main()
{
	
		UartInit();
	  Delay2000ms();
		while(1){
		Delay1000ms();
		Read_Data_FromDHT11();
		//往发送缓冲区写入数据,就完成数据的发送
	  sendString("H:");
		sendByte(datas[1]/10+0x30);
		sendByte(datas[1]%10+0x30);
		sendString(".");
		sendByte(datas[2]/10+0x30);
		sendByte(datas[2]%10+0x30);
		sendString("        &&       ");
			
		sendString("T:");
		sendByte(datas[3]/10+0x30);
		sendByte(datas[3]%10+0x30);
		sendString(".");
		sendByte(datas[4]/10+0x30);
		sendByte(datas[4]%10+0x30);
		sendString("\r\n");
			
		
			
		}
}

LCD1602相关的编程实现

4.温湿度小系统

未分文件编程

#include "reg52.h"
#include "intrins.h"
#define databuffer P0




sfr AUXR = 0x8E;
sbit DHT = P1^0;
sbit RS  = P1^1;
sbit RW  = P1^2;
sbit EN  = P1^3;

char datas[6];
char huma[9];
char temp[9];
char flag ;
char tmp;

void UartInit(void) //9600bps@11.0592MHz
{
AUXR = 0x01;
SCON = 0x50; //配置串口工作方式1,REN使能接收
TMOD &= 0x0F;
TMOD |= 0x20;//定时器1工作方式位8位自动重装
TH1 = 0xFD;
TL1 = 0xFD;//9600波特率的初值
TR1 = 1;//启动定时器
EA = 1;//开启总中断
ES = 1;//开启串口中断
}

void Delay1000ms() //@11.0592MHz
{
		unsigned char i, j, k;
		_nop_();
		i = 8;
		j = 1;
		k = 243;
		do
		{
		do
		{
		while (--k);
		} while (--j);
		} while (--i);
}
		
void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}



void Delay30ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 54;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
}


void Delay40us()		//@11.0592MHz
{
	unsigned char i;

	_nop_();
	i = 15;
	while (--i);
}

void Delay15ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 27;
	j = 226;
	do
	{
		while (--j);
	} while (--i);
}

void Delay5ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 9;
	j = 244;
	do
	{
		while (--j);
	} while (--i);
}



void sendByte(char data_msg)
{
		SBUF = data_msg;
		while(!TI);
		TI = 0;
}

void sendString(char* str)
{
		while( *str != '\0'){
		sendByte(*str);
		str++;
   }
}

void  DHT11_Start()
{
   DHT = 1;
	 DHT = 0;
	 Delay30ms();	
   DHT = 1;
	
	 while(DHT);  //找到Dp点,模块存在
	 while(!DHT); //e点
	 while(DHT);  //找到f点
}


void Read_Data_FromDHT11()
{
   int i ;
	 int j ;
	 DHT11_Start();   //每测量一次温湿度需调用一次该函数
	 for(i = 1;i<=5;i++){
		 for(j =1;j<=8;j++){
        while(!DHT);
			  Delay40us();  //单片机破译 01区分点,
			                 // 即由高电平持续时间不同代表逻辑01
			  if(DHT == 1){
             flag = 1 ;
             while(DHT);					
        }else{
             flag = 0;
      }
			tmp = tmp<<1;
			tmp = tmp|flag;
     }
		 datas[i] = tmp;
}

}




void Check_Busy()
{
	
		 char tmp   = 0x80;
					databuffer = 0x80;
		
		 while(tmp & 0x80){
		 RS = 0;
		 RW = 1;
		 EN = 0;
		 _nop_();
		 EN = 1;
		 _nop_();
		 _nop_();
		 
		 tmp = databuffer;
		 _nop_();
		 
			EN = 0;  //状态2前面添加这两条语句即可。
			 _nop_(); //_nop_();
		 }
}





void Write_Cmd_Func(char Position)
{
	 Check_Busy();
   RS = 0;         //写指令即,数据a要显示的地址
	
	 RW = 0;
	 EN = 0;
	 _nop_();
	 
	databuffer = Position; //数据传输点。在写操作下,处于EN = 1前面。
	_nop_();
	
	 EN = 1;       //状态2前面添加这两条语句即可。
	_nop_();
	_nop_();
	 EN = 0;
	_nop_();

}

void Write_Data_Func(char ShowData)
{
	   Check_Busy();
		 RS = 1;              //写数据a
		
		 RW = 0;
		 EN = 0;
		 _nop_();
		 databuffer = ShowData; //数据传输点。在写操作下,处于EN = 1前面。
	   _nop_();
		 EN = 1;
		_nop_();
		_nop_();
		 EN = 0;
		_nop_();

}

void LCD_1602_Init()
{
	
		Delay15ms();
		Write_Cmd_Func(0x38);
		Delay5ms();
		Write_Cmd_Func(0x38);
		Write_Cmd_Func(0x08);
		Write_Cmd_Func(0x01);
		Write_Cmd_Func(0x06);
		Write_Cmd_Func(0x0c);  //0x0c
	
}

 void LCD1602_ShowData_Line(int row,int col,char* string)
{
   switch(row){
		        

		case 1: 
			   Write_Cmd_Func(0x80+col);   //确定第一行的首字母位置,其他依次写入即可,即多次调用Write_Data_Func()函数即可。
		     while(*string){
            Write_Data_Func(*string);
            string++;					 
         }
		   break;
			
		case 2:
			  Write_Cmd_Func(0x80+0x40+col);
		     while(*string){
            Write_Data_Func(*string);
            string++;					 
         }
           break;
  }
}


void Data_Build()
{              //T:34.55°
   huma[0] = 'H';
	 huma[1] = ':';
	  
	 huma[2] = datas[1]/10+0x30;
	 huma[3] = datas[1]%10+0x30;
	 huma[4] ='.';
	
	 huma[5] = datas[2]/10+0x30;
	 huma[6] = datas[2]%10+0x30;
	
	 huma[7] = 'C';
	 huma[8] = '\0';
	
	 temp[0] = 'T';
	 temp[1] = ':';
	  
	 temp[2] = datas[3]/10+0x30;
	 temp[3] = datas[3]%10+0x30;
	 temp[4] ='.';
	
	 temp[5] = datas[4]/10+0x30;
	 temp[6] = datas[4]%10+0x30;
	
	 temp[7] = 'C';
	 temp[8] = '\0';

}


void main()
{
	
		UartInit();
    LCD_1602_Init();
	  Delay2000ms();
	
		while(1){
	
		Read_Data_FromDHT11();
	
		Data_Build();
		
	
		//往发送缓冲区写入数据,就完成数据的发送
	  
	//	sendByte(datas[1]/10+0x30);

		Delay1000ms();
		Delay1000ms();
		sendString(huma);
	  sendString("    ");
		sendString(temp);
		 sendString("\r\n");
					
		LCD1602_ShowData_Line(1,4,huma);
		LCD1602_ShowData_Line(2,4,temp);
			
		}
}


分文件编程

OLED模块

OLED显示一个点

#include "reg52.h"
#include "intrins.h"





sbit LED1 = P3^6;
sbit SCL = P1^1;
sbit SDA = P1^2;



void IIC_Start()
{
 SCL = 0;     //OLED防止雪花的产生
	
 SDA = 1;SCL = 1;
 _nop_();   //5us //算上堆栈调用,一个_nop_()约是5us

 SDA = 0;SCL = 1;
_nop_();    

}

void IIC_Stop()
{
 SCL = 0;  //OLED中用到的IIC协议防止雪花产生
	
 SDA = 0;SCL =1;
 _nop_();
	
 SDA = 1;SCL = 1;
  _nop_();	 


}




char IIC_ACK()  //一般不去调用,只有当OLED显示不正常时,去检测是否是有效应答
{
			char flag;
			SDA = 1;
			_nop_();
			
			SCL = 1;
		//可以加一个_nop_();也可不加
			
			flag = SDA;
			_nop_();     //逻辑上的捆绑,无需看时序图,最好加上。
			
			SCL = 0;
			_nop_();
	return flag;

}

void IIC_Send_Byte(char datasend)
{
	 int i = 0;
  
		for(i = 0;i<8;i++){
		
		 SCL = 0;
		 
		 SDA = datasend & 0x80;  //取最高位 用&OX80
		 _nop_();
		
		 SCL = 1;
			_nop_();
		
			SCL = 0;
		 _nop_();
		
		 datasend= datasend<<1; //注意移位操作
		}

}

void IIC_Write_Cmd( char Data_cmd)
{
   	IIC_Start();            //                     SA0        R/W                    
	  IIC_Send_Byte(0x78);   //0111 1000   从机地址 OLED1 IIC设备是被写入
    IIC_ACK();
    IIC_Send_Byte(0x00);//0(0)00 0000 写命令
    IIC_ACK();
	
	  IIC_Send_Byte(Data_cmd);
	  IIC_ACK();
	  IIC_Stop();

}

void IIC_Write_Data( char Data_data)
{
   	IIC_Start();            //                     SA0        R/W                    
	  IIC_Send_Byte(0x78);   //0111 1000   从机地址 OLED1 IIC设备是被写入
    IIC_ACK();
    IIC_Send_Byte(0x40);//0(1)00 0000 写数据内容 0x40
    IIC_ACK();
	
	  IIC_Send_Byte(Data_data);
	  IIC_ACK();
	  IIC_Stop();

}

                                //   
void Oled_Init(void){
		IIC_Write_Cmd(0xAE);//--display off
		IIC_Write_Cmd(0x00);//---set low column address
		IIC_Write_Cmd(0x10);//---set high column address
		IIC_Write_Cmd(0x40);//--set start line address
		IIC_Write_Cmd(0xB0);//--set page address
		IIC_Write_Cmd(0x81); // contract control
		IIC_Write_Cmd(0xFF);//--128
		IIC_Write_Cmd(0xA1);//set segment remap
		IIC_Write_Cmd(0xA6);//--normal / reverse
		IIC_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
		IIC_Write_Cmd(0x3F);//--1/32 duty
		IIC_Write_Cmd(0xC8);//Com scan direction
		IIC_Write_Cmd(0xD3);//-set display offset
		IIC_Write_Cmd(0x00);//
		IIC_Write_Cmd(0xD5);//set osc division
		IIC_Write_Cmd(0x80);//
		IIC_Write_Cmd(0xD8);//set area color mode off
		IIC_Write_Cmd(0x05);//
		IIC_Write_Cmd(0xD9);//Set Pre-Charge Period
		IIC_Write_Cmd(0xF1);//
		IIC_Write_Cmd(0xDA);//set com pin configuartion
		IIC_Write_Cmd(0x12);//
		IIC_Write_Cmd(0xDB);//set Vcomh
		IIC_Write_Cmd(0x30);//
		IIC_Write_Cmd(0x8D);//set charge pump enable
		IIC_Write_Cmd(0x14);//
		IIC_Write_Cmd(0xAF);//--turn on oled panel


}

void Oled_Clear()
{

    unsigned char i ;
	  unsigned char j;
	 for(i = 0;i<8;i++){
			 IIC_Write_Cmd(0xB0+i);   //遍历P0 -P7页
			 IIC_Write_Cmd(0x00);    //选择第0列
			 IIC_Write_Cmd(0x10);   
			 
       for(j = 0; j<128; j++){ // 遍历每组下的对应的127列
         IIC_Write_Data(0); 
       }
   
   }


}




void main()
{
	
	
	Oled_Init();
	
	IIC_Write_Cmd(0x20);
	IIC_Write_Cmd(0x02);   //两条指令,OLED选择页寻址模式
	Oled_Clear();
	                        //选位置,Page[i] 和 第n列
	IIC_Write_Cmd(0xB5);   //选择Page[0]   1011 0()()() 第7组就是 0xB7
	
	 IIC_Write_Cmd(0x00);    //固定第0列
	 IIC_Write_Cmd(0x10);   

	IIC_Write_Data(0x08);   //第一列的第5个点
  IIC_Write_Data(0x08);   //第一列的第5个点

	
					 	
	
	
	while(1);
}
















OLED显示一个字符A

小车项目

实现左转和右转

#include "reg52.h"
#include "intrins.h"
sbit Left_Con1A = P3^1;
sbit Left_Con1B = P3^2;

sbit Right_Con1A = P3^3;
sbit Right_Con1B = P3^4;



void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}



void LeftWheel_Goforward()  //左轮前进
{
	 Left_Con1A  = 0;
	 Left_Con1B  = 1;
}
void LeftWheel_GoBack()  //左轮后退
{
	 Left_Con1A  = 1;
	 Left_Con1B  = 0;

}
void LeftWheel_Stop()  //左轮停止
{
	 Left_Con1A  = 0;
	 Left_Con1B  = 0;

}

void RightWheel_Goforward()  //右轮前进
{
	 Right_Con1A  = 0;
	 Right_Con1B  = 1;
}
void RightWheel_GoBack()  //右轮后退
{
	 Right_Con1A  = 1;
	 Right_Con1B  = 0;

}
void RightWheel_Stop()  //右轮停止
{
	 Right_Con1A  = 0;
	 Right_Con1B  = 0;
}




void TurnRight()  //右转
{
   LeftWheel_Goforward();  //左轮前进
	 RightWheel_Stop();  //右轮不动
	
}

void TurnLeft()  //左转
{
	 RightWheel_Goforward();  //右轮前进;
	 LeftWheel_Stop();   //左轮不动
	
}

void main()
{
  TurnLeft();

   Delay1000ms();
   TurnRight();
	 Delay1000ms();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值