 
- UID
- 373967
- 帖子
- 9428
- 主題
- 2609
- 精華
- 0
- 積分
- 1023
- 楓幣
- 49
- 威望
- 999
- 存款
- 38807
- 贊助金額
- 0
- 推廣
- 0
- GP
- 1205
- 閱讀權限
- 70
- 在線時間
- 477 小時
- 註冊時間
- 2023-1-12
- 最後登入
- 2025-3-15
|
STC12C5608AD-35I-SKDIP28是一款8051系列的微控制器
您可以使用它來製作WiFi無線監視器。
以下是您需要的零件列表:
STC12C5608AD-35I-SKDIP28微控制器
ESP8266 WiFi模塊
攝像頭模塊
電容器和電阻器
電源適配器和連接線
杜邦線
您可以使用下面的鏈接來查看STC12C5608AD-35I-SKDIP28微控制器的引腳佈局:
https://www.stcmcu.com/datasheet/stc/stc-ad-pdf/stc12c5608ad-series-english.pdf
下面是示例代碼,可用於ESP8266模塊與STC12C5608AD-35I-SKDIP28微控制器之間的通信。該代碼可以通過串行通信從ESP8266模塊接收數據,並將其顯示在液晶顯示器上。
#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#include <string.h>
sbit ESP8266_RTS = P1^1;
sbit ESP8266_CTS = P1^0;
sbit ESP8266_RST = P1^2;
sbit RS = P2^0;
sbit RW = P2^1;
sbit E = P2^2;
sbit LCD_D4 = P2^4;
sbit LCD_D5 = P2^5;
sbit LCD_D6 = P2^6;
sbit LCD_D7 = P2^7;
void delay(unsigned int i);
void LCD_Init(void);
void LCD_WriteCommand(unsigned char Command);
void LCD_WriteData(unsigned char Data);
void LCD_WriteString(unsigned char x,unsigned char y,unsigned char *s);
void ESP8266_Init(void);
void ESP8266_SendString(unsigned char *s);
void ESP8266_ReceiveString(unsigned char *s);
void main()
{
unsigned char str[100];
unsigned char temp[50];
LCD_Init();
ESP8266_Init();
while(1)
{
ESP8266_ReceiveString(str);
sprintf(temp, "%s", str);
LCD_WriteString(1,1,temp);
}
}
void delay(unsigned int i)
{
while(i--);
}
void LCD_Init(void)
{
delay(10000);
LCD_WriteCommand(0x30);
delay(5000);
LCD_WriteCommand(0x30);
delay(5000);
LCD_WriteCommand(0x30);
delay(5000);
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x0C);
LCD_WriteCommand(0x06);
LCD_WriteCommand(0x01);
}
void LCD_WriteCommand(unsigned char Command)
{
RS = 0;
RW = 0;
E = 1;
LCD_D4 = Command >> 4;
LCD_D5 = Command >> 5;
LCD_D6 = Command >> 6;
LCD_D7 = Command >> 7;
E = 0;
delay(50);
E = 1;
LCD_D4 = Command & 0x0F;
LCD_D5 = (Command & 0x1F) >> 4;
LCD_D6 = (Command & 0x3F) >> 5;
LCD_D7 = (Command & 0x7F) >> 6;
E = 0;
delay(50);
}
void LCD_WriteData(unsigned char Data)
{
RS = 1;
RW = 0;
E = 1;
LCD_D4 = Data >> 4;
LCD_D5 = Data >> 5;
LCD_D6 = Data >> 6;
LCD_D7 = Data >> 7;
E = 0;
delay(50);
E = 1;
LCD_D4 = Data & 0x0F;
LCD_D5 = (Data & 0x1F) >> 4;
LCD_D6 = (Data & 0x3F) >> 5;
LCD_D7 = (Data & 0x7F) >> 6;
E = 0;
delay(50);
}
void LCD_WriteString(unsigned char x,unsigned char y,unsigned char *s)
{
unsigned char address;
if(y==0)
address = 0x80 + x;
else
address = 0xC0 + x;
LCD_WriteCommand(address);
while(*s)
{
LCD_WriteData(*s);
s++;
}
}
void ESP8266_Init(void)
{
ESP8266_RST = 0;
delay(50000);
ESP8266_RST = 1;
delay(50000);
ESP8266_SendString("AT\r\n");
delay(10000);
ESP8266_SendString("AT+CWMODE=1\r\n");
delay(10000);
ESP8266_SendString("AT+CWJAP="SSID","password"\r\n"); //replace "SSID" and "password" with your WiFi SSID and password
delay(20000);
}
void ESP8266_SendString(unsigned char *s)
{
while(*s)
{
SBUF = *s;
while(TI == 0);
TI = 0;
s++;
}
}
void ESP8266_ReceiveString(unsigned char *s)
{
unsigned char i;
kotlin
Copy code
while(1)
{
if(RI == 1)
{
*s = SBUF;
RI = 0;
s++;
if(*s == '\n' || *s == '\r')
{
*s = '\0';
break;
}
}
}
}
此示代碼僅適用於ESP8266模塊與STC12C5608AD-35I-SKDIP28微控制器之間的通信,還需要添加相應的代碼以支持攝像頭模塊和其他功能。 |
|