In previous example, I use the SPI module of the dsPIC30F2010 to control a serial LED display and seven-segment display. Now let put them together making a serial display digital volt-meter.
There is one on-board POT so I use it to adjust input voltage that varies between 0 and +5VDC. It will show the reading voltage on a serial seven-segment display.
Schematic:
![]() |
| Schematic Diagram |
This is just schematic using device symbols. I can not be simulated like other build-in models. I download the dsPIC30F2010 symbol from SnapEDA for free.
MikroC Source Code:
- // Chip Select Pin
- sbit Chip_Select at LATE3_bit;
- sbit Chip_Select_Direction at TRISE3_bit;
- void SN74595_Send(char _data){
- SPI_Write(_data); // Send high byte via SPI
- Chip_Select = 0; // Select SPI chip
- Chip_Select = 1; // Deselect SPI chip
- }
- // Common Cathod Segment Data
- const char cc[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
- 0x7F,0x6F,0x77,0x7C,0x58,0x5E,0x79,0x71};
- void show_number(char number){
- SN74595_Send(~cc[number]);
- }
- void main() {
- unsigned int temp_res;
- float voltage=0;
- char digit=0;
- Chip_Select = 1; // Deselect DAC
- Chip_Select_Direction = 0; // Set CS# pin as Output
- SPI1_Init(); // Initialize SPI module
- TRISB = 0xFFFF; // PORTB is input
- TRISD = 0; // PORTD is output
- TRISF = 0; // PORTF is output
- ADC1_Init(); // Enable ADC module
- while(1){
- temp_res = ADC1_Read(4); // Get 10-bit results of AD conversion
- voltage = (5.0 * temp_res)/1023;
- digit = (char)voltage;
- show_number(digit);
- Delay_ms(500);
- }
- }
Using a 0.5 second delay time making the display run very smooth without glitching. It could saves the power consumption since the ADC reading is not so frequently. For more information about using the ADC please read this post.

Zero Volt ADC Reading 
3 Volt ADC Reading 
5 Volt ADC Reading
I test example using my DIY dsPIC30F1010 Prototype Board. For more information about this PCB see this post.


No comments:
Post a Comment