Let's learn C

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Let's learn C

#1 Post by Thomas.Pahl@t-online.de » 20 Jun 2022 18:49

Hi Basic Fans! Who wants to wait 2 more years for a Basic Compiler? The Necto 2.0 is really a nice peace of software!! It is really intuitive and relative close to Pro Compilers.
I am 67 and time is running. The new license model is reconciling me with ME. You know that life time promise... Now let us learn C. That cannot be that difficult since C is
only a weerd Basic Dialect. :D

One serious issue: the software's function depends on reachable ME servers....

Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Re: Let's learn (Mikro)BASIC

#2 Post by Alessandro Fulignani » 21 Jun 2022 10:48

Dear Thomas,

Basic it's much more readable then C. Compactness of C was born for the the VT100 terminal with green phosphor monitors.
C is loosing fans by several years and the prove it is that Payton it is the most used and recommended language which is a strong step toward Basic. (See the Tiobe index)
In my companies we are using MIkroBasic to make all the technicians capable to write firmware, and it has been a strong success!
Right now even the C writers are getting in love with MikroBasic because they can discuss with the Hardware engineers just reading the FW.
Final, we have analyzed the assembler output from MikroC and MikroBasic and they are almost identical.

Have a look to this simple CRC routines written in MikroBasic and in C:

Sub function Vector_CRC_Calc (Dim Vector_lenght As Byte, Dim Byref CRC_Vector as byte[255] ) as byte

Dim CRC_Result,Bit_,Dato as byte

SUMCHK = 0xffff

For Dato = 0 to Vector_lenght

SUMCHK = SUMCHK xor CRC_Vector[Dato]

For Bit_ = 0 to 7

If SUMCHK.b0 = 1

Then SUMCHK = SUMCHK >> 1
SUMCHK = SUMCHK xor 0xA001

Else SUMCHK = SUMCHK >> 1

End If

Next Bit_

Next Dato


------------------------------------------------------------------------------------------------------


// Compute the MODBUS RTU CRC
UInt16 ModRTU_CRC(byte[] buf, int len)
{
UInt16 crc = 0xFFFF;

for (int pos = 0; pos < len; pos++) {
crc ^= (UInt16)buf[pos]; // XOR byte into least sig. byte of crc

for (int i = 8; i != 0; i--) { // Loop over each bit
if ((crc & 0x0001) != 0) { // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
}
else // Else LSB is not set
crc >>= 1; // Just shift right
}
}
// Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)
return crc;
}


The two routines gives exactly the same results, but the first one can be read by anybody, the second only by a SW engineer.

Don't forget that the goal it is NOT write software, but have the desired functionalities!

Of course we use MikroBasic only as Functions and Procedures, so you must avoid te use of Goto or Gosub or out of order instructions.

Have a nice day,

Alex
Attachments
Screenshot 2022-06-21 113124.png
Screenshot 2022-06-21 113124.png (38.98 KiB) Viewed 1247 times

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: Let's learn C!

#3 Post by Thomas.Pahl@t-online.de » 25 Jun 2022 15:06

It is not a question of beauty - the winner is ... Basic! :D

The Basic compilers get outdated soon. If you use well established processors that exist for many years - no problems.

But there are a lot of new chips that are not supported. I do not want to wait til 2024 or later. I will have learnt C much sooner. I hope.

Greetings.

sgssn
Posts: 34
Joined: 13 Sep 2021 16:24

Re: Let's learn C

#4 Post by sgssn » 26 Jun 2022 13:52

Hi all
'C' is a very good programming language for uC. 'C' was designed for PC-programming. Today i would not use C for making a program for a PC. I would use C#. One of the reason is because its a horror programming in Visual C by Microsoft. But to create a program i always would use 'C', because it is near to hardware. Espacially when you have poor RAM space. And when you write a program for a Mikrocontroller, and you can use a language for free i would use it. I dont work with MIKROE, i use MPLAB X and XC8, that supprts also programer and debugging. I think that is comparable to what MIKROE offers. As far as i know there is no Phyton support for uC from MIKROE. And 'C' is easy to learn.

regards
Gerhard

yellowdog
Posts: 5
Joined: 20 Oct 2023 05:22

Re: Let's learn C

#5 Post by yellowdog » 22 Oct 2023 09:13

'And 'C' is easy to learn...'

This is not true, C is hard to learn because its syntax is unreadable :-(

Post Reply

Return to “mikroBasic PRO for ARM General”