完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在做一个项目,涉及一个步进电机,一个LCD显示器,三个按钮和一个PIC16芯片,我有一些麻烦。如果我用一个例子来说明我需要做什么,那就容易多了;有三个按钮,一个顺时针,一个逆时针按钮和一个输入按钮。假设我按CW按钮5次,然后按CW按钮3次,然后按Enter键。然后步进电机在时钟方向上转动2圈。我想我知道该怎么做,而且我已经走到一半了,我卡住的部分是LCD部分。LCD必须显示“步进模式,步进:XX YYY”,其中XX是步数,YYY是方向。这个显示需要更新与每个按钮按下LIVE,这是让我困住的部分,如果它不是活着,那么它会更容易,但唉,它不是。我想用一堆“计数器”,然后用计数器中的值来做一个新增的PCL,之类的事情,但我不确定这是不行。任何帮助将非常感谢你!
以上来自于百度翻译 以下为原文 I'm working on a project that involves a stepper motor, an LCD display, three push buttons and a PIC16 chip that I'm having some trouble with. It'd be easier if i just explain what I need to do with an example; There are three buttons, a clockwise, a counter clockwise button and an enter button. Say I press the CW button 5 times and then the CCW button 3 times, I then press the enter button. The stepper motor should then turn 2 turns in the clock wise direction. This part I think I know how to do and I'm halfway there, the part I'm stuck on is the LCD part. The LCD must display 'STEP MODE, STEPS:XX YYY' where XX is the number of steps and YYY is the direction. This display needs to update LIVE with each button press, this is the part that's got me stuck, if it wasn't live then it'd be a lot easier but alas it is not. I was thinking of using a bunch of 'counters' and then using the value in the counter to do a addw PCL,f sort of thing but I'm not sure if that'd work. Any help would be very appreciated thank you! |
|
相关推荐
4个回答
|
|
|
|
|
|
一般来说,你的程序应该是一个循环,等待按下按钮,增加适当的计数器,如果计数发生变化,更新显示,如果按下ENTER,运行步进电机,循环并再次执行。有很多方法来检测按钮按下(中断,轮询)。一般来说,你需要卸下按钮。
以上来自于百度翻译 以下为原文 Generally your program should be a loop, waiting for button presses, incrementing the appropriate counters, update the display if a count changes, run the stepper motor if ENTER is pressed, loop around and do it all again. There are many ways to detect button presses (interrupts, polling). Generally you will need to debounce the buttons. |
|
|
|
这是一段代码。我希望它有帮助。当然,它需要一些改进。STEPS寄存器将始终具有TEMP1和TEMP2或TEMP2和TEMP1.cblock 0x20 TEMP1之间的差异;临时存储CW步骤TEMP2的数量;临时存储CCW步骤STEPS的数量;步骤数量(STEPS=TEMP1-TEMP2)FLAGS;位0指示方向:0-CW,1-C这里是初始化代码------clrf TEMP1 clrf TEMP2 clrf STEPS clrf FLAGStest_CW_button btfsc BTCW;是否按下了CW按钮?转到test_CCW_button;否,分支到test_CCW incf TEMP1,f;是,TEMP1=TEMP1+1movf TEMP2,W;W=TEMP2 subwf TEMP1,W;W=TEMP1-TEMP2 btfss STATUS,C;goto._res;是,分支到._res movwf STEPS;否,STEPS=W=TEMP1-TEMP2 bcf FLAGS,0;指示CW方向调用LCD_UPDATE;调用LCD更新子例程测试_CCW-按钮btfsc BTCCW;是否按下了CCW按钮?转到test_Enter_Button;no,分支到test_Enter incf TEMP2,f;是,TEMP2=TEMP2+1movf TEMP2,W;W=TEMP2 subwf TEMP1,W;W=TEMP1-TEMP2 btfss STATUS,C;goto._res;是,分支到._res movwf STEPS;否,STEPS=W=TEMP1-TEMP2 bcf FLAGS,0;指示CW方向调用LCD_UPDATE;调用LCD更新子例程_Enter_Button btfsc BTENTER;Enter按钮被按下吗?转到test_CW_button;否,分支到test_CW clrf TEMP1 CLRF TEMP2转到Move_.;分支到Move_.._res movf TEMP1,W;W=TEMP1 subwf TEMP2,W;W=TEMP2-TEMP1 movwf STEPS;STEPS=W=TEMP2-TEMP1 bsf FLAGS,0;指示CCW方向调用LCD_UPDATE goto test_CW_button
以上来自于百度翻译 以下为原文 Here's a piece of code. I hope it helps. Of course it need some improvements. The STEPS register will have always the difference between TEMP1 and TEMP2 or TEMP2 and TEMP1. cblock 0x20 TEMP1 ;temporarily stores the number of CW steps TEMP2 ;temporarily stores the number of CCW steps STEPS ;number of steps (STEPS = TEMP1 - TEMP2) FLAGS ;bit 0 indicate direction: 0 - CW, 1 - CCW enc ; --- initialization code here ---- clrf TEMP1 clrf TEMP2 clrf STEPS clrf FLAGS test_CW_button btfsc BTCW ;is CW button pressed? goto test_CCW_button ;no, branch to test_CCW incf TEMP1,f ;yes, TEMP1 = TEMP1 + 1 movf TEMP2,W ;W = TEMP2 subwf TEMP1,W ;W = TEMP1-TEMP2 btfss STATUS,C ;is the result negative? goto adj_res ;yes, branch to adj_res movwf STEPS ;no, STEPS = W = TEMP1 - TEMP2 bcf FLAGS,0 ;indicate CW direction call LCD_UPDATE ;call LCD update subroutine test_CCW-button btfsc BTCCW ;is CCW button pressed? goto test_Enter_Button ;no, branch to test_Enter incf TEMP2,f ;yes, TEMP2 = TEMP2 + 1 movf TEMP2,W ;W = TEMP2 subwf TEMP1,W ;W = TEMP1-TEMP2 btfss STATUS,C ;is the result negative? goto adj_res ;yes, branch to adj_res movwf STEPS ;no, STEPS = W = TEMP1 - TEMP2 bcf FLAGS,0 ;indicate CW direction call LCD_UPDATE ;call LCD update subroutine test_Enter_Button btfsc BTENTER ;is Enter button pressed? goto test_CW_button ;no, branch to test_CW clrf TEMP1 CLRF TEMP2 goto Move_Motor ;branch to Move_Motor adj_res movf TEMP1,W ;W = TEMP1 subwf TEMP2,W ;W = TEMP2 - TEMP1 movwf STEPS ;STEPS = W = TEMP2 - TEMP1 bsf FLAGS,0 ;indicate CCW direction call LCD_UPDATE goto test_CW_button |
|
|
|
在这里:
以上来自于百度翻译 以下为原文 Here: cblock 0x20 STEPS ;number of steps (positive = CW, negative = CCW) enc ; --- initialization code here ---- start clrf STEPS test_CW_button btfsc BTCW ;is CW button pressed? goto test_CCW_button ;no, branch to test_CCW incf STEPS,f call LCD_UPDATE ;call LCD update subroutine test_CCW-button btfsc BTCCW ;is CCW button pressed? goto test_Enter_Button ;no, branch to test_Enter decf STEPS,f call LCD_UPDATE ;call LCD update subroutine test_Enter_Button btfsc BTENTER ;is Enter button pressed? goto test_CW_button ;no, branch to test_CW call Move_Motor ;branch to Move_Motor goto start |
|
|
|
只有小组成员才能发言,加入小组>>
5204 浏览 9 评论
2016 浏览 8 评论
1942 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
754浏览 1评论
641浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
549浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
653浏览 0评论
553浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 10:23 , Processed in 1.284585 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号