Amazing resource for learning C++

C++ is very powerful language and learning it can be a bit daunting for some. I’ve found a beautiful course in MIT OCW.

The link to the course is as follows: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-096-introduction-to-c-january-iap-2011/lecture-notes/

It doesn’t matter if you are learning from scratch or want a quick refresh on your concepts, this is the course for you.

The examples taken in the slides are to the point and relevant in real life coding. Concepts like constructors, destructors and even the tricky ones like pointers, memory management and templates to name a few are beautifully explained.

If you don’t have a compiler and IDE installed then the CodeBlocks IDE is a great bundle. Here is a link to the windows bundle : http://www.codeblocks.org/downloads/26

If you are a beginner then codeblocks-17.12mingw-setup.exe is the file you should download (this advice is given on codeblocks site).

Hope this helped!

SIM 300/900 (GSM Module)

INTRODUCTION

SIM 300 is a GSM modem with a simple serial interface. SIM 300 modem can accept any GSM network operator SIM card and act just like a mobile phone with its own unique phone number. With this module one can send/receive sms, connect to internet via GPRS and receive calls. The modem can either be connected to PC serial port directly or to any microcontroller. When purchasing purchase the entire board. As it comes with RS232 to TTL converter and ethernet port. Also do check the module by calling a few times when in the shop.

You can purchase this module online. Some of the sites are listed below:

  1. http://www.nskelectronics.com/sim300_modem_with_rs232.html
  2. http://robokart.com/wireless-modules/gsm-gprs/sim-900a-gsm-gprs-modem.html

SIM300_INTERFACE_MODULE_RS232_TTL-500x500

Fig.1 SIM300 Module

There are two LEDs on the board. One is power LED and the other is the network LED. When you insert your SIM card into the slot and power ON the device the power LED will be turned ON. After few seconds the network LED will start blinking after an interval of 3 seconds. If this happens it means signal is proper but if it is blinking faster it means that there is no network. If your mobile phone has network then this module should have network at the same location(provided the antenna is connected.) Make a call and it should ring. Do it a couple of times before purchasing from a store.

AT commands

These are the Haye’s command set also called AT commands. AT stands for attention. These commands are used to control the modem. Using these commands the modem can be operated. There are different commands for sending/reading sms etc. For further information about the history you can read the Wikipedia article.

The AT command set can be downloaded here.

at_commands

Above table lists few of the commands. The most basic command is AT and the response is OK. If you get OK then it means that everything is working fine.

exteneded_at

Now to test out the commands or for direct interfacing with the PC or laptop you can use USB to RS232 adapter.

USBRS232Cable_1

Fig. 2 USB to RS232 Adapter

You will need to install prolific drivers. These will be included in a small CD that accompanies the adapter or you can download here.

Once you do that there will be a COM port available now. Some of the basic commands are explained in the following video.

Bit set, reset, toggle and masking in Microcontrollers

Well I would like your concepts on bit set and reset operations to be clear. No matter which language you use be it assembly or embedded c, you will always require to set and reset register bits.

Now whether you want to initialize some peripheral or poll something you will require these three operations.

Bit set operation

This means making a particular bit in an register as 1 or setting it. Now let us see this property of logical OR.

x OR 1 = 1

So whatever be the value of x if you OR it with 1 the result will be 1. This is what we want right? I’ll be taking one example after explaining bit reset.

Bit reset operation

This means that you want to make a particular bit of a register 0 or reset it. We make use of the property of logical AND:

x AND 0 = 0

So whatever be the value of x if you AND it with 0 the result is 0. This is what we wanted so bit reset is done by logical AND operation.

Masking

Often you are interested only in a particular bits of a register. This may be the input of some sensor or something else. Now you want to use masking in this scenario. So masking means you reset all the bits that are not required and let the bits under consideration as it is. Again we make use of logical AND properties.

x AND 0 = 0

x AND 1 = x

So you make the masking pattern by making the bits you want as 1 and the ones you don’t want  as 0. Convert this value to hex and logical AND that mask value with the register.

Bit toggle

Bit toggle is also useful. So for this we make use of the property of ex-or as follows.

x ex-or 1 = complement of x or x-bar

Thus if you ex-or the bit with 1 the bit will be toggled.

Example

130620141602

R &= 0x2081 // This is the masking operation in embedded c

R |= 0x2081 // This will set the bits 0,7,13

R ^= 0x2081 // This will toggle bits 0,7,13

So as you can see this example covers masking. Similarly you need to make the bit patterns for bit set, reset and toggle operation.

If you want more examples comment here. Please like the posts if you like what I have written. And do subscribe to get notifications of my new posts.