視頻教程:https://www.bilibili.com/video/BV1fF411K79x
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define LCD1602_DATAPINS P0
sbit LCD1602_E=P2^2;
sbit LCD1602_RW=P2^1;
sbit LCD1602_RS=P2^0;
sbit MA_1 = P1^0;
sbit MA_2 = P1^1;
sbit MA_3 = P1^2;
sbit MA_4 = P1^3;
sbit MB_1 = P1^4;
sbit MB_2 = P1^5;
sbit MB_3 = P1^6;
sbit MB_4 = P1^7;
uchar flag;
unsigned char code M_A[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9}; //X反轉順序
unsigned char code M_B[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //X正轉順序
/*******************************************************************************
* 函 數 名 : Delay
* 函數功能 : 延時(shí)
*******************************************************************************/
void DDelay(unsigned int t)
{
unsigned int k;
while(t--)
{
for(k=0; k80; k++);
}
}
/*******************************************************************************
* 函 數 名 : Lcd1602_Delay1ms
* 函數功能 : 延時(shí)函數,延時(shí)1ms
* 輸 入 : c
* 輸 出 : 無(wú)
* 說(shuō) 名 : 該函數是在12MHZ晶振下,12分頻單片機的延時(shí)。
*******************************************************************************/
void Lcd1602_Delay1ms(uint c) //誤差 0us
{
uchar a,b;
for (; c?>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
/*******************************************************************************
* 函 數 名 : LcdWriteCom
* 函數功能 : 向LCD寫(xiě)入一個(gè)字節的命令
* 輸 入 : com
* 輸 出 : 無(wú)
*******************************************************************************/
void LcdWriteCom(uchar com) //寫(xiě)入命令
{
LCD1602_E = 0; //使能
LCD1602_RS = 0; //選擇發(fā)送命令
LCD1602_RW = 0; //選擇寫(xiě)入
LCD1602_DATAPINS = com; //放入命令
Lcd1602_Delay1ms(1); //等待數據穩定
LCD1602_E = 1; //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5); //保持時(shí)間
LCD1602_E = 0;
}
/*******************************************************************************
* 函 數 名 : LcdWriteData
* 函數功能 : 向LCD寫(xiě)入一個(gè)字節的數據
* 輸 入 : dat
* 輸 出 : 無(wú)
*******************************************************************************/
void LcdWriteData(uchar dat) //寫(xiě)入數據
{
LCD1602_E = 0; //使能清零
LCD1602_RS = 1; //選擇輸入數據
LCD1602_RW = 0; //選擇寫(xiě)入
LCD1602_DATAPINS = dat; //寫(xiě)入數據
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5); //保持時(shí)間
LCD1602_E = 0;
}
/*******************************************************************************
* 函 數 名 : LcdInit()
* 函數功能 : 初始化LCD屏
* 輸 入 : 無(wú)
* 輸 出 : 無(wú)
*******************************************************************************/
void LcdInit() //LCD初始化子程序
{
LcdWriteCom(0x38); //開(kāi)顯示
LcdWriteCom(0x0c); //開(kāi)顯示不顯示光標
LcdWriteCom(0x06); //寫(xiě)一個(gè)指針加1
LcdWriteCom(0x01); //清屏
LcdWriteCom(0x80); //設置數據指針起點(diǎn)
}
//按指定位置顯示一個(gè)字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //當要顯示第二行時(shí)地址碼+0x40;
X |= 0x80; // 算出指令碼
LcdWriteCom(X); //這里不檢測忙信號,發(fā)送地址碼
LcdWriteData(DData);
}
//按指定位置顯示一串字符
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength;
ListLength = 0;
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
while (DData[ListLength]>=0x20) //若到達字串尾則退出
{
if (X <= 0xF) //X坐標應小于0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //顯示單個(gè)字符
ListLength++;
X++;
}
}
}
//unsigned char code M_A[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9}; //X反轉順序
//unsigned char code M_B[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //X正轉順序
void Motor_A1()
{
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 0;
MA_4 = 1;
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 1;
MA_4 = 1;
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 1;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 1;
MA_3 = 1;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 1;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 1;
MA_2 = 1;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 1;
MA_2 = 0;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 1;
MA_2 = 0;
MA_3 = 0;
MA_4 = 1;
}
//unsigned char code M_B[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //X正轉順序
void Motor_A2()
{
DDelay(3);
MA_1 = 1;
MA_2 = 0;
MA_3 = 0;
MA_4 = 1;
DDelay(3);
MA_1 = 1;
MA_2 = 0;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 1;
MA_2 = 1;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 1;
MA_3 = 0;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 1;
MA_3 = 1;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 1;
MA_4 = 0;
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 1;
MA_4 = 1;
DDelay(3);
MA_1 = 0;
MA_2 = 0;
MA_3 = 0;
MA_4 = 1;
}
void Motor_B1()
{
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 0;
MB_4 = 1;
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 1;
MB_4 = 1;
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 1;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 1;
MB_3 = 1;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 1;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 1;
MB_2 = 1;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 1;
MB_2 = 0;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 1;
MB_2 = 0;
MB_3 = 0;
MB_4 = 1;
}
void Motor_B2()
{
DDelay(3);
MB_1 = 1;
MB_2 = 0;
MB_3 = 0;
MB_4 = 1;
DDelay(3);
MB_1 = 1;
MB_2 = 0;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 1;
MB_2 = 1;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 1;
MB_3 = 0;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 1;
MB_3 = 1;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 1;
MB_4 = 0;
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 1;
MB_4 = 1;
DDelay(3);
MB_1 = 0;
MB_2 = 0;
MB_3 = 0;
MB_4 = 1;
}
void M_Con(uchar id,uchar dir,uint step)
{
uchar i;
if(id == 0)
{
if(dir == 0)
{
for(i=0;i=step2)
{
num = step1 - step2;
for(i=0;i
審核編輯:湯梓紅
聲明:本文內容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權轉載。文章觀(guān)點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習之用,如有內容侵權或者其他違規問(wèn)題,請聯(lián)系本站處理。
舉報投訴
-
Proteus
+關(guān)注
關(guān)注
76文章
1688瀏覽量
105789 -
電動(dòng)機
+關(guān)注
關(guān)注
73文章
3884瀏覽量
94453 -
步進(jìn)電機
+關(guān)注
關(guān)注
149文章
2973瀏覽量
146376
發(fā)布評論請先 登錄
相關(guān)推薦
80C51+proteus步進(jìn)電機實(shí)驗
`80C51+proteus步進(jìn)電機實(shí)驗,帶LCD顯示速度,方向,狀態(tài),數碼管顯示檔位`
發(fā)表于 07-18 11:55
工程師資料:電機控制技術(shù)應用解決方案
的設計基于單片機和proteus的步進(jìn)電機控制基于NiosII軟核處理器的步進(jìn)電機接口設計基于A(yíng)Tmega16單片機
發(fā)表于 12-17 14:37
如何使用proteus軟件去仿真步進(jìn)電機?
使用proteus仿真步進(jìn)電機目錄使用proteus仿真步進(jìn)電機電路代碼遇到問(wèn)題總結電路芯片使用
發(fā)表于 07-07 06:06
基于單片機和proteus的步進(jìn)電機控制
發(fā)表于 03-02 22:10
?132次下載
基于proteus的步進(jìn)電機仿真簡(jiǎn)介
發(fā)表于 12-02 10:50
?15次下載
Proteus步進(jìn)電機控制資料
發(fā)表于 06-19 14:33
?9次下載
正反轉可控的步進(jìn)電機Proteus仿真
正反轉可控的步進(jìn)電機Proteus仿真正反轉可控的步進(jìn)電機Proteus仿真
發(fā)表于 12-22 17:45
?243次下載
proteus步進(jìn)電機仿真
步進(jìn)電機是一種能夠將電脈沖信號轉換成角位移或線(xiàn)位移的機電元件,它實(shí)際上是一種單相或多相同步電動(dòng)機。單相步進(jìn)電動(dòng)機有單路電脈沖驅動(dòng),輸出功率一般很小,其用途為微小功率驅動(dòng)。多相步進(jìn)電動(dòng)機
發(fā)表于 02-26 09:56
?5.3w次閱讀
使用proteus仿真步進(jìn)電機
使用proteus仿真步進(jìn)電機目錄使用proteus仿真步進(jìn)電機電路代碼遇到問(wèn)題總結電路芯片使用
發(fā)表于 12-31 18:50
?25次下載
評論