Im doing an elevator project and my teacher wants it in Arduino code
#define MX_ARD
#define MX_CAL_ARD
#define MX_CLK_SPEED 16000000
#define FCP_NULL Unconnected_Port
#define MX_UART_ID
#define MX_UART_UCSRC
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <avr\io.h>
#include <avr\interrupt.h>
#include <avr\eeprom.h>
#include <avr\wdt.h>
/========================================================================
Use :Include the type definitions
*========================================================================*/
#include "C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\internals.c"
MX_UINT8 FCLV_LOOP1;
MX_UINT8 FCLV_LOOP2;
MX_UINT8 FCLV_LOOP3;
MX_UINT8 FCLV_LOOP4;
/========================================================================
Use :panel
:Variable declarations
:Macro function declarations
*========================================================================*/
#define FCV_FALSE (0)
#define FCV_TRUE (1)
MX_GLOBAL MX_UINT8 FCV_DATO = (0x0);
MX_GLOBAL MX_UINT8 FCV_CONTA = (0x1);
MX_GLOBAL MX_UINT8 FCV_PISOACTUAL = (0x1);
MX_GLOBAL MX_UINT8 FCV_MOVIMIENTO = (0x0);
MX_GLOBAL MX_SINT32 FCV_T = (1000);
/========================================================================
Use :shape_cuboid2
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :shape_cuboid1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :dash_IO_flasher
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :TimeStamp1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :InjectorBase1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :COMPort1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :fcdhelper
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :cal_uart
:Variable declarations
:Macro function declarations
*========================================================================*/
#define MX_UART_UseTX_1 (1)
#define MX_UART_TX_TRIS_1 trisd
#define MX_UART_REF1
#define MX_UART_RTS_PIN_1 (2)
#define MX_UART_DBITS_1 (8)
#define MX_UART_RETURN_1 (0)
#define MX_UART_RX_PORT_1 portd
#define MX_UART_RTS_PORT_1 portb
#define MX_UART_ECHO_1 (0)
#define MX_UART_FLOWEN_1 (0)
#define MX_UART_CTS_PORT_1 portb
#define MX_UART_TX_PIN_1 (1)
#define MX_UART_RX_TRIS_1 trisd
#define MX_UART_BAUD_1 (9600)
#define MX_UART_RTS_TRIS_1 trisb
#define MX_UART_TX_PORT_1 portd
#define MX_UART_RX_PIN_1 (0)
#define MX_UART_UseRX_1 (1)
#define MX_UART_CTS_TRIS_1 trisb
#define MX_UART_CHANNEL_1 (1)
#define MX_UART_INT_1 (0)
#define MX_UART_CTS_PIN_1 (1)
MX_GLOBAL MX_UINT32 FCV_05481_cal_uart__CONSOLE;
MX_UINT8 FCD_05481_cal_uart__ControlPin(MX_UINT8 FCL_PIN, MX_UINT8 FCL_STATE);
void FCD_05481_cal_uart__Prv_TextConsole(MX_CHAR *FCL_STR, MX_UINT16 FCLsz_STR, MX_UINT8 FCL_COLOUR);
void FC_CAL_UART_UpdateBaud_1(MX_UINT8 FCL_NEW_BAUD);
MX_UINT8 FCD_05481_cal_uart__TestProperty(MX_UINT8 FCL_PROPERTY);
void FCD_05481_cal_uart__Prv_SimShowWaveform(MX_UINT8 FCL_TXRX, MX_UINT16 FCL_DATA);
MX_SINT16 FC_CAL_UART_Receive_1(MX_UINT8 FCL_TIMEOUT);
void FC_CAL_UART_Send_1(MX_UINT16 FCL_CHAR);
void FC_CAL_UART_Init_1();
void FC_CAL_UART_Delay_1();
void FC_CAL_UART_Uninit_1();
/========================================================================
Use :Bluetooth_HC05
:Variable declarations
:Macro function declarations
*========================================================================*/
void FCD_07aa1_Bluetooth_HC05__SetPairKey(MX_CHAR *PFCL_KEY);
void FCD_07aa1_Bluetooth_HC05__SendString(MX_CHAR *FCL_DATA, MX_UINT16 FCLsz_DATA);
void FCD_07aa1_Bluetooth_HC05__SendCommand(MX_CHAR *FCL_COMMAND, MX_UINT16 FCLsz_COMMAND);
void FCD_07aa1_Bluetooth_HC05__SetBaud(MX_BOOL FCL_BAUD);
void FCD_07aa1_Bluetooth_HC05__SendNumber(MX_SINT32 FCL_NUMBER);
void FCD_07aa1_Bluetooth_HC05__SendChar(MX_SINT16 FCL_CHAR);
void FCD_07aa1_Bluetooth_HC05__SetName(MX_CHAR *PFCL_NAME);
void FCD_07aa1_Bluetooth_HC05__ReceiveString(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL, MX_UINT8 FCL_TIMEOUT, MX_UINT8 FCL_NUMBYTES);
void FCD_07aa1_Bluetooth_HC05__Initialise();
MX_SINT16 FCD_07aa1_Bluetooth_HC05__ReceiveChar(MX_SINT16 FCL_TIMEOUT);
/========================================================================
Use :motion_helper1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :motor_base1
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :ctrl_lcd
:Variable declarations
:Macro function declarations
*========================================================================*/
/========================================================================
Use :LCD
:Variable declarations
:Macro function declarations
*========================================================================*/
void FCD_04071_LCD__Clear();
void FCD_04071_LCD__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT);
void FCD_04071_LCD__PrintAscii(MX_UINT8 FCL_CHARACTER);
void FCD_04071_LCD__PrintNumber(MX_SINT16 FCL_NUMBER);
void FCD_04071_LCD__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7);
void FCD_04071_LCD__ClearLine(MX_UINT8 FCL_LINE);
void FCD_04071_LCD__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y);
void FCD_04071_LCD__Command(MX_UINT8 FCL_INSTRUCTION);
void FCD_04071_LCD__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT);
void FCD_04071_LCD__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION);
void FCD_04071_LCD__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE);
void FCD_04071_LCD__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER);
void FCD_04071_LCD__Start();
/========================================================================
Use :lcd_16x2
:Variable declarations
:Macro function declarations
*========================================================================*/
#define FCD_0f9e1_lcd_16x2__Clear FCD_04071_LCD__Clear
#define FCD_0f9e1_lcd_16x2__PrintString FCD_04071_LCD__PrintString
#define FCD_0f9e1_lcd_16x2__PrintAscii FCD_04071_LCD__PrintAscii
#define FCD_0f9e1_lcd_16x2__PrintNumber FCD_04071_LCD__PrintNumber
#define FCD_0f9e1_lcd_16x2__RAMWrite FCD_04071_LCD__RAMWrite
#define FCD_0f9e1_lcd_16x2__ClearLine FCD_04071_LCD__ClearLine
#define FCD_0f9e1_lcd_16x2__Cursor FCD_04071_LCD__Cursor
#define FCD_0f9e1_lcd_16x2__Command FCD_04071_LCD__Command
#define FCD_0f9e1_lcd_16x2__PrintFormattedNumber FCD_04071_LCD__PrintFormattedNumber
#define FCD_0f9e1_lcd_16x2__ScrollDisplay FCD_04071_LCD__ScrollDisplay
#define FCD_0f9e1_lcd_16x2__RawSend FCD_04071_LCD__RawSend
#define FCD_0f9e1_lcd_16x2__RemapCharacter FCD_04071_LCD__RemapCharacter
#define FCD_0f9e1_lcd_16x2__Start FCD_04071_LCD__Start
/========================================================================
Use :Include the chip adaption layer
*========================================================================*/
#include "C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\includes.c"
/========================================================================
Use :shape_cuboid2
:Macro implementations
*========================================================================*/
/========================================================================
Use :shape_cuboid1
:Macro implementations
*========================================================================*/
/========================================================================
Use :dash_IO_flasher
:Macro implementations
*========================================================================*/
/========================================================================
Use :TimeStamp1
:Macro implementations
*========================================================================*/
/========================================================================
Use :InjectorBase1
:Macro implementations
*========================================================================*/
/========================================================================
Use :COMPort1
:Macro implementations
*========================================================================*/
/========================================================================
Use :fcdhelper
:Macro implementations
*========================================================================*/
/========================================================================
Use :cal_uart
:Macro implementations
*========================================================================/
/=----------------------------------------------------------------------=*
Use :Allows direct control over the TX and RTS pins
:Also allows for reading of the state of the RX and CTS pins.
:Only available when the UART is uninitialised.
:
:Parameters for macro ControlPin:
: Pin : 0=TX, 1=RX, 2=RTS, 3=CTS
: State : MX_UINT8
:
:Returns : MX_UINT8
*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_05481_cal_uart__ControlPin(MX_UINT8 FCL_PIN, MX_UINT8 FCL_STATE)
{
//Local variable definitions
MX_UINT8 FCR_RETVAL;
switch (FCL_PIN)
{
case 1:
{
#if (1)
FCR_RETVAL = GET_PORT_PIN(D, 0);
// #else
//Code has been optimised out by the pre-processor
#endif
break;
}
case 2:
{
#if (0)
//Code has been optimised out by the pre-processor
// #else
#endif
break;
}
case 3:
{
#if (0)
//Code has been optimised out by the pre-processor
// #else
#endif
break;
}
default:
{
#if (1)
if (FCL_STATE)
{
SET_PORT_PIN(D, 1, 1);
} else {
SET_PORT_PIN(D, 1, 0);
}
// #else
//Code has been optimised out by the pre-processor
#endif
}
}
return (FCR_RETVAL);
}
/=----------------------------------------------------------------------=
Use :Parameters for macro Prv_TextConsole:
: Str[20] : MX_CHAR (by-ref)
: colour : MX_UINT8
*=----------------------------------------------------------------------=*/
void FCD_05481_cal_uart__Prv_TextConsole(MX_CHAR *FCL_STR, MX_UINT16 FCLsz_STR, MX_UINT8 FCL_COLOUR)
{
switch (FCL_COLOUR)
{
case 1:
{
break;
}
case 2:
{
break;
}
default:
{
}
}
}
/=----------------------------------------------------------------------=
Use :A simple macro to allow us to test the value of a single property during runtime.
:
:Parameters for macro TestProperty:
: Property : 0=UseTX, 1=UseRX, 2=UseFlowControl
:
:Returns : MX_UINT8
*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_05481_cal_uart__TestProperty(MX_UINT8 FCL_PROPERTY)
{
//Local variable definitions
MX_UINT8 FCR_RETVAL;
FCR_RETVAL = 0;
if (FCL_PROPERTY == 0)
{
#if (1)
FCR_RETVAL = 1;
// #else
//Code has been optimised out by the pre-processor
#endif
// } else {
}
if (FCL_PROPERTY == 1)
{
#if (1)
FCR_RETVAL = 1;
// #else
//Code has been optimised out by the pre-processor
#endif
// } else {
}
if (FCL_PROPERTY == 2)
{
#if (0)
//Code has been optimised out by the pre-processor
// #else
#endif
// } else {
}
return (FCR_RETVAL);
}
/=----------------------------------------------------------------------=
Use :Parameters for macro Prv_SimShowWaveform:
: TXRX : MX_UINT8
: Data : MX_UINT16
*=----------------------------------------------------------------------=*/
void FCD_05481_cal_uart__Prv_SimShowWaveform(MX_UINT8 FCL_TXRX, MX_UINT16 FCL_DATA)
{
if (FCL_TXRX)
{
SET_PORT_PIN(D, 0, 0);
FCI_DELAYBYTE_US(104);
for (FCLV_LOOP4=0; (FCLV_LOOP4)<(8); (FCLV_LOOP4)++)
{
if (FCL_DATA & 0x01)
{
SET_PORT_PIN(D, 0, 1);
} else {
SET_PORT_PIN(D, 0, 0);
}
FCI_DELAYBYTE_US(104);
FCL_DATA = FCL_DATA >> 1;
}
SET_PORT_PIN(D, 0, 1);
FCI_DELAYBYTE_US(104);
} else {
SET_PORT_PIN(D, 1, 0);
FCI_DELAYBYTE_US(104);
for (FCLV_LOOP3=0; (FCLV_LOOP3)<(8); (FCLV_LOOP3)++)
{
if (FCL_DATA & 0x01)
{
SET_PORT_PIN(D, 1, 1);
} else {
SET_PORT_PIN(D, 1, 0);
}
FCI_DELAYBYTE_US(104);
FCL_DATA = FCL_DATA >> 1;
}
SET_PORT_PIN(D, 1, 1);
FCI_DELAYBYTE_US(104);
}
}
/========================================================================
Use :Bluetooth_HC05
:Macro implementations
*========================================================================/
/=----------------------------------------------------------------------=*
Use :Sets the Bluetooth pair key stored in the Bluetooth module's ROM.
:Commands must be sent before Bluetooth communications are estabished e.g. right after power on and initialisation.
:
:Parameters for macro SetPairKey:
: Key[5] : Four digit pair key e.g. "0000" or "1234"
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SetPairKey(MX_CHAR *PFCL_KEY)
{
//Local variable definitions
#define FCLsz_COMMAND 28
MX_CHAR FCL_COMMAND[FCLsz_COMMAND];
#define FCLsz_KEY 5
MX_CHAR FCL_KEY[FCLsz_KEY];
FCI_CONCATENATE(PFCL_KEY,FCLsz_KEY,"",0,FCL_KEY,FCLsz_KEY);
FCI_SHEAD("AT+PIN",7, FCL_KEY,FCLsz_KEY, FCL_COMMAND,28);
FCD_07aa1_Bluetooth_HC05__SendCommand(FCL_COMMAND, FCLsz_COMMAND);
//Local variable definitions
#undef FCLsz_COMMAND
#undef FCLsz_KEY
}
/=----------------------------------------------------------------------=
Use :Sends out a string of bytes from the UART interface.
:
:Parameters for macro SendString:
: Data[20] : MX_CHAR (by-ref)
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SendString(MX_CHAR *FCL_DATA, MX_UINT16 FCLsz_DATA)
{
//Local variable definitions
MX_UINT8 FCL_LEN;
MX_UINT8 FCL_IDX;
FCL_LEN = FCI_GETLENGTH(FCL_DATA, FCLsz_DATA);
FCL_IDX = 0;
while (FCL_IDX < FCL_LEN)
{
FC_CAL_UART_Send_1(FCL_DATA[FCL_IDX]);
FCL_IDX = FCL_IDX + 1;
}
}
/=----------------------------------------------------------------------=
Use :Sends a command string to the HC05/HC06 module.
:
:Parameters for macro SendCommand:
: Command[28] : MX_CHAR (by-ref)
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SendCommand(MX_CHAR *FCL_COMMAND, MX_UINT16 FCLsz_COMMAND)
{
for (FCLV_LOOP1=0; (FCLV_LOOP1)<(10); (FCLV_LOOP1)++)
{
FCD_07aa1_Bluetooth_HC05__ReceiveChar(1);
}
FCD_07aa1_Bluetooth_HC05__SendString(FCL_COMMAND, FCLsz_COMMAND);
FCD_07aa1_Bluetooth_HC05__SendChar('\r');
FCD_07aa1_Bluetooth_HC05__SendChar('\n');
for (FCLV_LOOP2=0; (FCLV_LOOP2)<(50); (FCLV_LOOP2)++)
{
FCD_07aa1_Bluetooth_HC05__ReceiveChar(1);
}
}
/=----------------------------------------------------------------------=
Use :Sets the Bluetooth baud rate stored in the Bluetooth module's ROM.
:Commands must be sent before Bluetooth communications are estabished e.g. right after power on and initialisation.
:
:Parameters for macro SetBaud:
: Baud : 1=1200, 2=2400, 3=4800, 4=9600, 5=19200, 6=NA, 7=38400, 8=57600, 9=115200
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SetBaud(MX_BOOL FCL_BAUD)
{
//Local variable definitions
#define FCLsz_COMMAND 28
MX_CHAR FCL_COMMAND[FCLsz_COMMAND];
if (FCL_BAUD > 0)
{
if (FCL_BAUD < 10)
{
if (FCL_BAUD == 6)
{
} else {
if (FCL_BAUD > 6)
{
FCI_SHEAD("AT+BAUD",8, FCI_TOSTRING(FCL_BAUD - 1, FCI_TMP_STR,20),20, FCL_COMMAND,28);
FCD_07aa1_Bluetooth_HC05__SendCommand(FCL_COMMAND, FCLsz_COMMAND);
FC_CAL_UART_UpdateBaud_1(FCL_BAUD);
} else {
FCI_SHEAD("AT+BAUD",8, FCI_TOSTRING(FCL_BAUD, FCI_TMP_STR,20),20, FCL_COMMAND,28);
FCD_07aa1_Bluetooth_HC05__SendCommand(FCL_COMMAND, FCLsz_COMMAND);
FC_CAL_UART_UpdateBaud_1(FCL_BAUD);
}
}
// } else {
}
// } else {
}
//Local variable definitions
#undef FCLsz_COMMAND
}
/=----------------------------------------------------------------------=
Use :Sends out a number as an ASCII String from the UART interface.
:
:Parameters for macro SendNumber:
: Number : MX_SINT32 (by-ref)
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SendNumber(MX_SINT32 FCL_NUMBER)
{
//Local variable definitions
#define FCLsz_NUMSTR 20
MX_CHAR FCL_NUMSTR[FCLsz_NUMSTR];
FCI_TOSTRING(FCL_NUMBER, FCL_NUMSTR,20);
FCD_07aa1_Bluetooth_HC05__SendString(FCL_NUMSTR, FCLsz_NUMSTR);
//Local variable definitions
#undef FCLsz_NUMSTR
}
/=----------------------------------------------------------------------=
Use :Sends out a single packet from the UART interface.
:
:Parameters for macro SendChar:
: Char : MX_SINT16
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SendChar(MX_SINT16 FCL_CHAR)
{
FC_CAL_UART_Send_1(FCL_CHAR);
}
/=----------------------------------------------------------------------=
Use :Sets the Bluetooth Friendly name stored in the Bluetooth module's ROM.
:Commands must be sent before Bluetooth communications are estabished e.g. right after power on and initialisation.
:
:Parameters for macro SetName:
: Name[20] : Name you wish to provide to the module
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__SetName(MX_CHAR *PFCL_NAME)
{
//Local variable definitions
#define FCLsz_COMMAND 28
MX_CHAR FCL_COMMAND[FCLsz_COMMAND];
#define FCLsz_NAME 20
MX_CHAR FCL_NAME[FCLsz_NAME];
FCI_CONCATENATE(PFCL_NAME,FCLsz_NAME,"",0,FCL_NAME,FCLsz_NAME);
FCI_SHEAD("AT+NAME",8, FCL_NAME,FCLsz_NAME, FCL_COMMAND,28);
FCD_07aa1_Bluetooth_HC05__SendCommand(FCL_COMMAND, FCLsz_COMMAND);
//Local variable definitions
#undef FCLsz_COMMAND
#undef FCLsz_NAME
}
/=----------------------------------------------------------------------=
Use :Attempts to receive a string of bytes from the UART interface.
:
:Parameters for macro ReceiveString:
: Timeout : MX_UINT8
: NumBytes : MX_UINT8
:
:Returns : MX_CHAR*
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__ReceiveString(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL, MX_UINT8 FCL_TIMEOUT, MX_UINT8 FCL_NUMBYTES)
{
//Local variable definitions
MX_SINT16 FCL_ERRORVAL;
MX_UINT8 FCL_CHCOUNT = (0x0);
MX_SINT16 FCL_RETVAL;
MX_UINT8 FCL_CH;
while (FCL_CHCOUNT < FCL_NUMBYTES)
{
FCL_RETVAL = FC_CAL_UART_Receive_1(FCL_TIMEOUT);
if (FCL_RETVAL < 255)
{
FCL_CH = FCL_RETVAL & 0xff;
FCR_RETVAL[FCL_CHCOUNT] = FCL_CH;
FCL_CHCOUNT = FCL_CHCOUNT + 1;
} else {
FCR_RETVAL[FCL_CHCOUNT] = 0;
FCL_CHCOUNT = FCL_NUMBYTES;
}
}
}
/=----------------------------------------------------------------------=
Use :Sets up the RS232 peripheral, must be called at the start of your program or at least before you start calling any other RS232 macros.
*=----------------------------------------------------------------------=*/
void FCD_07aa1_Bluetooth_HC05__Initialise()
{
FC_CAL_UART_Init_1();
}
/=----------------------------------------------------------------------=
Use :Attempts to receive a single packet from the UART interface.
:
:Parameters for macro ReceiveChar:
: Timeout : Time to wait for valid data before returning, 0=Dont wait, 255=Wait forever.
:
:Returns : MX_SINT16
*=----------------------------------------------------------------------=*/
MX_SINT16 FCD_07aa1_Bluetooth_HC05__ReceiveChar(MX_SINT16 FCL_TIMEOUT)
{
//Local variable definitions
MX_SINT16 FCR_RETVAL;
FCR_RETVAL = FC_CAL_UART_Receive_1(FCL_TIMEOUT);
return (FCR_RETVAL);
}
/========================================================================
Use :motion_helper1
:Macro implementations
*========================================================================*/
/========================================================================
Use :motor_base1
:Macro implementations
*========================================================================*/
/========================================================================
Use :ctrl_lcd
:Macro implementations
*========================================================================*/
/========================================================================
Use :LCD
:Macro implementations
*========================================================================/
/=----------------------------------------------------------------------=
Use :Clears the entire contents of the display.
*=----------------------------------------------------------------------=/
void FCD_04071_LCD__Clear()
{
FCD_04071_LCD__RawSend(0x01, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x02, 0);
FCI_DELAYBYTE_MS(2);
}
/=----------------------------------------------------------------------=
Use :Breaks down a string of text and sends it to the LCD via the private RawSend(byte, mask) macro
:
:Parameters for macro PrintString:
: Text[20] : Enter the text or variable to print to the LCD
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintString(MX_CHAR *FCL_TEXT, MX_UINT16 FCLsz_TEXT)
{
//Local variable definitions
MX_UINT8 FCL_IDX = (0x0);
MX_UINT8 FCL_COUNT;
FCL_COUNT = FCI_GETLENGTH(FCL_TEXT, FCLsz_TEXT);
while (FCL_IDX < FCL_COUNT)
{
#if (0) // 0 > 0
//Code has been optimised out by the pre-processor
#else
FCD_04071_LCD__RawSend(FCL_TEXT[FCL_IDX], 0x10);
#endif
FCL_IDX = FCL_IDX + 1;
}
}
/=----------------------------------------------------------------------=
Use :Takes the ascii value for a character and prints the character
:
:Parameters for macro PrintAscii:
: character : Holds an ascii value.
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintAscii(MX_UINT8 FCL_CHARACTER)
{
FCD_04071_LCD__RawSend(FCL_CHARACTER, 0x10);
}
/=----------------------------------------------------------------------=
Use :Based on v5 macro, will allow you to print a number. This is limited to a signed-INT, -32768 to 32767
:
:Parameters for macro PrintNumber:
: Number : Enter the number or variable to print to the LCD
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintNumber(MX_SINT16 FCL_NUMBER)
{
//Local variable definitions
#define FCLsz_S 10
MX_CHAR FCL_S[FCLsz_S];
FCI_TOSTRING(FCL_NUMBER, FCL_S,10);
FCD_04071_LCD__PrintString(FCL_S, FCLsz_S);
//Local variable definitions
#undef FCLsz_S
}
/=----------------------------------------------------------------------=
Use :Modifies the internal memory of the LCD to allow for up to 8 customised characters to be created and stored in the device memory
:
:Parameters for macro RAMWrite:
: Index : Values 0 to 7
: d0 : MX_UINT8
: d1 : MX_UINT8
: d2 : MX_UINT8
: d3 : MX_UINT8
: d4 : MX_UINT8
: d5 : MX_UINT8
: d6 : MX_UINT8
: d7 : MX_UINT8
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RAMWrite(MX_UINT8 FCL_INDEX, MX_UINT8 FCL_D0, MX_UINT8 FCL_D1, MX_UINT8 FCL_D2, MX_UINT8 FCL_D3, MX_UINT8 FCL_D4, MX_UINT8 FCL_D5, MX_UINT8 FCL_D6, MX_UINT8 FCL_D7)
{
FCD_04071_LCD__RawSend(64 + (FCL_INDEX << 3), 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(FCL_D0, 0x10);
FCD_04071_LCD__RawSend(FCL_D1, 0x10);
FCD_04071_LCD__RawSend(FCL_D2, 0x10);
FCD_04071_LCD__RawSend(FCL_D3, 0x10);
FCD_04071_LCD__RawSend(FCL_D4, 0x10);
FCD_04071_LCD__RawSend(FCL_D5, 0x10);
FCD_04071_LCD__RawSend(FCL_D6, 0x10);
FCD_04071_LCD__RawSend(FCL_D7, 0x10);
FCD_04071_LCD__Clear();
}
/=----------------------------------------------------------------------=
Use :Clears a single line on the display and then moves the cursor to the start of the line to allow you to start populating the line with data.
:
:Parameters for macro ClearLine:
: Line : The line to clear, zero being the first (top) line of the display
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__ClearLine(MX_UINT8 FCL_LINE)
{
//Local variable definitions
MX_UINT8 FCL_X;
if (FCL_LINE < 2)
{
FCD_04071_LCD__Cursor(0, FCL_LINE);
FCL_X = 0;
while (FCL_X < 16)
{
FCD_04071_LCD__RawSend(' ', 0x10);
FCL_X = FCL_X + 1;
}
FCD_04071_LCD__Cursor(0, FCL_LINE);
// } else {
}
}
/=----------------------------------------------------------------------=
Use :Moves the cursor on the LCD Display
:
:Parameters for macro Cursor:
: x : Set the cursor position in the X plane, 0 is the left most cell
: y : Set the cursor position in the Y plane, 0 is the top most cell
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Cursor(MX_UINT8 FCL_X, MX_UINT8 FCL_Y)
{
#if (0) // 2 == 1
//Code has been optimised out by the pre-processor
// #else
#endif
#if (1) // 2 == 2
if (FCL_Y == 0)
{
FCL_Y = 0x80;
} else {
FCL_Y = 0xC0;
}
// #else
//Code has been optimised out by the pre-processor
#endif
#if (0) // 2 == 4
//Code has been optimised out by the pre-processor
// #else
#endif
FCD_04071_LCD__RawSend(FCL_Y + FCL_X, 0);
FCI_DELAYBYTE_MS(2);
}
/=----------------------------------------------------------------------=
Use :Use this method/macro to send a specific command to the LCD. Refer to the Matrix Multimedia EB006 datasheet for a list of supported instructions. For Non-Matrix LCD's refer to the manufacturers datasheet.
:
:Parameters for macro Command:
: instruction : Send a defined command to the LCD Screen. See datasheet for supported commands.
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Command(MX_UINT8 FCL_INSTRUCTION)
{
FCD_04071_LCD__RawSend(FCL_INSTRUCTION, 0);
FCI_DELAYBYTE_MS(2);
}
/=----------------------------------------------------------------------=
Use :Will allow you to print a number up to 32-bits with signed or unsigned formatting.
:Signed = -2147483648 to 2147483647
:Unsigned = 0 to 4294967295
:
:Parameters for macro PrintFormattedNumber:
: Number : Enter the number or variable to print to the LCD
: Format : 0=Signed, 1=Unsigned
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__PrintFormattedNumber(MX_UINT32 FCL_NUMBER, MX_BOOL FCL_FORMAT)
{
//Local variable definitions
#define FCLsz_S 15
MX_CHAR FCL_S[FCLsz_S];
if (FCL_FORMAT == 1)
{
FCI_UTOS32(FCL_NUMBER, FCL_S,15);
} else {
FCI_ITOS32((MX_SINT32)(FCL_NUMBER), FCL_S,15);
}
FCD_04071_LCD__PrintString(FCL_S, FCLsz_S);
//Local variable definitions
#undef FCLsz_S
}
/=----------------------------------------------------------------------=
Use :Scrolls the display left or right by a number of given positions.
:
:Parameters for macro ScrollDisplay:
: Position : Holds the number of positions to shift the display
: Direction : 0 = left, 1 = right
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__ScrollDisplay(MX_UINT8 FCL_POSITION, MX_UINT8 FCL_DIRECTION)
{
//Local variable definitions
MX_UINT8 FCL_CMD = (0x0);
FCL_CMD = 0;
if (FCL_DIRECTION == 0)
{
FCL_CMD = 0x18;
} else {
FCL_CMD = 0x1C;
}
if (FCL_CMD != 0 && FCL_POSITION != 0)
{
while (FCL_POSITION != 0)
{
FCD_04071_LCD__RawSend(FCL_CMD, 0);
FCL_POSITION = FCL_POSITION - 1;
}
// } else {
}
}
/=----------------------------------------------------------------------=
Use :Sends data to the LCD display
:
:Parameters for macro RawSend:
: data : The data byte to send to the LCD
: type : A boolean to indicate command type: true to write data, false to write a command
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RawSend(MX_UINT8 FCL_DATA, MX_BOOL FCL_TYPE)
{
//Local variable definitions
MX_UINT8 FCL_NIBBLE;
//Comment:
//Output upper nibble of the byte
#if (1) // 0 == 0
SET_PORT_PIN(B, 0, 0);
SET_PORT_PIN(B, 1, 0);
SET_PORT_PIN(B, 2, 0);
SET_PORT_PIN(B, 3, 0);
SET_PORT_PIN(B, 4, 0);
SET_PORT_PIN(B, 5, 0);
#if (0)
//Code has been optimised out by the pre-processor
// #else
#endif
FCL_NIBBLE = (FCL_DATA >> 4);
SET_PORT_PIN(B, 0, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 1, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 2, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 3, (FCL_NIBBLE & 0x01));
// #else
//Code has been optimised out by the pre-processor
#endif
//Comment:
//Output byte to pins
#if (0) // 0 == 1
//Code has been optimised out by the pre-processor
// #else
#endif
//Comment:
//Output byte to port
#if (0) // 0 == 2
//Code has been optimised out by the pre-processor
// #else
#endif
if (FCL_TYPE)
{
SET_PORT_PIN(B, 4, 1);
// } else {
}
FCI_DELAYBYTE_US(100);
//Comment:
//Set Enable high, pause then set low
//to acknowledge the data has been
//submitted.
SET_PORT_PIN(B, 5, 1);
FCI_DELAYBYTE_US(100);
SET_PORT_PIN(B, 5, 0);
FCI_DELAYBYTE_US(100);
#if (1) // 0 == 0
SET_PORT_PIN(B, 0, 0);
SET_PORT_PIN(B, 1, 0);
SET_PORT_PIN(B, 2, 0);
SET_PORT_PIN(B, 3, 0);
SET_PORT_PIN(B, 4, 0);
FCL_NIBBLE = (FCL_DATA & 0xf);
SET_PORT_PIN(B, 0, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 1, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 2, (FCL_NIBBLE & 0x01));
FCL_NIBBLE = FCL_NIBBLE >> 1;
SET_PORT_PIN(B, 3, (FCL_NIBBLE & 0x01));
if (FCL_TYPE)
{
SET_PORT_PIN(B, 4, 1);
// } else {
}
FCI_DELAYBYTE_US(100);
SET_PORT_PIN(B, 5, 1);
FCI_DELAYBYTE_US(100);
SET_PORT_PIN(B, 5, 0);
FCI_DELAYBYTE_US(100);
// #else
//Code has been optimised out by the pre-processor
#endif
}
/=----------------------------------------------------------------------=
Use :Assigns a remap character allowing the PrintString function to automatically swap between pre-defined characters.
:The characters can be custom (in the range 0-9) or can point to an existing character in the LCD character map.
:
:Parameters for macro RemapCharacter:
: RemapIdx : Remap Index, Range: 0 to (Remap Characters - 1)
: SearchCharacter : Character to look for a replace
: ReplacementCharacter : New character value to use in place of the search character.
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__RemapCharacter(MX_UINT8 FCL_REMAPIDX, MX_UINT8 FCL_SEARCHCHARACTER, MX_UINT8 FCL_REPLACEMENTCHARACTER)
{
#if (0) // 0 > 0
//Code has been optimised out by the pre-processor
// #else
#endif
}
/=----------------------------------------------------------------------=
Use :Startup routine required by the hardware device.
:Automatically clears the display after initialising.
*=----------------------------------------------------------------------=*/
void FCD_04071_LCD__Start()
{
#if (1) // 0 == 0
SET_PORT_PIN(B, 0, 0);
SET_PORT_PIN(B, 1, 0);
SET_PORT_PIN(B, 2, 0);
SET_PORT_PIN(B, 3, 0);
SET_PORT_PIN(B, 4, 0);
SET_PORT_PIN(B, 5, 0);
// #else
//Code has been optimised out by the pre-processor
#endif
#if (0) // 0 == 1
//Code has been optimised out by the pre-processor
// #else
#endif
#if (0) // 0 == 2
//Code has been optimised out by the pre-processor
// #else
#endif
#if (0)
//Code has been optimised out by the pre-processor
// #else
#endif
FCI_DELAYBYTE_MS(12);
FCD_04071_LCD__RawSend(0x33, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x33, 0);
FCI_DELAYBYTE_MS(2);
#if (0) // 0 > 0
//Code has been optimised out by the pre-processor
#else
FCD_04071_LCD__RawSend(0x32, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x2c, 0);
#endif
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x06, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x0c, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x01, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__RawSend(0x02, 0);
FCI_DELAYBYTE_MS(2);
FCD_04071_LCD__Clear();
#if (0) // 0 > 0
//Code has been optimised out by the pre-processor
// #else
#endif
}
/========================================================================
Use :lcd_16x2
:Macro implementations
*========================================================================*/
/========================================================================
Use :panel
:Macro implementations
*========================================================================*/
/========================================================================
Use :Main
*========================================================================*/
int main()
{
MCUSR=0x00;
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Start()
FCD_0f9e1_lcd_16x2__Start();
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("piso 1")
FCD_0f9e1_lcd_16x2__PrintString("piso 1", 7);
// Name: Call Component Macro, Type: Call Component Macro: Bluetooth_HC05::Initialise()
FCD_07aa1_Bluetooth_HC05__Initialise();
// Name: Loop, Type: Loop: While 1
while (1)
{
// Name: Call Component Macro, Type: Call Component Macro: DATO=Bluetooth_HC05::ReceiveChar(30)
FCV_DATO = FCD_07aa1_Bluetooth_HC05__ReceiveChar(30);
// Name: Switch, Type: Switch: DATO?
switch (FCV_DATO)
{
case 'A':
{
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: conta = 1
FCV_CONTA = 1;
break;
}
case 'B':
{
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: conta = 2
FCV_CONTA = 2;
break;
}
case 'C':
{
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: conta = 3
FCV_CONTA = 3;
break;
}
// default:
}
// Name: Decision, Type: Decision: conta > pisoactual?
if (FCV_CONTA > FCV_PISOACTUAL)
{
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: movimiento = conta - pisoactual
FCV_MOVIMIENTO = FCV_CONTA - FCV_PISOACTUAL;
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Clear()
FCD_0f9e1_lcd_16x2__Clear();
// Name: Output, Type: Output: 1 -> C1
SET_PORT_PIN(C,1,(1));
// Name: Output, Type: Output: 0 -> C0
SET_PORT_PIN(C,0,(0));
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("subiendo")
FCD_0f9e1_lcd_16x2__PrintString("subiendo", 9);
// Name: Delay, Type: Delay: 4 * movimiento s
FCI_DELAYBYTE_S(4 * FCV_MOVIMIENTO);
// Name: Output, Type: Output: 0 -> C1
SET_PORT_PIN(C,1,(0));
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: pisoactual = conta
FCV_PISOACTUAL = FCV_CONTA;
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Clear()
FCD_0f9e1_lcd_16x2__Clear();
// } else {
}
// Name: Decision, Type: Decision: pisoactual == 2?
if (FCV_PISOACTUAL == 2)
{
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("piso 2")
FCD_0f9e1_lcd_16x2__PrintString("piso 2", 7);
// } else {
}
// Name: Decision, Type: Decision: pisoactual == 3?
if (FCV_PISOACTUAL == 3)
{
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("piso 3")
FCD_0f9e1_lcd_16x2__PrintString("piso 3", 7);
// } else {
}
// Name: Decision, Type: Decision: pisoactual == 1?
if (FCV_PISOACTUAL == 1)
{
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("piso 1")
FCD_0f9e1_lcd_16x2__PrintString("piso 1", 7);
// } else {
}
// Name: Decision, Type: Decision: conta < pisoactual?
if (FCV_CONTA < FCV_PISOACTUAL)
{
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: movimiento = pisoactual - conta
FCV_MOVIMIENTO = FCV_PISOACTUAL - FCV_CONTA;
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Clear()
FCD_0f9e1_lcd_16x2__Clear();
// Name: Output, Type: Output: 1 -> C0
SET_PORT_PIN(C,0,(1));
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Cursor(4, 0)
FCD_0f9e1_lcd_16x2__Cursor(4, 0);
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::PrintString("bajando")
FCD_0f9e1_lcd_16x2__PrintString("bajando", 8);
// Name: Delay, Type: Delay: 4 * movimiento s
FCI_DELAYBYTE_S(4 * FCV_MOVIMIENTO);
// Name: Output, Type: Output: 0 -> C0
SET_PORT_PIN(C,0,(0));
// Name: Calculation, Type: Calculation:
// Name: Calculation, Type: pisoactual = conta
FCV_PISOACTUAL = FCV_CONTA;
// Name: Call Component Macro, Type: Call Component Macro: lcd_16x2::Clear()
FCD_0f9e1_lcd_16x2__Clear();
// } else {
}
}
mainendloop: goto mainendloop;
}
/========================================================================
Use :Interrupt
*========================================================================*/