我陷入了循环...! [英] I'm stuck in a loop...!

查看:103
本文介绍了我陷入了循环...!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...只是想知道是否有人可以看到为什么我无法摆脱这个循环?这个想法是在输出端口的高4位上放置一个高半字节,并使脉冲成行.然后,当使能再次变高时,发送较低的半字节...

当我减慢该过程的速度并放入一些LED时,该序列可以正常工作,但是由于某种原因,它会循环约10秒钟.发生这种情况时,我无权访问任何其他功能,因此必须有某些东西可以阻止switch语句中断.这是代码...

Hey guys...Just wondering if anybody can see why I can''t getout of this loop? the idea is an upper nibble is placed on the upper 4 bits of an output port, and enable line pulsed. The lower nibble is then sent when the enable goes high again...

When I slow the process down and put in some LEDs the sequence works fine, but for some reason it loops for about 10 seconds. I don''t have access to any other functions when this is happening, so there must be something stopping the switch statement from breaking. Here''s the code...

case 0x02:                                      //case 0x02 from firmware

            IDENT_PORT = 0X00;

            j = 0x16;                              //bit mask ie, & with 1111 0000 to clear bottom nibble
            upper_nibble = j & 0x0f0;              //   0001 0110
            PORTB = upper_nibble;                  //present upper nibble on port b

            RB1 = 1;                               //pulse enable line
            DelayMs(500);
            RB1 = 0;
            //DelayMs(500);
            PORTB = 0x00;

            k = (j << 4) | (j >> 4);               //swap upper and lower nibbles of 0x16
            lower_nibble = k & 0x0f0;              //again bit mask to leave the lower nibble (0110)
            PORTB = lower_nibble;                  //put on port

            RB1 = 1;
                DelayMs(500);                      //pulse enable line
            RB1 = 0;
                DelayMs(500);

            PORTB = 0x00;                          //clear port
            ReceivedDataBuffer[0] = 0x00;

    break;



我真的很乐意提供帮助,我认为我离该项目太近了.



I''d really appriciate the help, I think i''m too close to the project

推荐答案

那不是我最明显的代码曾经见过,并且忽略了它在任何时候都没有循环,注释有点垃圾...

编写一个将字节发送到端口的函数-我假设您的端口使用前四位作为数据线,并且该数据在脉冲线的上升沿有效.该函数应调用一个函数以两次输出半字节.

That isn''t the most obvious bit of code I''ve ever seen, and ignoring that it doesn''t have a loop in it at any point an the comments are a bit rubbish...

Write a function which transmits a byte to the port - I assume that your port uses the top four bits as the data lines, and that data is valid out on the rising edge of you pulse line. The function should call a function to output a nibble, twice.

void OutByte(byte b)
   {
   OutNibble(b);             // High nibble
   OutNibble(b << 4);        // Low nibble
   }
void OutNibble(byte b);
   {
   PORTB = b & 0xf0;         // Data lines are top four bits of port
   RB1 = 1;                  // Strobe the data as available.
   DelayMs(500);             // Allow receiver to notice
   RB1 = 0;                  // Cancel strobe...
   DelayMs(500);             // ...and stabilize.
   }

您可以对延迟进行微调,以在对它们施加作用域时实现数据/频闪稳定.

You can fine tune your delays to allow for data/strobe stabilization when you put a scope on them.


是的,我知道我的代码很草率……我还没有.我花了很长的时间来做这件事,所以我有点用逻辑来弥补,因为我不太了解这种语言...但是我正在慢慢地到达那里.我不认为我可以使用您的代码,因为大多数固件都包含在一个函数中,在我不知道自己在做什么之前,我并不想明确地尝试使用它. br/> 我想知道是否可以向您寻求帮助,例如,我正在玩一个pic USB接口教程,该教程中将一个未签名的字符通过C ++应用程序写入固件.

yes I know my code is pretty sloppy...I haven''t being doing it for very long so I kind of make it up with logic as Im not too sure on the language...but im getting there, slowly. I don''t think I can use your code as most of the firmware is contained within a function, and I don''t particully want to play around with it too much until I know what I''m doing...
I was wondering if I could ask you for some help tho, i''m playing with a pic USB interface tutorial, where an unsigned char is written to the firmware form a c++ application.

void ProcessIO(void)
{
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
       if(!HIDRxHandleBusy(USBOutHandle))                                    
           {
             switch(RecievedDataBuffer[0])
              {
                 case.............
              }
	USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
    }
}



问题在于它充满了switch语句,我只想将j(在我的原始问题中)分配给导入的未签名char.虽然很糟糕,但是我的原始代码可以完成工作,但是当我尝试用
替换switch语句时
j = RecievedDataBuffer [0];
upper_nibble = j& 0x0f0等.(与原始问题相同).

应用程序崩溃...您对如何解决此问题有任何建议吗?

干杯

马丁(Martyn)



The problem is its full of switch statements and I would just like to assign j (in my original question) to the imported unsigned char. Although pretty crappy, my original code does the job, but when i try to replace the switch statement with

j = RecievedDataBuffer[0];
upper_nibble = j & 0x0f0 etc..(as in the original question).

The application crashes...Do you have any suggestion of how I could fix this?

Cheers

Martyn


这篇关于我陷入了循环...!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆