|
單片機(jī)控制步進(jìn)電機(jī)正反轉(zhuǎn)
設(shè)計(jì)原理:采用51單片機(jī)最小系統(tǒng),通過達(dá)林頓管(ULN2003)來控制一個(gè)5線4相異步電機(jī)的正轉(zhuǎn)和反轉(zhuǎn)
從而達(dá)到晾衣架升降的目的
本系統(tǒng)還有衣服的重量自動(dòng)檢測(cè)的功能,采用模數(shù)轉(zhuǎn)換器ADC0832,對(duì)重量傳感器進(jìn)行重量采集
將采集到的信號(hào)轉(zhuǎn)換為數(shù)字信號(hào)送至單片機(jī)處理,并最終顯示在LCD1602液晶顯示器上
系統(tǒng)會(huì)自動(dòng)的根據(jù)衣物的重量控制晾衣架的起落
0.png (33.33 KB, 下載次數(shù): 49)
下載附件
2017-5-7 16:49 上傳
0.png (40.23 KB, 下載次數(shù): 52)
下載附件
2017-5-7 16:50 上傳
0.png (44.96 KB, 下載次數(shù): 33)
下載附件
2017-5-7 16:48 上傳
單片機(jī)源程序:
- #include "reg52.h" //此文件中定義了單片機(jī)的一些特殊功能寄存器
- #include "adc0832.h"
- #include "lcd1602.h"
- #include "delay.h"
- #include<intrins.h>
- #include <string.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar flag=0;
- unsigned char code F_Rotation[8]={0x08,0x18,0x10,0x30,0x20,0x60,0x40,0x48}; //順時(shí)針轉(zhuǎn)表格
- unsigned char code B_Rotation[8]={0x48,0x40,0x60,0x20,0x30,0x10,0x18,0x08}; //逆時(shí)針轉(zhuǎn)表格
- /******************************************/
- /* 延時(shí)子程序 */
- /******************************************/
- void Delay1ms(unsigned int count)
- {
- unsigned int i,j;
- for(i=0;i<count;i++)
- for(j=0;j<120;j++);
- }
- //步進(jìn)電機(jī)正轉(zhuǎn)函數(shù)
- void SETP_MOTOR_FFW(uchar n)
- {
- uchar i,j;
- for(i=0;i<5*n;i++)
- {
- for(j=0;j<8;j++)
- {
-
- P3 = F_Rotation[j];
- Delay1ms(25);
-
- }
- }
- }
- //步進(jìn)電機(jī)反轉(zhuǎn)函數(shù)
- void SETP_MOTOR_REV(uchar n)
- {
- uchar i,j;
- for(i=0;i<5*n;i++)
- {
- for(j=0;j<8;j++)
- {
-
- P3 = B_Rotation[j];
- Delay1ms(25);
- }
- }
-
- }
- void adc0832_cl(uchar q)
- {
- q=q*100/255; //對(duì)采集到的AD值進(jìn)行0-100的量化
- LCD_Write_String(4,0,"Weight");
- write_com(0xC0+5);
- write_dat(q/100+0x30); //百位
- write_dat(q%100/10+0x30); //十位
- write_dat(q%10+0x30); //個(gè)位
-
- if( q>70 && flag==1)
- {SETP_MOTOR_REV(2); flag=0; }
- if(q<30 && flag==0)
- {SETP_MOTOR_FFW(2); flag=1; }
-
-
-
- }
- void main()
- {
- lcd1602_init(); //液晶初始化
- while(1)
- {
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
下載:
晾衣控制電機(jī)轉(zhuǎn)動(dòng).rar
(116.58 KB, 下載次數(shù): 113)
2017-5-7 12:32 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|