当前位置:网站首页>Yyds dry goods inventory intelligent fan based on CC2530 design

Yyds dry goods inventory intelligent fan based on CC2530 design

2022-07-05 02:40:00 DS brother Bruce Lee

1. Project introduction

With the frequent use of air conditioning cooling equipment , The global climate is getting warmer and warmer, and the substances emitted by air-conditioning cooling equipment have an increasing impact on the environment . Second, people often catch a cold or feel unwell after sleeping because the temperature is too low or the temperature rises , Compared with air conditioning, fans are more suitable for the elderly, children and people with weak physique .
Through the intelligent fan design of Internet of things technology, it can solve the problem that the cooling equipment is still running because of sleeping , Realize more energy-saving and intelligent control .

Through the temperature sensor to collect the ambient temperature data and the voice control module to adjust the wind speed to realize the intelligent control of the fan , Make the fan automatically adjust the wind force with the change of temperature .

The specific functions are as follows :

  1. Realize voice control , It can recognize voice commands and automatically make corresponding work ;
  2. Realize real-time temperature monitoring ;
  3. Realize automatic control of fan speed through real-time temperature ;
  4. After power on, the fan can be switched on and the number of revolutions can be adjusted :

Realize the idea :

use DHT11 Temperature and humidity sensor , Collect ambient temperature , Compare the set temperature threshold with the collected ambient temperature , Switch that controls the fan , Voice control can also be completed by detecting voice through voice recognition module .

The functions implemented are summarized as follows :

  1. Press the key on the development board to control the switch of the fan (LED The light switch )
  2. The switch of the fan is controlled by voice (LED The light switch )
    Speech is recognized by the speech module .
  3. In the main function, every 500ms Collect once DHT11 temperature , And then through OLED The display shows .

Complete project source code download address : https://download.csdn.net/download/xiaolong1126626497/75318366

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer

2. Hardware introduction

2.1 OLED display

OLED use 0.96 " SPI Interface display . The resolution is 128x64.

 The specific wiring is as follows : 
#define LCD_SCL P1_2 //SCLK  The clock  D0(SCLK)
#define LCD_SDA P1_3 //SDA D1(MOSI)  data 
#define LCD_RST P1_7 //_RES hardware reset  Reset  
#define LCD_DC P0_0 //A0 H/L  Command data strobe ,H: data ,L: command 
VCC Pick up 3.3V  
GND Pick up GND

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _02

2.2 DHT11 Temperature and humidity sensor

DHT11 It is a single bus digital temperature and humidity sensor , Voltage compatible 3v~5v, SCM can directly IO Port connection simulation sequence completes data reading .

The specific wiring is as follows :

DATA Connect to P0_7 mouth 
VCC Pick up 3.3V  
GND Pick up GND

     
  • 1.
  • 2.
  • 3.

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _03

2.3 Voice module

The voice module adopts LD3320 Chip for identification , You can set internally recognized terms , Support secondary development programming .

The default built-in recognition entries are as follows :

#yyds Dry inventory # be based on CC2530 Designed smart fan _CC2530_04

The following is the physical picture of the speech recognition module :

#yyds Dry inventory # be based on CC2530 Designed smart fan _CC2530_05

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _06

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _07

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _08

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _09

#yyds Dry inventory # be based on CC2530 Designed smart fan _ Single chip microcomputer _10

#yyds Dry inventory # be based on CC2530 Designed smart fan _CC2530_11

#yyds Dry inventory # be based on CC2530 Designed smart fan _CC2530_12

3. Case code

3.1 Speech recognition module code

/******************************************************* ** CPU: STC11L08XE **  Crystal oscillator :22.1184MHZ **  Baud rate :9600 bit/S **  Password mode :  That is, you need to say “ The little hero ” This password  , To be able to carry out the next level of recognition  /*********************************************************/


#include "config.h"
/************************************************************************************/
// nAsrStatus  Used in main The main program indicates the running state of the program , No LD3320 The status register inside the chip 
// LD_ASR_NONE:  Means not doing ASR distinguish 
// LD_ASR_RUNING:  Express LD3320 Doing ASR In recognition 
// LD_ASR_FOUNDOK:  Indicates that after the identification process is completed , There is a recognition result 
// LD_ASR_FOUNDZERO:  Indicates that after the identification process is completed , No recognition results 
// LD_ASR_ERROR:  Indicates that in the identification process LD3320 There is an incorrect state inside the chip 
/***********************************************************************************/
uint8 idata nAsrStatus = 0;
void MCU_init();
void ProcessInt0(); // Identify the handler 
void delay(unsigned long uldata);
void User_handle(uint8 dat);// The user executes the operation function 
void Delay200ms();
void Led_test(void);// Working instructions of single chip microcomputer 
uint8_t G0_flag = DISABLE; // Operation flag ,ENABLE: function .DISABLE: Stop running 
sbit LED = P4 ^ 2; // Signal indicator 

sbit SRD1 = P1 ^ 7;
sbit SRD2 = P1 ^ 6;
sbit SRD3 = P1 ^ 5;
sbit SRD4 = P1 ^ 4;


/*********************************************************** *  name   call : void main(void) *  work   can :  The main function   Program entrance  *  Entrance parameters : *  Export parameters : *  say   bright : *  Calling method : **********************************************************/
void  main(void)
{
	uint8 idata nAsrRes;
	uint8 i = 0;
	P1M0 = 0xFF;
	P1M1 = 0x00;
	SRD1 = SRD2 = SRD3 = SRD4 = 0;
	Led_test();
	MCU_init();
	LD_Reset();
	UartIni(); /* Serial initialization */
	nAsrStatus = LD_ASR_NONE;		//  The initial state : Not doing ASR
	PrintCom("<G> Welcome to use ");
	while(1)
	{
		switch(nAsrStatus)
		{
		case LD_ASR_RUNING:
		case LD_ASR_ERROR:
			break;
		case LD_ASR_NONE:
		{
			nAsrStatus = LD_ASR_RUNING;
			if (RunASR() == 0)	/*  Start once ASR Identification process :ASR initialization ,ASR Add key words , start-up ASR operation */
			{
				nAsrStatus = LD_ASR_ERROR;
			}
			break;
		}
		case LD_ASR_FOUNDOK: /*  once ASR Identify the end of the process , selection ASR Recognition result */
		{
			nAsrRes = LD_GetResult();		/* To get the results */
			User_handle(nAsrRes);// The user executes the function 
			nAsrStatus = LD_ASR_NONE;
			break;
		}
		case LD_ASR_FOUNDZERO:
		default:
		{
			nAsrStatus = LD_ASR_NONE;
			break;
		}
		}// switch
	}// while

}
/*********************************************************** *  name   call : LED Lamp test  *  work   can :  Whether the single chip microcomputer works  *  Entrance parameters :  nothing  *  Export parameters : nothing  *  say   bright : **********************************************************/
void Led_test(void)
{
	LED = ~ LED;
	Delay200ms();
	LED = ~ LED;
	Delay200ms();
	LED = ~ LED;
	Delay200ms();
	LED = ~ LED;
	Delay200ms();
	LED = ~ LED;
	Delay200ms();
	LED = ~ LED;
}
/*********************************************************** *  name   call : void MCU_init() *  work   can :  MCU initialization  *  Entrance parameters : *  Export parameters : *  say   bright : *  Calling method : **********************************************************/
void MCU_init()
{
	P0 = 0xff;
	P1 = 0x00;
	P2 = 0xff;
	P3 = 0xff;
	P4 = 0xff;


	AUXR &= 0x7F;		// Timer clock 12T Pattern 
	TMOD |= 0x01;		// Set timer mode 
	TL0 = 0x00;		// Set initial value of timing 
	TH0 = 0x28;		// Set initial value of timing 
	TF0 = 0;		// eliminate TF0 sign 
	TR0 = 1;		// Timer 0 Start timing 
	ET0 = 1;

	LD_MODE = 0;		//  Set up MD Pin is low , Parallel mode read / write 
	IE0 = 1;
	EX0 = 1;
	EA = 1;
	WDT_CONTR = 0x3D;
}
/*********************************************************** *  name   call :  The time delay function  *  work   can : *  Entrance parameters : *  Export parameters : *  say   bright : *  Calling method : **********************************************************/
void Delay200us()		//@22.1184MHz
{
	unsigned char i, j;
	_nop_();
	_nop_();
	i = 5;
	j = 73;
	do
	{
		while (--j);
	}
	while (--i);
}

void  delay(unsigned long uldata)
{
	unsigned int j  =  0;
	unsigned int g  =  0;
	while(uldata--)
		Delay200us();
}

void Delay200ms()		//@22.1184MHz
{
	unsigned char i, j, k;

	i = 17;
	j = 208;
	k = 27;
	do
	{
		do
		{
			while (--k);
		}
		while (--j);
	}
	while (--i);
}

/*********************************************************** *  name   call :  Interrupt handling function  *  work   can : *  Entrance parameters : *  Export parameters : *  say   bright : *  Calling method : **********************************************************/
void ExtInt0Handler(void) interrupt 0
{
	ProcessInt0();
}
/*********************************************************** *  name   call : The user executes the function  *  work   can : After the identification is successful , The execution action can be modified here  *  Entrance parameters :  nothing  *  Export parameters : nothing  *  say   bright : **********************************************************/
void 	User_handle(uint8 dat)
{
	if(0 == dat)
	{
		G0_flag = ENABLE;
		PrintCom("<G> Hello , master ");
		LED = 0;
	}
	else if(ENABLE == G0_flag)
	{
		G0_flag = DISABLE;
		LED = 1;
		switch(dat)
		{
		case CODE_1:	 /* command “ turn on the light ”*/
			SRD1 = 1;
			PrintCom("<G> The light is on ");
			break;
		case CODE_2:	 /* command “ Turn off the lights ”*/
			SRD1 = 0;
			PrintCom("<G> The light is off \r\n");
			break;
		case CODE_3:		/* command “ Turn on the TV. ”*/
			SRD2 = 1;
			PrintCom("<G> The TV is on \r\n");
			break;
		case CODE_4:		/* command “ Close the TV ”*/
			SRD2 = 0;
			PrintCom("<G> The TV is off \r\n");
			break;
		case CODE_5:		/* command “ Open the refrigerator ”*/
			SRD3 = 1;
			PrintCom("<G> The refrigerator has been opened \r\n");
			break;
		case CODE_6:		/* command “ Close the refrigerator ”*/
			SRD3 = 0;
			PrintCom("<G> The refrigerator is closed \r\n");
			break;
		case CODE_7:		/* command “ Turn on the air conditioning ”*/
			SRD4 = 1;
			PrintCom("<G> Empty bar has been opened \r\n");
			break;
		case CODE_8:		/* command “ Turn off the air conditioner ”*/
			SRD4 = 0;
			PrintCom("<G> Empty bar is closed \r\n");
			break;
		case CODE_9:		/* command “ Turn it all on ”*/
			SRD1 = 1;
			SRD2 = 1;
			SRD3 = 1;
			SRD4 = 1;
			PrintCom("<G> All open \r\n");
			break;
		case CODE_10:		/* command “ Close all ”*/
			SRD1 = 0;
			SRD2 = 0;
			SRD3 = 0;
			SRD4 = 0;
			PrintCom("<G> All closed \r\n");
			break;
		case CODE_11:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_12:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_13:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_14:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_15:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_16:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_17:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_18:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_19:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_20:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_21:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_22:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_23:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_24:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_25:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_26:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_27:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_28:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_29:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_30:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_31:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_32:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_33:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_34:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_35:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_36:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_37:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_38:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_39:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_40:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_41:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_42:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_43:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_44:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_45:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_46:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_47:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_48:		/* command “.....”*/

			PrintCom("");
			break;
		case CODE_49:		/* command “.....”*/

			PrintCom("");
			break;
		default:/*text.....*/
			break;
		}
	}
	else
	{
		//PrintCom(" Please say the first level password \r\n"); /*text.....*/
	}
}

void tm0_isr() interrupt 1
{
    TL0 = 0x00;		// Set initial value of timing 
	TH0 = 0x28;		// Set initial value of timing 
	WDT_CONTR=0x3D;
		
}

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.
  • 337.
  • 338.
  • 339.
  • 340.
  • 341.
  • 342.
  • 343.
  • 344.
  • 345.
  • 346.
  • 347.
  • 348.
  • 349.
  • 350.
  • 351.
  • 352.
  • 353.
  • 354.
  • 355.
  • 356.
  • 357.
  • 358.
  • 359.
  • 360.
  • 361.
  • 362.
  • 363.
  • 364.
  • 365.
  • 366.
  • 367.
  • 368.
  • 369.
  • 370.
  • 371.
  • 372.
  • 373.
  • 374.
  • 375.
  • 376.
  • 377.
  • 378.
  • 379.
  • 380.
  • 381.
  • 382.
  • 383.
  • 384.
  • 385.
  • 386.
  • 387.
  • 388.
  • 389.
  • 390.
  • 391.
  • 392.
  • 393.
  • 394.
  • 395.
  • 396.
  • 397.
  • 398.
  • 399.
  • 400.
  • 401.
  • 402.
  • 403.
  • 404.
  • 405.
  • 406.
  • 407.
  • 408.
  • 409.
  • 410.
  • 411.
  • 412.
  • 413.
  • 414.
  • 415.
  • 416.
  • 417.
  • 418.
  • 419.
  • 420.
  • 421.
  • 422.
  • 423.
  • 424.
  • 425.
  • 426.
  • 427.
  • 428.
  • 429.
  • 430.
  • 431.
  • 432.
  • 433.
  • 434.
  • 435.
  • 436.
  • 437.
  • 438.
  • 439.

3.2 cc2530 Serial port code

#include "uart.h"
/*  The functionality : A serial port 0 initialization  */
void Init_Uart0(void)
{
  PERCFG&=~(1<<0);  // A serial port 0 The pins of the are mapped to positions 1, namely P0_2 and P0_3
  P0SEL|=0x3<<2;   // take P0_2 and P0_3 Set the port as a peripheral function 
  U0BAUD = 216;     //32MHz System clock generation 115200BPS Baud rate 
  U0GCR&=~(0x1F<<0);// Clear baud rate index 
  U0GCR|=11<<0;      //32MHz System clock generation 115200BPS Baud rate 
  U0UCR |= 0x80;    // No flow control ,8 Bit data , Clear buffer 
  U0CSR |= 0x3<<6;  // choice UART Pattern , Enable the receiver 
}


/*  The functionality :UART0 Send string function  */
void UR0SendString(char *str)
{
 while(*str!='\0')
  {
    U0DBUF = *str;    // About to send 1 Byte data write U0DBUF
    while(UTX0IF == 0);// Wait for the data to be sent 
    UTX0IF = 0;       // Clear the send complete flag , Prepare for the next send 
    str++;
  }
}

/*  The functionality :  imitation printf Style formatting and printing function  */
char USART0_PRINT_BUFF[200]; // Format data cache data 
void USART0_Printf(const char *format,...)
{
  char *str=NULL;
  /*1.  Format conversion */
  va_list ap; // va_list---->char *
  va_start(ap,format); // Initialization parameter list 
  vsprintf(USART0_PRINT_BUFF,
        format,
        ap); // Format printing 
  va_end(ap); // End parameter acquisition 
  /*2.  Serial printing */
  str=USART0_PRINT_BUFF;// Pointer assignment 
  while(*str!='\0')
  {
    U0DBUF=*str; // Send a byte of data 
    str++; // The pointer increases by itself , Point to the next data 
    while(UTX0IF == 0);// Wait for the data to be sent 
    UTX0IF = 0;       // Clear the send complete flag , Prepare for the next send 
  }
}

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.

3.3 OLED Display code

typedef unsigned char uchar;
typedef unsigned int  uint;


#define LCD_SCL P1_2 //SCLK  The clock  D0(SCLK)
#define LCD_SDA P1_3 //SDA D1(MOSI)  data 
#define LCD_RST P1_7 //_RES hardware reset  Reset  
#define LCD_DC P0_0 //A0 H/L  Command data strobe ,H: data ,L: command 

#define XLevelL 0x00
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 64
#define Brightness 0xCF 
#define X_WIDTH 128
#define Y_WIDTH 64


void DelayMS(unsigned int msec)
{ 
    unsigned int i,j;
    
    for (i=0; i<msec; i++)
        for (j=0; j<530; j++);
}

/*********************LCD  Time delay 1ms************************************/
void LCD_DLY_ms(unsigned int ms)
{                         
    unsigned int a;
    while(ms)
    {
        a=1800;
        while(a--);
        ms--;
    }
    return;
}
/*********************LCD Writing data ************************************/ 
void LCD_WrDat(unsigned char dat)     
{
    unsigned char i=8, temp=0;
    LCD_DC=1;  
    for(i=0;i<8;i++) // Send an eight bit data  
    {
        LCD_SCL=0;  
        
        temp = dat&0x80;
        if (temp == 0)
        {
            LCD_SDA = 0;
        }
        else
        {
            LCD_SDA = 1;
        }
        LCD_SCL=1;             
        dat<<=1;    
    }
}

/*********************LCD Write orders ************************************/                                        
void LCD_WrCmd(unsigned char cmd)
{
    unsigned char i=8, temp=0;
    LCD_DC=0;
    for(i=0;i<8;i++) // Send an eight bit data  
    { 
        LCD_SCL=0; 
       
        temp = cmd&0x80;
        if (temp == 0)
        {
            LCD_SDA = 0;
        }
        else
        {
            LCD_SDA = 1;
        }
        LCD_SCL=1;
        cmd<<=1;;        
    }     
}
/*********************LCD  Set coordinates ************************************/
void LCD_Set_Pos(unsigned char x, unsigned char y) 
{ 
    LCD_WrCmd(0xb0+y);
    LCD_WrCmd(((x&0xf0)>>4)|0x10);
    LCD_WrCmd((x&0x0f)|0x01); 
} 
/*********************LCD Full screen ************************************/
void LCD_Fill(unsigned char bmp_dat) 
{
    unsigned char y,x;
    for(y=0;y<8;y++)
    {
        LCD_WrCmd(0xb0+y);
        LCD_WrCmd(0x01);
        LCD_WrCmd(0x10);
        for(x=0;x<X_WIDTH;x++)
            LCD_WrDat(bmp_dat);
    }
}
/*********************LCD Reset ************************************/
void LCD_CLS(void)
{
    unsigned char y,x;    
    for(y=0;y<8;y++)
    {
        LCD_WrCmd(0xb0+y);
        LCD_WrCmd(0x01);
        LCD_WrCmd(0x10); 
        for(x=0;x<X_WIDTH;x++)
            LCD_WrDat(0);
    }
}
/*********************LCD initialization ************************************/
void LCD_Init(void)     
{  
    P0SEL &= 0xFE; // Give Way P0.0 For the ordinary IO mouth ,
    P0DIR |= 0x01; // Give Way P0.0 For output 

    P1SEL &= 0x73; // Give Way  P1.2 P1.3 P1.7 For the ordinary IO mouth 
    P1DIR |= 0x8C; // hold  P1.2 P1.3 1.7 Set as output 
    
    LCD_SCL=1;
    LCD_RST=0;
    LCD_DLY_ms(50);
    LCD_RST=1;      // There should be enough time from power on to initialization , Wait RC Reset complete  
    LCD_WrCmd(0xae);//--turn off oled panel
    LCD_WrCmd(0x00);//---set low column address
    LCD_WrCmd(0x10);//---set high column address
    LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
    LCD_WrCmd(0x81);//--set contrast control register
    LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
    LCD_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0 Reverse left and right  0xa1 normal 
    LCD_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0 Up and down reversed  0xc8 normal 
    LCD_WrCmd(0xa6);//--set normal display
    LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
    LCD_WrCmd(0x3f);//--1/64 duty
    LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
    LCD_WrCmd(0x00);//-not offset
    LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
    LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
    LCD_WrCmd(0xd9);//--set pre-charge period
    LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
    LCD_WrCmd(0xda);//--set com pins hardware configuration
    LCD_WrCmd(0x12);
    LCD_WrCmd(0xdb);//--set vcomh
    LCD_WrCmd(0x40);//Set VCOM Deselect Level
    LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
    LCD_WrCmd(0x02);//
    LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
    LCD_WrCmd(0x14);//--set(0x10) disable
    LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
    LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) 
    LCD_WrCmd(0xaf);//--turn on oled panel
    LCD_Fill(0xff);  // Initial screen clearing 
    LCD_Set_Pos(0,0);     
} 

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
原网站

版权声明
本文为[DS brother Bruce Lee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140908089144.html