University of Electronic Science and Technology of China Microprocessor and Embedded Experiment 3

Experiment 3: IO interface programming

Table of contents

Experiment 3: IO interface programming

1. Purpose of the experiment

2. Experimental content

3. Experimental steps

1. Nixie tube experiment

2. UART serial port experiment

4. Experimental results


1. Purpose of the experiment

1. Master the working principle of GPIO and UART interface of ARM.

2. Learn programming to realize the control of GPIO interface and UART communication between ARM and PC.

3. Master the C language programming method under ARM bare metal.

2. Experimental content

1. Learn the principle of serial communication and understand the serial communication control register.

2. Realize I/O interface programming.

3. Experimental steps

1. Nixie tube experiment

1. Double-click to open the vivado project file under the corresponding project folder

2. Select Export under the File menu, click to include bitstream, and click OK

3. Select luanch SDK under the File menu to open the SDK software

4. Create a new project and name it, select Empty Application as the type

5. Add source files to the newly created project and create a new Source File

6. Name the file, pay attention to keep up with the file type. c, click Finish

7. Complete the missing code in the seg_test.c file and add it to the source file: Functions to be completed:

  Use the switch to control the right four digital tubes to display numbers 0~9. When the value is greater than 9, the digital tubes have no display

  Among them, the switch is from low to high from right to left, the open state of the switch is 1, and the closed state is 0. The binary value composed of the switch corresponds to the decimal value displayed on the digital tube

8. Click Save, the software automatically compiles the program

9. Connect the 2 interfaces of the development board to the host computer with the USB data cable, turn on the power switch 7 of the board, and turn all the dial switches of the development board to "on"

10. In vivado, click Open Hardware Manager in the lower left corner, select open target, and then select Auto Connection

11. Click Program device, find the bit stream of the project in the pop-up window, the path of the bit stream file in the project is: project_name/project_name.runs/impl_1/system_wrapper.bit, as shown in the figure below, click Program to download the bit stream to the board

12. Run the program

13. Toggle the switch and observe the display on the digital tube

14. You can use debug to debug the program, see Experiment 2 for details

2. UART serial port experiment

1. Double-click to open the vivado project file under the corresponding project folder

2. Select Export under the File menu, click to include bitstream, and click OK

3. Select luanch SDK under the File menu to open the SDK software

4. Create a new project and name it, select Empty Application as the type

5. Add source files to the newly created project and create a new Source File

6. Name the file, pay attention to keep up with the file type. c, click Finish

7. Complete the missing code in the common_uart.c file and add it to the source file. The functions to be completed:

Send a single character through the UART serial port on the PL, and return the character to the serial port after receiving it. If the received character is "x", exit the program

8. Click Save, the software will automatically compile the program

9. Connect the 2 UART interfaces of the development board to the host computer with a USB data cable, connect the USB port above 5 to the host computer with a double-headed USB cable, and turn on the power switch of the board 7

10. In vivado, click Open Hardware Manager in the lower left corner, select open target, and then select Auto Connection

11. Click Program device, find the bit stream of the project in the pop-up window, the path of the bit stream file in the project is: project_name/project_name.runs/impl_1/system_wrapper.bit, as shown in the figure below, click Program to download the bit stream to the board

12. Computer→Management, check the port number corresponding to Silicon Labs CP210x USB to UART Bridge in Device Manager→Port

13. Open the serial port debugging assistant, set the serial port to the port number, set the baud rate to 9600, keep the rest of the configuration unchanged, and then open the serial port

14. Run the program

15. In the serial port assistant, enter characters, click TX to send, and check whether the correct characters are received in the upper left box

4. Experimental results

The key code of the digital tube experiment:

        case 0 :a=0x3f;

            break;

    /*Complete the rest of the code, define the corresponding digital tube value when data is 1~9*/

    case 1 :a=0x06;

     break;

    case 2 :a=0x5b;

         break;

    case 3 :a=0x4f;

         break;

    case 4 :a=0x66;

         break;

    case 5 :a=0x6d;

     break;

    case 6 :a=0x7d;

     break;

    case 7 :a=0x07;

     break;

    case 8 :a=0x7f;

     break;

    case 9 :a=0x6f;

     break;

    case 10 :a=0x77;

         break;

}

    /*向数码管寄存器中写入值*/

XGpio_DiscreteWrite(&GpioOutput1,SEG_CHANNEL,a);

return XST_SUCCESS;

 

数码管实验实验结果:

 

实验现象:下面开关二进制对应1000,上面是数码管为8。当二进制开关拨动到对应十进制当中的10以外,数码管就不在亮起。

此外还增加了闪烁的功能。

UART串口实验关键代码:

 

UART串口实验结果:

 

实验现象解释:可以看到UART串口实验,当数据输x后,接收数据再增加。

五、实验总结

1.在进行数码管的实验当中,此外还增加了闪烁的功能,通过控制选择后,然后灯会交替闪烁。

2.在实验当中,深入了解了串口通信的原理,掌握了vivado和SDK的熟练使用。

3.掌握了编程实现GPIO接口的控制及ARM和PC机的UART通信,在实验当中发现其实C语言的逻辑思路和我们的汇编语言很相似,体会到了语言之间的融会贯通。

  • 实验思考题

1.查看相关寄存器,思考怎么配置UART时钟信号?

设置mellcon寄存器的值可以设置时钟,改变ulcon的值可以配置UART时钟信号。

2.要实现控制数码管闪烁的功能,有什么办法可以完成

1.向命令寄存器中写入“闪烁控制命令”

2.向命令寄存器中写入“下载数据并译码、Download命令”来完成,Download命令的第八位的D6可控制数码管的闪烁。

Guess you like

Origin blog.csdn.net/weixin_53284122/article/details/129259513