|
|||||
Chapter 3 problems |
- B3.3 - |
5-bit ones counter (μC - C) |
|||
|
1. Specifications
Design the 5-bit ones counter represented in Fig. 1 using plan B and a microcontroller PIC18F4520.
The same project is proposed in D1.3 as a combinational circuit based on logic gates.
|
Fig.1. Ones_counter_5bit symbol. |
Use this project to review basic concepts on μC as theory attached to the specifications section.
2. Planning
Copy and adapt a circuit from any of the previous projects (LAB9) and name it Ones_Counter_5bit.pdsprj. Assign pins to inputs and outputs accordingly to one of the following options (your instructior will tell you which):
Pin assignment option #1:
D4 --> RC7; D3 --> RC4; D2 --> RC3; D1 --> RB6; D0 --> RA1
Y2 --> RA2; Y1 --> RB5; Y0 --> RB0
Pin assignment option #2:
D4 --> RB5; D3 --> RB3; D2 --> RC2; D1 --> RC0; D0 --> RA0
Y2 --> RA3; Y1 --> RC5; Y0 --> RD0
Pin assignment option #3:
D4 --> RD7; D3 --> RD3; D2 --> RB3; D1 --> RA1; D0 --> RB2
Y2 --> RD6; Y1 --> RC5; Y0 --> RB1
Project location:
C:\CSD\P9\Ones_Counter_5bit\(files)
Organise the main program in our CSD way.
Propose a hardware-software diagram naming all the electrical signals, RAM variables and the software functions.
Explain how to configure the µC in init_system(). List all RAM variables required and their type.
Organise using a flowchart the interface function read_inputs().
Organise using a flowchart the interface function write_outputs().
Infer the truth_table() software function using a behavioural interpretation and the corresponding flowchart.
Write the Ones_Counter_5bit.c source code translating the function flowcharts. Start capturing only one input as in (LAB9) and visualising it in the watch window. And only then go step by step developing & testing more inputs.
Start a software IDE project for the target microcontroller PIC18F4520 and generate the configuration files ".cof" and ".hex" after compilation. Discuss the project summary: % of ROM used for the code, number of RAM bytes used, etc.
Add a few lines of code every time, compile and run the test intereactively to check results watching variables.
Note: Step-by-step tactical approach for developing and testing the project: Read one input at a time and run to check that the voltage value is correctly captured as a valid digital value in RAM memory. Write one output at a time and run to check that your code is correct to light the LED connected at the output pin. |
Measure how long does it take to run the main loop code when using a 4 MHz and a 20 MHz crystall oscillators.