Dear,
we used to program microchip in C language.
we like to consider moving to flowcode.
before we buy, we downloaded the free version and it's looking good.
we do like to try one time to convert the C code to Flowcode but we can't do it on the free version.
can someone please convert this code for us so we can see how this function work and send to us?
our email is - info@Tomer-systems.com
the code is here below
'***********************************************************************
'* Name : XBee.BAS *
'* Author : Hadar Magali *
'* Date : 20-Aug-10 *
'* Version : 1.1 *
'* Notes : Concrete pump pulse counter, for De-Waalusing XBee *
'* Used Adrresses: * *
'* : *
'* Notice : Copyright (c) 2010 *
'***********************************************************************
'The metal detector is connected to RA4 (pin 6).
'
'The "Reverse" signal connevted to RA5 (pin 7).
'The "Reverse" signal is pulled down. It reverses counting while being high.
'
'Ther system sends the maximum reading (Max_Counting).
'
'The start counting is 100.
'
'Each 1.4 second, the RS232 transmits the Pulse_counter register(16 Bit).
'
'Baud rate of 9,469 (9,600), with 5,000,000 Hz cristal.
'
'The Pulse_Counter register low Byte is mirored to PIC PORTD.
'
'The massage is "(TT,TH,HU,TE,UN)" (without the ",")
'Where:
' "(" = (40 ASCII). Massage start
' "TT" = Tens of Thousents
' "TH" = THousents
' "HU" = HUndredss
' "TE" = TEns
' "UN" = UNits
' ")" = (41 ASCII).End of massage.
Pause 1000 'wait 1 seconds for XBee init
'Variables decleration
Pulse_counter var WORD
Max_Counting VAR WORD
Remaider VAR WORD
Tens_Thousents VAR Word
Tousents VAR Word
Hundreds VAR Word
Tens VAR BYTE
Singles VAR BYTE
Previos_state VAR BIT
Excisting_state VAR BIT
'Initiation (Enter)
trisa = 255 'pic port A input
trisc = 0 'pic port C output
trisd = 0 'pic port D output
ADCON1 = 6 'All pins are digital (no a/d).
spbrg = 32 'baud rate 9600 (32+1, high speed, 5,000,000 Hz => 9,469)
rcsta = 128 'set pin RC6/RX/CLK to RS232 Transmit
txsta = 36 'transmit enable, high speed
Pulse_counter = 100 'initiating counter to "zero" - 100
Max_Counting = 100 'Initiating Max-Counter to "zero" - 100
if (PORTA & 16) > 0 THEN
Excisting_state = 1
Else
Excisting_state = 0
ENDIF
Previos_state = Excisting_state
'Real program
Start_Over:
if (PORTA & 16) > 0 THEN
Excisting_state = 1
Else
Excisting_state = 0
ENDIF
IF Previos_state = Excisting_state Then Transmit ' If no pump pulse - transmit the
'Pulse_counter register as is
IF (PORTA & 32) > 0 THEN
Pulse_counter = Pulse_counter - 1 'If pump switch is in "Reverse" position, decrement
'Pulse_counter register by 1
ELSE
Pulse_counter = Pulse_counter + 1 'If pump switch is in "Normal" position, increment
'Pulse_counter register by 1
ENDIF
IF Pulse_counter > Max_Counting THEN
Max_Counting = Pulse_counter
ENDIF
Previos_state = Excisting_state
PORTD = Max_Counting // 256 'miroring Pulse_Counter low byte to PORTD
Transmit:
If (TXSTA & 2) = 0 THEN Transmit 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = 40 'Transmit delimiter caracter "(" = 28H = 40
Tens_Thousents = Max_Counting / 10000
Remaider = Max_Counting // 10000
Wait_1:
If (TXSTA & 2) = 0 THEN Wait_1 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = Tens_Thousents + 48 'Transmit Tens-Thousents digit of Pulse_counte in ASCII
Tousents = Remaider / 1000
Remaider = Remaider // 1000
Wait_2:
If (TXSTA & 2) = 0 THEN Wait_2 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = Tousents + 48 'Transmit Thousents digit of Pulse_counte in ASCII
Hundreds = Remaider / 100
Remaider = Remaider // 100
Wait_3:
If (TXSTA & 2) = 0 THEN Wait_3 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = Hundreds + 48 'Transmit hunderd digit of Pulse_counte in ASCII
Tens = Remaider / 10
Singles = Remaider // 10
Wait_4:
If (TXSTA & 2) = 0 THEN Wait_4 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = Tens + 48 'Transmit Tens digit of Pulse_counte in ASCII
Wait_5
If (TXSTA & 2) = 0 THEN Wait_5 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = Singles + 48 'Transmit Singles digit of Pulse_counte in ASCII
Wait_6:
If (TXSTA & 2) = 0 THEN Wait_6 'wait for UART
txsta = 4 'High speed
rcsta = 128 'serial port enable
txsta = 36 'transmit, high speed
txreg = 41 'end of massage "(" = 29H = 41
Pause 1400 'Wait 1.4 seconds - sends two massages per second.
goto Start_Over 'start a new rs232 massage.
thanks.
convert C code to Flowcode
-
HadarMagali
- Posts: 2
- http://meble-kuchenne.info.pl
- Joined: Wed May 27, 2026 3:42 pm
-
mnfisher
- Valued Contributor
- Posts: 2046
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 161 times
- Been thanked: 950 times
Re: convert C code to Flowcode
The code you present here isn't C - the convert function won't work.... we do like to try one time to convert the C code to Flowcode but we can't do it on the free version.
As a description of what you are trying to do - it looks straightforward to convert to flowcode - what have you attempted so far?
Martin
-
HadarMagali
- Posts: 2
- Joined: Wed May 27, 2026 3:42 pm
Re: convert C code to Flowcode
Hi Martin,
i think this is the c code, can you please convert it and send it to us info@tomer-systems.com
thanks.
/***********************************************************************
* Name : XBee.c
* Author : Hadar Magali (Translated to C)
* Date : 2026 Conversion
* Version : 1.1_C
* Notes : Concrete pump pulse counter, for De-Waalusing XBee
***********************************************************************/
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
// Define crystal frequency for delay macros (5,000,000 Hz)
#define _XTAL_FREQ 5000000
// Function prototype
void transmit_char(char c);
void main(void) {
// Wait 1 second for XBee initialization
__delay_ms(1000);
// Variables declaration
uint16_t pulse_counter = 100; // Initiating counter to "zero" - 100
uint16_t max_counting = 100; // Initiating Max-Counter to "zero" - 100
uint16_t remainder = 0;
uint16_t tens_thousands = 0;
uint16_t thousands = 0;
uint16_t hundreds = 0;
uint8_t tens = 0;
uint8_t singles = 0;
bool previous_state = false;
bool existing_state = false;
// Initialization (Hardware Configuration)
TRISA = 255; // PIC port A input
TRISC = 0; // PIC port C output
TRISD = 0; // PIC port D output
// Disable analog inputs (Set to digital)
// Note: On newer PICs, use ANSEL/ANSELH registers. For legacy PICs, ADCON1 = 6.
ADCON1 = 6;
// USART configuration for 9600 Baud at 5MHz (As per original registers)
SPBRG = 32;
RCSTA = 128; // Serial port enabled (SPEN = 1)
TXSTA = 36; // Transmit enabled (TXEN = 1), High speed (BRGH = 1)
// Initial check of RA4 (pin 6)
if ((PORTA & 16) > 0) {
existing_state = true;
} else {
existing_state = false;
}
previous_state = existing_state;
// Main Loop
while (1) {
// Read existing state from RA4
if ((PORTA & 16) > 0) {
existing_state = true;
} else {
existing_state = false;
}
// If edge changed, calculate pulse. If not, jump straight to transmit.
if (previous_state != existing_state) {
// Check RA5 (pin 7) for Reverse direction
if ((PORTA & 32) > 0) {
pulse_counter = pulse_counter - 1; // Reverse: Decrement
} else {
pulse_counter = pulse_counter + 1; // Normal: Increment
}
// Update peak reading
if (pulse_counter > max_counting) {
max_counting = pulse_counter;
}
previous_state = existing_state;
// Mirror Pulse_Counter low byte to PORTD (Using max_counting as per code)
PORTD = max_counting % 256;
}
// --- Transmit Data Packet ---
// Transmit delimiter character "("
transmit_char(40);
// Calculate digits
tens_thousands = max_counting / 10000;
remainder = max_counting % 10000;
transmit_char(tens_thousands + 48);
thousands = remainder / 1000;
remainder = remainder % 1000;
transmit_char(thousands + 48);
hundreds = remainder / 100;
remainder = remainder % 100;
transmit_char(hundreds + 48);
tens = remainder / 10;
singles = remainder % 10;
transmit_char(tens + 48);
transmit_char(singles + 48);
// Transmit delimiter character ")"
transmit_char(41);
// Wait 1.4 seconds before sending the next message
__delay_ms(1400);
}
}
/**
* Handles UART transmission and safely waits for the buffer to clear
*/
void transmit_char(char c) {
// Wait until TXSTA bit 1 (TRMT - Transmit Shift Register Empty) is 1
while (TXSTAbits.TRMT == 0);
// Re-apply original register overrides from your code structure
TXSTA = 4; // High speed flag
RCSTA = 128; // Serial port enable
TXSTA = 36; // Transmit, high speed
TXREG = c; // Load data into transmission register
}
i think this is the c code, can you please convert it and send it to us info@tomer-systems.com
thanks.
/***********************************************************************
* Name : XBee.c
* Author : Hadar Magali (Translated to C)
* Date : 2026 Conversion
* Version : 1.1_C
* Notes : Concrete pump pulse counter, for De-Waalusing XBee
***********************************************************************/
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
// Define crystal frequency for delay macros (5,000,000 Hz)
#define _XTAL_FREQ 5000000
// Function prototype
void transmit_char(char c);
void main(void) {
// Wait 1 second for XBee initialization
__delay_ms(1000);
// Variables declaration
uint16_t pulse_counter = 100; // Initiating counter to "zero" - 100
uint16_t max_counting = 100; // Initiating Max-Counter to "zero" - 100
uint16_t remainder = 0;
uint16_t tens_thousands = 0;
uint16_t thousands = 0;
uint16_t hundreds = 0;
uint8_t tens = 0;
uint8_t singles = 0;
bool previous_state = false;
bool existing_state = false;
// Initialization (Hardware Configuration)
TRISA = 255; // PIC port A input
TRISC = 0; // PIC port C output
TRISD = 0; // PIC port D output
// Disable analog inputs (Set to digital)
// Note: On newer PICs, use ANSEL/ANSELH registers. For legacy PICs, ADCON1 = 6.
ADCON1 = 6;
// USART configuration for 9600 Baud at 5MHz (As per original registers)
SPBRG = 32;
RCSTA = 128; // Serial port enabled (SPEN = 1)
TXSTA = 36; // Transmit enabled (TXEN = 1), High speed (BRGH = 1)
// Initial check of RA4 (pin 6)
if ((PORTA & 16) > 0) {
existing_state = true;
} else {
existing_state = false;
}
previous_state = existing_state;
// Main Loop
while (1) {
// Read existing state from RA4
if ((PORTA & 16) > 0) {
existing_state = true;
} else {
existing_state = false;
}
// If edge changed, calculate pulse. If not, jump straight to transmit.
if (previous_state != existing_state) {
// Check RA5 (pin 7) for Reverse direction
if ((PORTA & 32) > 0) {
pulse_counter = pulse_counter - 1; // Reverse: Decrement
} else {
pulse_counter = pulse_counter + 1; // Normal: Increment
}
// Update peak reading
if (pulse_counter > max_counting) {
max_counting = pulse_counter;
}
previous_state = existing_state;
// Mirror Pulse_Counter low byte to PORTD (Using max_counting as per code)
PORTD = max_counting % 256;
}
// --- Transmit Data Packet ---
// Transmit delimiter character "("
transmit_char(40);
// Calculate digits
tens_thousands = max_counting / 10000;
remainder = max_counting % 10000;
transmit_char(tens_thousands + 48);
thousands = remainder / 1000;
remainder = remainder % 1000;
transmit_char(thousands + 48);
hundreds = remainder / 100;
remainder = remainder % 100;
transmit_char(hundreds + 48);
tens = remainder / 10;
singles = remainder % 10;
transmit_char(tens + 48);
transmit_char(singles + 48);
// Transmit delimiter character ")"
transmit_char(41);
// Wait 1.4 seconds before sending the next message
__delay_ms(1400);
}
}
/**
* Handles UART transmission and safely waits for the buffer to clear
*/
void transmit_char(char c) {
// Wait until TXSTA bit 1 (TRMT - Transmit Shift Register Empty) is 1
while (TXSTAbits.TRMT == 0);
// Re-apply original register overrides from your code structure
TXSTA = 4; // High speed flag
RCSTA = 128; // Serial port enable
TXSTA = 36; // Transmit, high speed
TXREG = c; // Load data into transmission register
}
-
mnfisher
- Valued Contributor
- Posts: 2046
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 161 times
- Been thanked: 950 times
Re: convert C code to Flowcode
Something like:
Martin
Martin
- Attachments
-
- concrete.fcfx
- (13.51 KiB) Downloaded 1 time