The block diagram below shows pin 1 of the 16F88 - it's useful to see how the hardware is connected so you can set up the pin correctly for voltage reference output.
It shows that the voltage reference is directly connected to the pin so all you need to do to output a voltage is to set the TRISA bit (to 1) - to make the P & N fets go into high impedance i.e. drawing no current - and set CVROE (1) obviously CVREN has to be 1 to enable the voltage reference. As well as this set ANSEL (1) (see below).
Note: The TRIS control circuit not shown on this diagram.
The RA2 pin is the only pin that is analogue I/O (because of the voltage
reference output) all other analogue pins are analogue input only.
This register (ANSEL) defaults to all ones so they are all analogue I/(O) at power up but it's best to control the values so you know what they should be.
Vsupply = 4.93V
(i) CVRR = 1 (Low range)
Outputs 16 voltage steps from 0.01V to 3.05V
(ii) CVRR = 0 (high range)
Outputs 16 voltage steps from 1.22V to 3.53V
Low volt range
High volt range
So for the second range (higher voltage output range) you can have finer step sizes and a slightly higher maximum voltage output (but the minimum is not zero).
CVRSRC = 4.93V
|Measured (i)||0.01V to||3.05V|
|For (i) Range is||0V to||4.93*0.625 =||3.08V|
|Measured (ii)||1.22V to||3.53V|
|For (ii) Range is||0.25*4.93 =||1.23V to||4.93*0.72 =||3.55V|
This shows the practical measurements match the datasheet predictions very well.
Running at 8MHz with the following code produces a pulse width for an output
step of 11us (90kHz) - obviously this will change depending on the code used
but you could probably create a simple signal generator.
Note: You can increase the output speed by using a 20MHz crystal - for the current project it is using the internal oscillator at 8MHz so there's room for improvement.
How to use the BMP280 for weather pressure measurement or altitude change detection.
Easily use the SSD1306 in any of your projects.
How to easily make a logic level converter e.g. between 3V and 5V.