PIC的UART问题 [英] PIC UART Problem with VB

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

问题描述



i与UART有问题,当我从vb发送0并且PIC接收它并将其乘以100时它在LED上变为1111我使用PIC18F452并且有很多连续的UART阅读

任何人都可以帮助我????????



[从OP评论中添加]



这里是PIC中的阅读代码

hi
i have a problem with UART that when i send 0 from vb and the PIC receive it and multiply it by 100 it it become 1111 on the led i use PIC18F452 and have a lot of consecutive UART read
could any one help me ????????

[Added from OP comment]

here is the reading code in PIC

if (UART1_Data_Ready())
       {    a=0;

         for( a=0;a<3;a++)
         {
         ch_Rd= UART1_Read();
         b=ch_Rd;
         delay_ms(2);

         ch_Rd= UART1_Read();
           delay_ms(2);
         acc=ch_Rd;
         b+=acc*100;
         loc[a]=b;

          }



这里是VB的sening代码示例:


and here is a sample of sening code frome the VB :

serial1.Write(1)
        serial1.Write(2)
        serial1.Write(0)
        serial1.Write(3)
        serial1.Write(0)
        serial1.Write(4)
        serial1.Write(0)


当我在leds i上显示loc [1]的内容时
有类似的东西:11110011


when i display the content of loc[1] for example on leds i had something like:11110011

推荐答案

你可能会认为我在这里真的很讨厌 - 我不是......



首先想到的是:你在哪里知道2ms的延迟是否足以保证接收到一个角色?你不能只是去哦,我有一个炭,另一个将在2ms内,所以我会抓住它 - 它不像公共汽车!



因此,当你读UART准备就绪时,你可以抓住它碰巧拥有的任何东西,无论角色是否存在,然后将其乘以100,然后将其填入内存。为什么?为什么100?是应该是一个带字符的特殊数字?因为相信我,它不是......



为什么你不回去开始,并尽量确保你能收到一个字节正确,然后看看你要做什么来接收两个,依此类推,因为它看起来并不像你想到的那样。也许访问Microchip网站及其示例代码会有所帮助吗?
You are probably going to think I''m being really nasty to you here - I''m not...

The first thing that springs to mind is: where did you get the idea that a 2ms delay would be enough time to guarantee the receive of a character will occur? You can''t just go "Oh, I''ve got a char, another one will be along in 2ms, so I''ll grab that" - it''s not like busses!

So when you "read" that the UART is ready, you then grab whatever it happens to have regardless of where there is a character or not, and then multiply it by 100 before stuffing it into memory. Why? Why 100? is that supposed to be a special number with characters? Because trust me, it isn''t...

Why don''t you go right back to the beginning, and try to make sure that you can receive a single byte correctly, then look at what you have to do to receive two, and so on, because it doesn''t look like you have thought things through very far as yet. Perhaps a trip to the Microchip web site and its example code would help?


这篇关于PIC的UART问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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