In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
If we want to complete the information exchange between the single-chip microcomputer and the computer, we can use the computer to grasp some information of the single-chip microcomputer and send some information of the single-chip microcomputer to the software on the computer. Next we will do a complex routine to complete the data sent by the single-chip microcomputer serial port debugging assistant, which is displayed on the digital tube on our opening board.
# include sbit ADDR3 = P1 ^ 3; sbit ENLED = P1 ^ 4; unsigned char code LedChar [] = {/ / Digital tube display character conversion table 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E}; unsigned char LedBuff [7] = {/ / Digital tube + independent LED display buffer 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned char T0RH = 0; / / high byte unsigned char T0RL of T0 reload value = 0 / / low byte unsigned char RxdByte of T0 overload value = 0; / / bytes accepted by serial port void ConfigTimer0 (unsigned int ms); void ConfigUART (unsigned int baud); void main () {EA = 1; / / enable total ENLED = 0; / / Select digital tube and independent LED ADDR3 = 1; ConfigTimer0 (1); / / set equipment T0 punctual 1ms ConfigUART (9600) / / set the baud rate of the equipment to 9600 while (1) {/ / display the accepted bytes on the digital tube in hexadecimal LedBuff [0] = LedChar [RxdByte & 0x0F]; LedBuff [1] = LedChar [RxdByte > > 4];}} / * set the equipment and start T0mai T0 punctuality * / void ConfigTimer0 (unsigned int ms) {unsigned long tmp; / / temporary variable tmp = 11059200 / 12 / / timer counting frequency tmp = (tmp * ms) / 1000; / / calculation required count value tmp = 65536-tmp; / / calculate punctual attention payload value tmp = tmp + 13; / / compensation for error caused by infix echo delay T0RH = (unsigned char) (tmp > 8); / / punctual attention load value is divided into upper and lower bytes T0RL = (unsigned char) tmp; TMOD & = 0xF0; / / handheld TMOD of zero T0 | = 0x01 / / set equipment T0 to form 1 TH0 = T0RH; / / load T0 overload value TL0 = T0RL; ET0 = 1; / / enable T0 suffix TR0 = 1; / / start T0} / * serial port setting equipment configuration function, baud- communication baud rate * / void ConfigUART (unsigned int baud) {SCON = 0x50; / / set equipment installation serial port to form 1 TMOD & = 0x0F; / / Control bit TMOD of clearing zero T1 | = 0x20 / / set the equipment configuration T1 in the form 2 TH1 = 256-(11059200Universe 12 TH1 32) / baud; / / calculate T1 overload value TL1 = TH1; / / initial value equals overload value ET1 = 0; / / stop T1 infix ES = 1; / / enable serial port suffix TR1 = 1; / / start T1} / * LED static scan refresh function, need to misappropriate * / void LedScan () {static unsigned char i = 0 in the just-in-time suffix. / / static scan index P0 = 0xFF; / / close all segment selections, display hidden P1 = (P1 & 0xF8) | I; / / assign the index value to the lower 3 bits of P1 port P0 = LedBuff [I]; / / send the data of the index status in the buffer to P0 port if (I)
< 6){ //索引递增轮回,遍历全部缓冲区 i++; }else{ i = 0; } } /* T0 中缀效劳函数,完成 LED 扫描 */ void InterruptTimer0() interrupt 1{ TH0 = T0RH; //从新加载重载值 TL0 = T0RL; LedScan(); //LED 扫描显示 } /* UART 中缀效劳函数 */ void InterruptUART() interrupt 4{ if (RI){ //接纳到字节 RI = 0; //手动清零接纳中缀标记位 RxdByte = SBUF; //接纳到的数据保管到接纳字节变量中 //接纳到的数据又直接发还,叫作-"echo", //用以提醒用户输出的信息能否已准确接纳 SBUF = RxdByte; } if (TI){ //字节发送终了 TI = 0; //手动清零发送中缀标记位 } } 人人在做这个试验的时分,有个小成绩要留意一下。由于 STC89C52 下载程序是运用了UART 串口下载,下载完程序后,程序运转起来了,可是下载软件最初还会经过串口发送一些额定的数据,所以程序刚下载出来不是显示 00,而能够是其他数据。人人只需把电源开关封闭,从新翻开一次就好了。 仔细的同窗能够会发现,在串口调试助手发送选项和接纳选项处,还有个"字符格局发送"和"字符格局显示",这是什么意思呢? 先抛开我们运用的汉字不谈,那么我们常用的字符就包括了 0~9 的数字、A~Z/a~z 的字母、还有各类标点符号等。那么在单片机零碎外面我们怎样来表现它们呢? ASCII 码(American Standard Code for Information Interchange,即美国信息交换规范代码)可以完成这个任务:我们晓得,在单片机中一个字节的数据可以有 0~255 共 256 个值,我们取个中的 0~127 共 128 个值付与了它别的一层涵义,即让它们辨别来代表一个常用字符,其详细的对应关系如表 11-3 所示。 表 11-3 ASCII 码字符表 ASC掌握ASCII字符ASCII字符ASCII字符000 值NUL 字符032 值(space)064 值@096 值001SOH033!065A097a002STX034"066B098b003ETX035#067C099c004EOT036$068D100d005END037%069E101e006ACK038&070F102f007BEL039'071G103g008BS040(072H104h009HT041)073I105i010LF042*074J106j011VT043+075K107k012FF044,076L108l013CR045-077M109m014SO046.078N110n015SI047/079O111o016DLE0480080P112p017DC10491081Q113q018DC20502082R114r019DC30513083S115s020DC40524084T116t021NAK0535085U117u022SYN0546086V118v023ETB0557087W119w024CAN0568088X120x025EM0579089Y121y026SUB058:090Z122z027ESC059;091[123{028FS060094^126~031US063?095_127DEL 如许我们就在常用字符和字节数据之间树立了逐个对应的关系,那么如今一个字节就既可以代表一个整数又可以代表一个字符了,但它实质上只是一个字节的数据,而我们付与了它分歧的涵义,什么时分付与它哪一种涵义就看编程者的意图了。ASCII 码在单片机零碎中使用十分普遍,我们后续的课程也会常常运用到它,下面我们来对它做一个直不雅的看法,同窗们必定要深入了解其实质。 对比上述表格,我们就可以完成字符和数字之间的转换了,比方照样这个程序,我们发送的时分改成字符格局发送,接纳照样用十六进制接纳,如许接纳和数码管好做一下比照。 我们用字符格局发送一个小写的 a,前往一个十六进制的 0x61,数码管上显示的也是 61,ASCII 码内外字符 a 对应十进制是 97,等于十六进制的 0x61;我们再用字符格局发送一个数字 1,前往一个十六进制的 0x31,数码管上显示的也是 31,ASCII 内外字符 1 对应的十进制是 49,等于十六进制的 0x31。这下人人就该清晰了:所谓的十六进制发送和十六进制接纳,多是按字节数据的真实值停止的;而字符格局发送和字符格局接纳,是按 ASCII 码表中字符方式停止的,但它实践上最终传输的照样一个字节数据。这个表格,当然不需求人人去记住,了解它,用的时分过去查就行了。 通讯的进修,不像前边掌握局部那么直不雅了,通讯局部我们的程序只能取得一个后果,而其进程我们却无法直接看到,所以渐渐的能够人人就会晓得有示波器和逻辑剖析仪这类丈量仪器。假如黉舍试验室或许公司里有示波器或许逻辑剖析仪这类仪器,可以拿过去抓一下串口波形,直不雅的理解一下。假如临时还没有这些仪器,先晓得这么回事,有前提再说。由于工具类装备有的比拟昂贵,有前提可以尽量运用黉舍或许公司的。在这里我用一款简略单纯的逻辑剖析仪把串口通讯的波形抓出来给人人看一下,人人理解一下即可,如图 11-7 所示。Figure 11-7 Serial port data representation diagram of logic profiler
The influence of profilers and oscilloscopes is to catch the waveforms of the communication process and stop analyzing. Let's talk about the meaning of the waveform. The waveform is low on the right and high on the left. the above waveform is sent to the single-chip microcomputer, and the lower waveform is sent back to the computer by the single-chip microcomputer. Take the above waveform as an example, the first bit on the right is Zhao bit 0, and the order from low to high is 10001100, which is the data 0x31, that is, the'1' inside and outside the ASCII code. Everyone can notice that the profiler has marked a white dot in each data bit, showing that there is no white dot in the data position and when the data is available. The difference between T1 and T2 is shown on the left as 0.102ms, which is about 1 / 9600, slightly biased, within the allowable size. After figure 11-7, we can clearly understand the specific process of sending and receiving serial communication.
Let's understand again here, if we use the serial debugging assistant and send a "12" directly with the character pattern, what should we display on our digital tube? What should the serial debugging assistant go to? Through the experiment, it is found that our digital tube displays 32, while the serial debugging assistant goes to hexadecimal to display 31 and 32 data, as shown in figure 11-8.
Figure 11-8 Serial debugging Assistant data display
Let's use the logic profiler to grab this data and take a look, as shown in figure 11-9.
Figure 11-9 logical profiler grabs data
As far as the ASCII code table is concerned, the number itself is a character rather than data, so if you send "12", in practice, it is to distinguish between "1" and "2". The single-chip microcomputer first receives the first character "1" and displays the corresponding number 31 on the digital tube, but immediately receives the character "2". The digital tube suddenly becomes 32 from 31, and we visually. There is no way to find this rapid change, so we think the digital tube directly shows 32.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.