完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
嗨,伙计们,
我一直在玩我的2键FOB和接收器,我想把它连接到我的PSoC 1不会很棒。 与我的PSoC相连的是我制作的2个红外波束断路器,它们目前使用的是简单的代码。我想做一个简单的警报。应该是这样的。系统待机;等待武器(钥匙离岸按钮1)&武装;FOB的按钮应该解除是否报警被激活或禁用它,即使它不激活报警。 所以我需要声明一些类似的事情: 扣臂=0; 扣臂=0; 而buttonARM不压,不做任何事,如果它是ARM启动报警 { 做报警的东西,这样做来监视红外波束断路器 如果警报响起的任何理由和buttondisarm按下,禁用报警输出 } IM 100%确定如何实现KEKFOB 任何帮助总是非常感谢。 谢谢 以上来自于百度翻译 以下为原文 Hi guys, Ive been playing around with my 2 button key fob and receiver, and i thought wouldnt it be great to interface it to my Psoc 1. conected to my psoc are 2 ir beam breakers i made, they currently work with a simple bit of code. I was wanting to make a simple alarm. it shoud be like this. system on> wait till armed (button 1 of key fob) > armed> do alarm stuff (already done). button 2 of the fob should disarm the alarm whether the alarm was activated or just to disable it even if it wasnt activated. so do i need to declare something like: buttonarm==0; buttondisarm==0; while buttonarm is not pressed, dont do anything, if it is arm alarm activated { do alarm stuff, have this done to monitor ir beam breakers if the alarm goes off for any reason and buttondisarm is pressed, disable alarm output } im 100% sure on how to implement the keyfob any help is always greatly appreciated. thanks |
|
相关推荐
44个回答
|
|
…继续的。。。
开关/外壳也可以做像这样的复杂的事情… 案例1:案例2://语句中断;案例3:/语句B断裂;其中语句“A”将被执行,无论变量是1还是2。 或者像这样: 案例1:/ /状态1中断;案例2://语句2例3://语句2中断;在这里,我们在案例2之后忽略了“中断”,因此代码可以在案例2中跳入,并通过案例3,或者根据变量的值可以在3中直接跳转。 以上来自于百度翻译 以下为原文 ... continued... The switch / case can also do complex thing like this... case 1: case 2: // statements A break; case 3: // statements B break; where 'statements A' will be executed whether the variable is 1 or 2 or like this : case 1: // statments 1 break; case 2: // statements 2 case 3: // statements 2 break; Where we have left out the 'break' after case 2, so the code can jump in at case 2 and fall through to case 3, or you can jump straight in at 3 depending on the value of the variable. |
|
|
|
导致这样的事情,因为你的应用程序的基本结构:
定义状态0,定义状态1,定义STATEY激活2 int程序状态=STATEY解除;而(1){Switter(程序状态){ StaseTeX解除武装:doAxDARARMEDY CODER();如果(ARMXButoNo.PuHuffe())程序状态=状态武装;中断;CASE状态武装:DoAARMeMeD代码();(DISARM)ButoNoPuSuffle())StaseStaseSttEyDeAc武装;If(ActudioTyDeCeCd())程序状态= StaseEndoAc激活;Bead;StaseStEnOrth:SoNo.AlARME();IF(DeMARXButnOpPuHuffe())程序状态= StuteXDe武装;Sturnt;默认:DealStale= StuteXDe武装;} 以上来自于百度翻译 以下为原文 Leading to something like this fot the basic structure of your app: #define STATE_DISARMED 0 #define STATE_ARMED 1 #define STATE_ACTIVATED 2 int programState = STATE_DISARMED; while(1) { switch (programState) { case STATE_DISARMED: do_disarmed_code(); if (arm_button_pushed()) programState = STATE_ARMED; break; case STATE_ARMED: do_armed_code(); if (disarm_button_pushed()) programState = STATE_DISARMED; if (activation_detected()) programState = STATE_ACTIVATED; break; case STATE_ACTIVATED: sound_alarm(); if(disarm_button_pushed()) programState = STATE_DISARMED; break; default: programState = STATE_DISARMED; } } |
|
|
|
要注意的是,当您检测到按钮被按下,或者激活检测到您不调用该代码时,您只需更改程序状态,那么无限DO(1)循环的下一次迭代执行代码。
以上来自于百度翻译 以下为原文 The big thing to note in this is that when you detect that a button is pushed, or activation detected you do NOT call that code, you simply change the program state, so the next iteration of the infinite do(1) loop executes the code. |
|
|
|
嗨,大家好,
我认为我们的朋友CFYCOP对所有的状态机编程感到困惑。他对国家的观念感到困难。 我对CFYCORP的建议是一次做1件事。 我的建议是 1。从一个关键输入和一个LED输出从头开始构建一个新的项目,输入使用DeNoCurter,所以输出是去抖输入(这里没有很多软件)。 2。使用一个开关,并按下按钮打开,并再次按下拖动。(领导国家)和“领导”状态 三。使用2个按钮,一个打开(ARM)和一个关机(解除武装)。 经过这次演习,他应该能够更多地了解国家。我们可以继续从那个项目开始。 以上来自于百度翻译 以下为原文 Hi all, I think our friend Cf_corp is confused with all those state machine programming. And he is having difficulty with the idea of states. My suggestion to Cf_corp is do things 1 at a time my suggestion is 1. Build a new project from scratch with one key input and one LED output, the input uses a debouncer, so the output is debounced input ( not much software here). 2. Use one switch and have the button pressed to turn on and press again to trun off. ( A "LED ON" state, and "LED OFF" state) 3. Use 2 buttons, one to turn on (ARM) and one to turn off ( DISARM). After this exercise, he should be able to understand more about states. And we can contiune the rest ot the project from that on. |
|
|
|
嗨,SpiderKenny,谢谢你的帮助。
正如鲍伯指出的,我仍然对此感到困惑,有人知道有任何带有切换语句的示例项目吗?或者我可以非常贴近我的PSoC设计器页面,然后运行? 谢谢大家 以上来自于百度翻译 以下为原文 Hi SpiderKenny, Thanks for all your helpful replies. As Bob pointed out I am still slighlty confused by this, does anyone know of any sample project with switch statements in it? or something i canpretty much stick into my psoc designer page and complie and run? thanks guys |
|
|
|
吕梁
我有点CONCONFREST,我用Visual Basic在控制台上做状态机做选择菜单之类的事情,但是我从来没有用微控制器做过。 我要像你所建议的那样去做简单的方法。 所以我刚刚开始了一个新的空白项目,我刚刚注意到你最近一篇关于简单做事的帖子。我渴望尝试这种方法, 谢谢你这么有耐心! 以上来自于百度翻译 以下为原文 Hi lleung, I am a bit cononfused still, ive done state machines with visual basic on the console doing things like selection menus etc, but ive never done them with the microcontroller. I was going to go for the simple approach like you suggested. so i just started a new blank project, and ive just noticed your last post regarding doing things simply. im keen to try that approach, thanks for being so patient folks! |
|
|
|
|
|
|
|
吕梁
所以基本上我开始了一个新的项目, IV指定端口0上的输入和端口1上的输出 我认为现在代码中有一些声明要做, 所以我们有了莱德森,莱德弗,手臂,解除武装。 这只是一个问题: 定义Ledion 定义LeDyOFF 定义臂 解除武装 INT状态; (1){ 开关(状态) 以上来自于百度翻译 以下为原文 Hi lleung, so basically ive started a new project, ive designated an input on port 0.0 and an output on port 1.0 i take it there is some declaring to do in the code itself now, so we have LED_ON, LED_OFF, ARM, DISARM woudld it be a matter of doing this: #define LED_ON #define LED_OFF #define ARM #defibe DISARM int state; while(1) { switch(state) |
|
|
|
看看C.的“EnUM”语句
定义Ledion 不会做任何事情,它只会让Delyon定义,但不会给它一个价值。所以你可以写 定义27的莱迪 因此,当编译器看到一个“DeLyon”时,它将用“27”代替你所期望的。 为了有几个名字,一次定义C程序员通常使用“EnUM”语句,这将给你的优势,保持定义一起,并宣布变量的目的枚举代表。在我的第二篇文章中,我在这里写了一个例子,我在这里写了一个EnUM的例子。 你在找一个工作例子吗?斯皮德肯尼的职位是一个!您只需提供他调用的函数,这些函数会被标记为错误,因为它们是未知的,例如ARMXButoNoPuHuffE()或DeMARXButoNoPuHuffe(),它们是函数。 半焦(空) { 返回PRT1DR和0x01; } 鲍勃 以上来自于百度翻译 以下为原文 Have a look at the "enum" statement in C. #define LED_ON will not do something at all, it just makes LED_ON defined but will not give it a value. So you might write #define LED_ON 27 which will give it, well not really a value but a replacement text. So when the compiler sees a "LED_ON" it will replace this with "27" doing exactly what you expect. To have several names #defined at once C programmers usually use the "enum" statement which will give you the advantage of keeping the definitions together and having declared variables for the purpose the enum stands for. Have a look a bit up in this thread at my second post where I wrote an example for the enum I'm talking about. You are looking for a working example? SpiderKenny's post is one! You only have to provide the functions he called which would be marked as errors because they are unknown yed as for example arm_button_pushed() or disarm_button_pushed() which are functions char arm_button_pressed(void) { return PRT1DR & 0x01; } Bob |
|
|
|
|
|
|
|
嗨,鲍伯,
所以它会像 EnUM {ARMXButoNoPress(0,DISARM ButoNo.PuHuffe),StayeX解除武装,状态武装,StisteAc激活,SoaOnCalmith}程序状态; 另一个部分:char ARMXButoNo.Press(Value}) 返回PRT1DR和0x01; } 这是否设置了作为端口1针0的函数ARMXButoNo压? 谢谢 以上来自于百度翻译 以下为原文 hi Bob, So it would be like enum { arm_button_pushed(0, disarm_button_pushed(), STATE_DISARMED, STATE_ARMED, STATE_ACTIVATED, sound_alarm} programState; the other piece;: char arm_button_pressed(void) { return PRT1DR & 0x01; } Does that set up the function arm_button_pressed as port 1 pin 0? thanks |
|
|
|
先忘记国家和事件吧。
启动简单的1输入,1输出,无需首先消除。然后添加去抖动。先完成这个任务。 以上来自于百度翻译 以下为原文 How about forget about the states and events first. Start the simple 1 input , 1 output without debounce first. Then added the debounce. Finish this first. |
|
|
|
吕梁
也许简单的方法是最好的,所以正如我所说的,我有一个新的项目,只有一个输入和一个输出设置, 这种状态和事件让我有点困惑, 我会有一些东西,比如EnUM {almith-武装,警报,解除武装,警报激活,未知}状态; 以上来自于百度翻译 以下为原文 Hi lleung, maybe the simple approach is best, so as i said, i have a new project with just an input and an output setup, this states and events has me a bit confused, would i have something like, enum {alarm_armed, alarm_disarmed, alarm_activated, unknown } states; |
|
|
|
现在不要担心国家或事件。
只要创建一个项目,打开输入输出时打开的LED。 把它放在这里,我们进入下一步。 以上来自于百度翻译 以下为原文 Don't worry about the state or events now. Just create the project that turn on the ourput LED when the input is on. Post it here and we go to the next step. |
|
|
|
|
|
|
|
好的,所以我附上了一个输入和输出的示例代码,我用了很多次建议的LED API,基本上当端口0上的输入很高时,端口1上的输出被激活。
采样1.Zip 169 K 以上来自于百度翻译 以下为原文 ok, so ive attached a sample code with an input and output, Ive used the LED api as was suggested to me so many times, basically when the input on port 0.0 is made high, the output on port 1 is activated.
|
|
|
|
现在你的输出跟随输入。但是
通常我们不直接使用输入,我们需要对输入进行去抖。这可以用硬件或软件来完成。对于硬件,您可以使用单镜头或PWD。或者你可以使用软件去抖动。 这是一个很好的参考。 HTTP://www. GangsL.COM/DeuncCn.HTM 和 K/Eng/Copys/Buffigs/Boogs/BurkPosis/4024981/My优先软件 看看你是否能用其中一个来消除你的输入。 以上来自于百度翻译 以下为原文 Now your ouput is following the input. But Normally we don't use the input directly, we need to debounce the input. This can be done in hardware or software. for hardware, you can use the one shot or the pwd from. Or you can use software to debounce. Here is a good reference http://www.ganssle.com/debouncing.htm and http://www.embedded.com/electronics-blogs/break-points/4024981/My-favorite-software-debouncers See if you can use one of those to debounce your input. |
|
|
|
吕梁
谢谢你的回复和链接,请看一下。我想实施反跳。谢谢 以上来自于百度翻译 以下为原文 hi lleung, thanks for the replies and links, will look into that. I wanted to implement a debounce. thanks |
|
|
|
所以我尝试在数据表中使用PWD API模块。
IVE用PWD API重新安装项目,在安装过程中IM不是100%确定的,或者如果它正确地完成了 邮编邮编 230.9 K 以上来自于百度翻译 以下为原文 So I tried using the PWD API module following the datasheet inlcuded etc. Ive reattached the project with PWD api, im not 100% sure on the setup or if its correctly done
|
|
|
|
今天晚些时候我会检查的。
顺便问一下,你们有口袋套装吗?使用PSoC3和5调试更容易。 以上来自于百度翻译 以下为原文 I'll check it later today. BTW, Do you have PoC3 eval kits. It would be easier to debug with psoc3 and 5. |
|
|
|
只有小组成员才能发言,加入小组>>
754个成员聚集在这个小组
加入小组2101 浏览 1 评论
1848 浏览 1 评论
3666 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1783 浏览 6 评论
1533 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
564浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
418浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
434浏览 2评论
380浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
911浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 21:35 , Processed in 1.365630 second(s), Total 114, Slave 97 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号