L9.3: basic I/O. Poll/read input values [P9] read_inputs() |
[29/11] |
3.4.2.2.3. read_inputs()
Our goal: How to poll/capture/read input port pins? How to convert electrical signals (digital voltages) into RAM variables?
Fig. 1. Example on how to read inputs. |
Mask, clean, shift and organise bits in convenient RAM variables. Bitwise logic operations (AND, OR, XOR, NOT, SHIFT). This is an example on how to read (or poll/acquire/capture) a signal connected to a μC pin and convert it into a convenient RAM variable. The concept of sampling an input at a given CLK active edge is a more complex concept to be explained in P10 on interrupts.
Fig. 2. Sequence of bitwise operations using a flowchart with rectangle symbols, (pdf), memory position diagrams representing how the bits of interest are processed and its ranslation to C code. |
Study how read is organised in Adder_BCD_1digit.
3.4.3. Development & testing
Our target μC device: chip PIC18F4520 from Microchip.
3.4.3.1. Hardware schematic capture: pdsprj file.
The simulation and testing tool to install in your computer using our cloud license: Virtual laboratory Proteus VSM.
3.4.3.2. Software development in C language
The IDE (integrated software develpment environment) to install in your computer: MPLABX with its C compiler XC8.
3.4.3.3. Project compilation and chip configuration files: hex, cof
Compiler options: C90, COFF output file generation.
3.4.3.4. Proteus simulation and testing. Step by step debugging, watch variables window
Run/stop, watch window, RAM variables, ROM (program memory), MCU registers and flags, step by step mode, break points, etc.
Measurements: main loop execution time. How fast is our circuit solving a truth table? How long does it take to execute an instruction in C or in assembly? Execution time of a section of code. Disassembly mode. µC OSC frequency.
Exercise: Input pin connections: Data(3..2) ---> RC(4..5); Data(1..0) ---> RB(7..6). Explain the bitwise operations and draw the flowchart for reading the variable var_Data.
|
Questionnaire on P5- P6 - P7 -P8 (30 min.)