upc eetac_1

Project P9: Introducing the microcontroller

Commercial devices, IDE, program flow in C and basic I/O

4-bit BCD adder

1. Specifications

- Introducing the microcontroller/microcomputer as the main building block of a modern digital system: architecture(CPU + program and data memories + I/O peripherals), assembler code instructions and program execution. The teaching method will be as usual in CSD, the project-based learning (PBL) designing practical examples.

- Commercial devices: Microchip PIC16F/PIC18F and Atmel AVR ATmega architectures, the integrated development environment (IDE), C language compiler, microcontroller simulation (Proteus - VSM) and training/ and prototyping boards (PICDEM2 plus, AVR mega 16/32 starter development board, Arduino, etc.).


Fig 1. Families of Microchip and Atmel (now a Microchip division) microcontrollers.

- Preferred devices and IDE tools (depending on the semester):

Atmel Studio (recommended v. 6.2 SP2)


- Coding the applications in C in our own CSD style. Some initial notes. This is the design flow (Visio).

- Digital inputs and outputs ports. As an example, let's implement a combinational circuit like a 1-digit BCD adder type MC14560 which could have been studied in P3.


Fig 2. The symbol of the 1-digit BCD adder indicating where to connect the input and output ports.

Fig 3. The classic chip MC14560 that we try to recreate as a way to learn on digital inputs and outputs and code organisation in a microcontroller.

Learning materials and tutorials:

- Dual_MUX4 tutorial (PIC16F877A / PIC18F4520 / Atmel ATmega8535).

- This is a Microchip brochure that shows the many tools involved in developing microcontroller designs.


2. Planning

1) Project locations and file names. Place the project folder in your cooperative group shared cloud system (Onedrive, Google drive, Dropbox, etc.) that have a local synchronised copy:


2) Organise the hardware. Draw your circuit in a sheet of paper and discuss where to connect: Reset (CD), CLK oscillator and digital I/O.

3) Organise the C code using a program flowchart: Init_system(), read_inputs(), algorithm, truth table or data processing, write_outputs(). Hardware-dependent functions (input, output and set-up) and software (or platform independent) functions (the truth table). Define the internal variables that will allow the processing of the truth table without regarding the way the PORT pins have been read or write.


Fig. 4.  Convenient variables that will allow the processing of information independently of the microcontroller hardware. 

Bitwise operations. This is example of how you can organise the reading of a variable. And these (1) - (2)  are examples on how to write a given variable using bitwise C instructions. 


4) Plan a sequence for building and debugging the application: the idea is "plan & develop & test" step by step introducing a few lines of code at a time. For instance, 1) solve the code for reading the Cin, run and test the Value_Cin variable using the "watch" window; 2) add the code for reading the operant A, run and test it, etc.

3. Development

1) Draw the schematic of the application in Proteus copying an example or tutorial which already contains the microcontroller that you have to use. Here you are an Atmega8535 version in which you can replace the Atmel chip by the PIC16F877A (or the PIC18F8520) and rewire the pins.


Fig. 5. The BCD_adder as captured in Proteus (PIC16F877A).


2) Run the microcontroller's IDE to develop and compile the C code copying and adapting an: (1) example PIC16F877A; (2) example ATmega8535; (3) example PIC18F4520. Do it section by section according to your plan, testing if it works before adding new code. For example complete the operations for watching the Value_Cin variable; then repeat it all for watching the variable Value_A, and so on. Use tutorial examples to copy and adapt the C source file. Keep the general program organisation emptying the functions, so that you can add code step by step while checking it by simulations.


4. Testing 

) Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points..



Fig. 6.  The circuit in "run" mode while monitoring the variables in the "watch" window.


5. Report

Project report starting with the template sheets of paper, scanned figures, file listings, docx , pptx, or any other resources.  

Remember that in class you'll be required to explain any section of your project individually or in group.


6. Prototyping

You're invited to download the application to a given training board an verify that it works as expected and the same as in the simulator.


Other similar projects on sequential circuits

Books, web pages, etc.

By the way, the Arduino platform is another microcontroller which has become famous, so that you can program it using "*.ino" source files and its development environment, or instead using "*.c" files and Atmel Studio IDE. Remember that here at the EETAC we have the license to simulate Arduino boards and applications in Proteus. Hence, you are invited to try your own projects.


Other materials of interest

Indeed, there are thousands of resources in books and through the internet to learn the basics on microcontrollers (microprocessor, program memory, RAM memory, I/O, peripherals, etc.). For instance (1), from where this image in Fig. 7 is taken:


Fig. 7.  The idea of a microcontroller (or microcomputer) integrating many dedicated peripherals, memory and a microprocessors in a single chip.