Close

Addressing the challenge of beginner C language coding

A project log for CHRP4 USB robotics development board

A simple, inexpensive development board for learning or teaching beginner microcontroller programming and robotics.

john-rampeltJohn Rampelt 04/25/2023 at 18:360 Comments

The C language is great for beginner computer technology learners to build a better understanding of microcontroller programming and interfacing due to its close connections to the underlying hardware. Unfortunately, the C program syntax and its required supporting structure and functions can also be overwhelming for new learners, and this is why many recent beginner microcontroller boards have made the move to higher-level programming languages like Python, or use block coding.

But, these initially easier solutions come at the expense of the user having full control over the system, and make it more difficult for learners to able to build a full understanding of how the software and hardware work together. This is especially important in a multi-year or multi-semester course that leads from introductory programming and interfacing to students eventually designing, building, testing, and programming their own microcontroller circuits.

I have used a variety of techniques over the years to make it easier for beginners to build their programming skills in C, and these students then find it much easier to move to other programming languages and environments later due to their comprehensive understanding of the structure of typical C programs. Below are some tips that I have had great success with in my classroom.

Treat C expressions as sentences and paragraphs

Simplify the program code to expose only the main( ) function first

Promote guided exploration and real-world/fun activities

Slowly fold in advanced concepts

Provide code templates for end-of-course challenge projects

// SUMO robot code template
#include    "xc.h"              // Microchip XC8 compiler include file
#include    "stdint.h"          // Include integer definitions
#include    "stdbool.h"         // Include Boolean (true/false) definitions
#include    "CHRP4.h"           // Include CHRP4 constants and functions

// Program constant definitions
#define search  0               // Search mode
#define push    1               // Push mode

// Program variable definitions
unsigned char mode = search;    // Start in search mode

// Motor function (create a motor function here)

// SONAR function (create a SONAR function here)

int main(void)                  // Run this code on every startup
{
    OSC_config();               // Set oscillator for 48 MHz operation
    CHRP4_config();             // Set up I/O ports for on-board CHRP4 devices
    
    // Create the code to search for your opponent
    while(mode == search)
    {
        
    }
    
    // Create the code to push your opponent out of the ring
    while(mode == push)
    {
        
    }
}

A methodical curriculum combined with a simple robot built using an inexpensive circuit and parts (such as CHRP4 with its simple robot platform) will go a long way to providing new learners with a comprehensive understanding of microcontroller programming and interfacing concepts, and will make it easy for them to progress further using other microcontrollers and programming languages later in their computing careers.

Discussions