Návštěvní kniha

Datum 07.04.2018

Vložil Deltawiaiit

Titulek Ошибка часточного преобразователя

Another option is to store bytes as they arrive and check each byte for the CR code. Reading individual bytes in a task loop eliminates blocking while waiting for the CR. index var byte received_data var byte 80 receive_serial_data: if PIR1.5 = 1 then 1 A byte is available to read. hserin received_data index if received_data index = 13 then 1 It's a CR code. Do something with the received data. 1 Reset the index. index = 0 1 Increment the index, resetting to 0 if the buffer is full. if index < 79 then index = index + 1 else index = 0 endif endif endif return 252 Ports for Embedded Systems C18 A device that is receiving commands that end with a CR can check for the character on receiving data and take action when received: byte index; char received_data 80 ; void receive_serial_data void if DataRdyUSART // A byte is available. received_data index = getcUSART ; if received_data index == 0x0d // It's a CR code. Do something with the received data. // Reset the index. index = 0; else // Increment the index, resetting to 0 if the buffer is full. if index < 79 index++; index = 0; Using Interrupts When data arrives at unpredictable times, firmware can use the receive interrupt to read bytes as they arrive. With the receive interrupt enabled, the CPU jumps to the interrupt vector a defined location in program memory every time a byte arrives at the port. An ISR can read the received byte and perform any other needed actions. In a similar way, with the transmit interrupt enabled, the CPU jumps to the interrupt vector every time TXREG is newly empty. The ISR can then write 253 Chapter 11 another byte to TXREG for transmitting and perform any other necessary actions. The PIC18F4520 has two interrupt vectors. Multiple interrupts with the same priority share an interrupt vector. If not using interrupt priority, all interrupts use vector 08h. If using interrupt priority, the high-priority interrupts use vector 08h and the low-priority interrupt prom-electric.ru

Zpět na diskuzi