| |

VerySource

 Forgot password?
 Register
Search
View: 3474|Reply: 13

A simple microcontroller program, everyone help

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-4 17:30:01
| Show all posts |Read mode
I use the serial port debugging assistant on my PC to send 1 to the microcontroller, but the display shows 0xF4, the send 2 shows 0xF5, the send 3 shows 0xF5, the send 4 shows 0xF4, and I think that 1 should be displayed as 0x01, and 2 is 0x02 (I assigned the received data to the P2 port and displayed it with a light-emitting diode) The relevant procedure is as follows. This procedure should be okay.

#include <reg51.h>
#include <string.h>

unsigned char ch;


void init_serialcomm ()
{
SCON = 0x50; // serial mode 1,8-bit UART, enable ucvr
TMOD = 0X20; // timer 1, mode 2, 8-bit reload
PCON = 0x80; // SMOD = 1
TH1 = 0xF4; // Baud: 4800 fosc = 11.0592M
IE = 0x90; // Enable Serial Interrupt
TR1 = 1; // timer 1 run
}

// Serial port receiving interrupt function
void serial () interrupt 4 using 3
{
if (RI)
      {
RI = 0;
ch = SBUF;
      }
}

main ()
{
init_serialcomm (); // Initialize the serial port
while (1)
{
P2 = ch;
Ranch
}
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-9 12:00:02
| Show all posts
Is the rate right?

Your configuration is 9600bps, which is twice as fast
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-17 15:54:01
| Show all posts
Thank you, but there is still a problem No matter what number I send, the upper four digits are always 0111. The lower four digits are no problem. For example, if I send 1, he displays 01110001. I can send a capital letter A, but it becomes 10000001.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-28 10:15:02
| Show all posts
Have you finished the receiving and sending procedure two days ago?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-14 20:15:02
| Show all posts
Not yet. Now I tried the simplest acceptance procedure. I found that the received data is still high.
I am doing graduation project
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-9 00:00:02
| Show all posts
The PC sends 1, is it the ASCII code of the 1 sent? It is possible that the debugging assistant is the '1' character sent instead of 0x01.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-27 14:00:01
| Show all posts
The landlord's program is ok, I tried it, it is normal. Send 1, display 00110001, send 2 display 00110010.
I used 89c51, 22.1184M, the baud rate is 9600
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-7 08:30:01
| Show all posts
I just found that input 1 is sent with the character '1'
Is it a crystal oscillator problem, I used 12M, and the error is more than 8%
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-7 22:15:01
| Show all posts
Haha, in fact, sometimes they are so-called small problems, right?
   It is better to be more careful. I remember the most worrying sentence when my teacher took me to set up:
    Success or failure of detail!
But congratulations, it's finally easy to use!
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-8 11:30:01
| Show all posts
I still miss the program two days ago, it should be the problem defined by buffer[],
        Who has the conditions to try it again, it is easy to give points, hehe
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list