Manchester Code Library
The mikroPascal PRO for FT90x provides a library for handling Manchester coded signals. The Manchester code is a code in which data and clock signals are combined to form a single self-synchronizing data stream; each encoded bit contains a transition at the midpoint of a bit period, the direction of transition determines whether the bit is 0 or 1; the second half is the true bit value and the first half is the complement of the true bit value (as shown in the figure below).

Important :
- The Manchester receive routines are blocking calls (
Man_Receive_InitandMan_Synchro). This means that MCU will wait until the task has been performed (e.g. byte is received, synchronization achieved, etc). - Manchester code library implements time-based activities, so interrupts need to be disabled when using it.
External dependencies of Manchester Code Library
| The following variables must be defined in all projects using Manchester Code Library: | Description: | Example: |
|---|---|---|
var MANRXPIN : sbit; sfr; external; |
Receive line. | var MANRXPIN : sbit at GPIO_PIN6_bit; |
var MANTXPIN : sbit; sfr; external; |
Transmit line. | var MANTXPIN : sbit at GPIO_PIN8_bit; |
Library Routines
The following routines are for the internal use by compiler only:
- Manchester_0
- Manchester_1
- Manchester_Out
Man_Receive_Init
| Prototype |
function Man_Receive_Init() : word; |
|---|---|
| Description |
The function configures Receiver pin. After that, the function performs synchronization procedure in order to retrieve baud rate out of the incoming signal. |
| Parameters |
None. |
| Returns |
|
| Requires |
External dependencies of the library from the top of the page must be defined before using this function. |
| Example |
// Manchester module connections var MANRXPIN: sbit at GPIO_PIN6_bit; var MANTXPIN: sbit at GPIO_PIN8_bit; // End Manchester module connections ... Man_Receive_Init(); // Initialize receiver |
| Notes |
In case of multiple persistent errors on reception, the user should call this routine once again or Man_Synchro routine to enable synchronization. |
Man_Receive
| Prototype |
function Man_Receive(var error : word) : byte; |
|---|---|
| Description |
The function extracts one byte from incoming signal. |
| Parameters |
|
| Returns |
A byte read from the incoming signal. |
| Requires |
To use this function, the user must prepare the MCU for receiving. See Man_Receive_Init routines. |
| Example |
var data_, error : word; ... error := 0; data_ := 0; data_ := Man_Receive(error); if (error <> 0) then begin // error handling end; |
| Notes |
None. |
Man_Send_Init
| Prototype |
procedure Man_Send_Init(); |
|---|---|
| Description |
The function configures Transmitter pin. |
| Parameters |
None. |
| Returns |
Nothing. |
| Requires |
External dependencies of the library from the top of the page must be defined before using this function. |
| Example |
// Manchester module connections var MANRXPIN: sbit at GPIO_PIN6_bit; var MANTXPIN: sbit at GPIO_PIN8_bit; // End Manchester module connections ... Man_Send_Init(); // Initialize transmitter |
| Notes |
None. |
Man_Send
| Prototype |
procedure Man_Send(tr_data : byte); |
|---|---|
| Description |
Sends one byte. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
To use this function, the user must prepare the MCU for sending. See Man_Send_Init routine. |
| Example |
var msg : byte; ... Man_Send(msg); |
| Notes |
Baud rate used is 500 bps. |
Man_Synchro
| Prototype |
function Man_Synchro(): word; |
|---|---|
| Description |
Measures half of the manchester bit length with 10us resolution. |
| Parameters |
None. |
| Returns |
|
| Requires |
To use this function, you must first prepare the MCU for receiving. See Man_Receive_Init. |
| Example |
var man__half_bit_len : word; ... man__half_bit_len := Man_Synchro(); |
| Notes |
None. |
Man_Break
| Prototype |
procedure Man_Break(); |
|---|---|
| Description |
Man_Receive is blocking routine and it can block the program flow. Call this routine from interrupt to unblock the program execution. This mechanism is similar to WDT. |
| Parameters |
None. |
| Returns |
Nothing. |
| Requires |
Nothing. |
| Example |
|
| Notes |
Interrupts should be disabled before using Manchester routines again (see note at the top of this page). |
Library Example
The following code is code for the Manchester receiver, it shows how to use the Manchester Library for receiving data:
The following code is code for the Manchester transmitter, it shows how to use the Manchester Library for transmitting data:
What do you think about this topic ? Send us feedback!




