找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 11408|回復(fù): 15
打印 上一主題 下一主題
收起左側(cè)

基于stm32的智能窗簾Proteus仿真設(shè)計(jì)

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:511094 發(fā)表于 2020-3-27 13:10 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include "stm32f10x.h"
  2. #include "bsp-lcd1602.h"
  3. #include "delay.h"
  4. #include "sys.h"
  5. #include "adc.h"


  6. void L298_GPIO( void )
  7. {
  8.         GPIO_InitTypeDef GPIO_InitStructure;        
  9.        
  10.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  11.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
  12.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  13.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  14.         GPIO_Init(GPIOC, &GPIO_InitStructure);       
  15. }

  16. void OPEN(void)        //left moto is runing, but right moto is brake
  17. {
  18.         GPIO_SetBits(GPIOC,GPIO_Pin_5);
  19.         GPIO_ResetBits(GPIOC,GPIO_Pin_4);
  20.         GPIO_ResetBits(GPIOC,GPIO_Pin_3);
  21.         GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  22.         GPIO_SetBits(GPIOC,GPIO_Pin_1);       
  23.         GPIO_SetBits(GPIOC,GPIO_Pin_0);
  24. }
  25. void CLOSE(void)        //right moto is runing, but left moto is brake
  26. {
  27.         GPIO_ResetBits(GPIOC,GPIO_Pin_5);
  28.         GPIO_ResetBits(GPIOC,GPIO_Pin_4);
  29.         GPIO_SetBits(GPIOC,GPIO_Pin_3);
  30.         GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  31.         GPIO_SetBits(GPIOC,GPIO_Pin_1);       
  32.         GPIO_SetBits(GPIOC,GPIO_Pin_0);
  33. }

  34. void STOP(void)        //right moto is runing, but left moto is brake
  35. {
  36.         GPIO_SetBits(GPIOC,GPIO_Pin_5);
  37.         GPIO_SetBits(GPIOC,GPIO_Pin_4);
  38.         GPIO_SetBits(GPIOC,GPIO_Pin_3);
  39.         GPIO_SetBits(GPIOC,GPIO_Pin_2);
  40.         GPIO_SetBits(GPIOC,GPIO_Pin_1);       
  41.         GPIO_SetBits(GPIOC,GPIO_Pin_0);
  42. }


  43. int main(void)
  44. {
  45. int a,b,c,d;
  46.         float temp;
  47.        
  48.         delay_init();                     //延時(shí)函數(shù)初始化                 
  49.         LCD1602_Init();
  50.     ADC1_GPIO_Config();
  51.         L298_GPIO();
  52.     ADC_Config();  
  53.         LCD1602_ShowStr(0,0,"  Auto curtain ",15);
  54.         LCD1602_ShowStr(0,1,"Light:",6);
  55.        
  56.         while(1)
  57.         {
  58.                 b=ADC_GetConversionValue(ADC1);
  59.                 temp=b*(3.4/4096)*10;
  60.                 //表示光線太弱
  61.                 if( temp < 8 )
  62.                 {
  63.                         LCD1602_ShowStr(7,1,"Low ",4);
  64.                         OPEN();
  65.                 }
  66.                 else
  67.                 {
  68.                         if( temp < 25)                                //光線合適
  69.                         {
  70.                                 LCD1602_ShowStr(7,1,"OK  ",4);
  71.                                 STOP();
  72.                         }
  73.                         else                                                //光線太強(qiáng)
  74.                         {
  75.                                 LCD1602_ShowStr(7,1,"High",4);
  76.                                 CLOSE();
  77.                         }
  78.                 }
  79. //                a=temp/1;
  80. //                c=temp*10;
  81. //                d=c%10;
  82. //                LCD_ShowNum(11,0,a);
  83. //                LCD_ShowNum(13,0,d);
  84.         }
  85. }
復(fù)制代碼

所有資料51hei提供下載:
基于stm32的智能窗簾仿真設(shè)計(jì).7z (285.11 KB, 下載次數(shù): 637)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏21 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:724710 發(fā)表于 2020-4-27 10:31 | 只看該作者
原理圖顯示有錯(cuò)誤,控制距離遠(yuǎn)近顯示屏有時(shí)不變化,相應(yīng)的電機(jī)不轉(zhuǎn)動(dòng)
回復(fù)

使用道具 舉報(bào)

板凳
ID:368810 發(fā)表于 2020-5-20 10:36 | 只看該作者
樓主,程序那個(gè)文件夾里哪個(gè)是主程序啊,用什么軟件打開?
回復(fù)

使用道具 舉報(bào)

地板
ID:368810 發(fā)表于 2020-5-20 15:19 | 只看該作者
YDYQ 發(fā)表于 2020-4-27 10:31
原理圖顯示有錯(cuò)誤,控制距離遠(yuǎn)近顯示屏有時(shí)不變化,相應(yīng)的電機(jī)不轉(zhuǎn)動(dòng)

靈敏度比較低,應(yīng)該在程序里修改可以提高靈敏度
回復(fù)

使用道具 舉報(bào)

5#
ID:368810 發(fā)表于 2020-5-22 17:03 | 只看該作者
樓主,程序應(yīng)該是有問題,proteus時(shí)間運(yùn)行了20多秒后屏幕上的字會(huì)消失,再過一會(huì)調(diào)整光敏元件電機(jī)沒有反應(yīng)
回復(fù)

使用道具 舉報(bào)

6#
ID:368810 發(fā)表于 2020-5-22 17:07 | 只看該作者
而且在proteus時(shí)間的第6或第7秒時(shí),屏幕的字從auto curtain會(huì)變?yōu)镵  uto curtain,不知道是什么原因,我用的是proteus8.6版本
回復(fù)

使用道具 舉報(bào)

7#
ID:772082 發(fā)表于 2020-6-15 11:59 | 只看該作者
zyy1100 發(fā)表于 2020-5-20 10:36
樓主,程序那個(gè)文件夾里哪個(gè)是主程序啊,用什么軟件打開?

keil v5 mdk可以打開
回復(fù)

使用道具 舉報(bào)

8#
ID:780927 發(fā)表于 2020-6-16 14:59 | 只看該作者
請(qǐng)問有電路原理圖嗎?
回復(fù)

使用道具 舉報(bào)

9#
ID:606520 發(fā)表于 2020-6-17 18:43 | 只看該作者
我能說,到現(xiàn)在我都不知道用什么軟件寫程序,這個(gè)模擬軟件是啥?
回復(fù)

使用道具 舉報(bào)

10#
ID:774546 發(fā)表于 2020-6-29 03:45 來自手機(jī) | 只看該作者
temp那里怎么算的啊,是什么意思啊
回復(fù)

使用道具 舉報(bào)

11#
ID:440028 發(fā)表于 2021-12-30 14:55 | 只看該作者
#include "stm32f10x.h"
#include "bsp-lcd1602.h"
#include "delay.h"
#include "sys.h"
#include "adc.h"


void L298_GPIO( void )
{
        GPIO_InitTypeDef GPIO_InitStructure;         
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);        
}

void OPEN(void)        //left moto is runing, but right moto is brake
{
        GPIO_SetBits(GPIOC,GPIO_Pin_5);
        GPIO_ResetBits(GPIOC,GPIO_Pin_4);
        GPIO_ResetBits(GPIOC,GPIO_Pin_3);
        GPIO_ResetBits(GPIOC,GPIO_Pin_2);
        GPIO_SetBits(GPIOC,GPIO_Pin_1);        
        GPIO_SetBits(GPIOC,GPIO_Pin_0);
}
void CLOSE(void)        //right moto is runing, but left moto is brake
{
        GPIO_ResetBits(GPIOC,GPIO_Pin_5);
        GPIO_ResetBits(GPIOC,GPIO_Pin_4);
        GPIO_SetBits(GPIOC,GPIO_Pin_3);
        GPIO_ResetBits(GPIOC,GPIO_Pin_2);
        GPIO_SetBits(GPIOC,GPIO_Pin_1);        
        GPIO_SetBits(GPIOC,GPIO_Pin_0);
}

void STOP(void)        //right moto is runing, but left moto is brake
{
        GPIO_SetBits(GPIOC,GPIO_Pin_5);
        GPIO_SetBits(GPIOC,GPIO_Pin_4);
        GPIO_SetBits(GPIOC,GPIO_Pin_3);
        GPIO_SetBits(GPIOC,GPIO_Pin_2);
        GPIO_SetBits(GPIOC,GPIO_Pin_1);        
        GPIO_SetBits(GPIOC,GPIO_Pin_0);
}


int main(void)
{
int a,b,c,d;
        float temp;
        
        delay_init();                     //延時(shí)函數(shù)初始化                  
        LCD1602_Init();
    ADC1_GPIO_Config();
        L298_GPIO();
    ADC_Config();  
        LCD1602_ShowStr(0,0,"  Auto curtain ",15);
        LCD1602_ShowStr(0,1,"Light:",6);
        
        while(1)
        {
                b=ADC_GetConversionValue(ADC1);
                temp=b*(3.4/4096)*10;
                //表示光線太弱
                if( temp < 8 )
                {
                        LCD1602_ShowStr(7,1,"open ",4);
                        OPEN();
                }
                else
                {
                        if( temp < 25)                                //光線合適
                        {
                                LCD1602_ShowStr(7,1,"OK  ",4);
                                STOP();
                        }
                        else                                                //光線太強(qiáng)
                        {
                                LCD1602_ShowStr(7,1,"close",4);
                                CLOSE();
                        }
                }
//                a=temp/1;
//                c=temp*10;
//                d=c%10;
//                LCD_ShowNum(11,0,a);
//                LCD_ShowNum(13,0,d);
        }
}
回復(fù)

使用道具 舉報(bào)

12#
ID:440028 發(fā)表于 2021-12-30 14:56 | 只看該作者
好像兩個(gè)程序都一樣,你倆怎么都差不多,都在51黑里
回復(fù)

使用道具 舉報(bào)

13#
ID:1039715 發(fā)表于 2022-7-16 16:02 | 只看該作者
zyy1100 發(fā)表于 2020-5-22 17:03
樓主,程序應(yīng)該是有問題,proteus時(shí)間運(yùn)行了20多秒后屏幕上的字會(huì)消失,再過一會(huì)調(diào)整光敏元件電機(jī)沒有反應(yīng)

        while(1)
        {
          LCD1602_ShowStr(0,0,"  Auto curtain ",15);
          LCD1602_ShowStr(0,1,"Light:",6);
                b=ADC_GetConversionValue(ADC1);
你可以試一下把這個(gè)Auto curtain 和light 放到while(1)里面試一下
回復(fù)

使用道具 舉報(bào)

14#
ID:1048726 發(fā)表于 2022-11-3 18:55 | 只看該作者
所以是有錯(cuò)誤嗎
回復(fù)

使用道具 舉報(bào)

15#
ID:1054785 發(fā)表于 2022-11-30 10:53 來自手機(jī) | 只看該作者
我想問問如果需要實(shí)現(xiàn)該功能電機(jī)需要選哪樣的
回復(fù)

使用道具 舉報(bào)

16#
ID:1054785 發(fā)表于 2022-12-6 13:59 來自手機(jī) | 只看該作者
窗簾開關(guān)找不到,關(guān)鍵詞是啥
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表