khatus
Member level 3
Hello, Guys, I wanted to show adc value in 7 segments dynamic display. I am using ADC channel 1 for this purpose. But while simulating in the proteus it shows the following error.Also, some random digits show in the display. I can't figure out the error. Please update my code if possible .........
moderator action: removed link to external file servers
Here is my full code
moderator action: removed link to external file servers
Here is my full code
Code:
/*
* 7-Segment common anode display for showing ADC value read from channe-1 of analog pin
* Programmer: SRikrishna Jana
* Target PIC: PIC16F877
* Frequency 8 Mhz
* Date: 5th august 2021
* Display on 3-digit 7 SEGMENT display
*/
unsigned char SEGMENT=0;
sbit C1 at RD0_bit; // C1--->C4 are for turnig on the common anode display
sbit C2 at RD1_bit; // If C1=1 display is on if C1=0 display is off
sbit C3 at RD2_bit; //Same rule follows C2,C3,C4
sbit C4 at RD3_bit;
//unsigned int value;
const unsigned char DriveSegment[10] = { 192, 249, 164, 176, 153, 146, 130, 248, 128, 152 }; //Digit code for 0 to 9
void UpdateDisplay(unsigned int value)
{
unsigned int SendVal = value;
unsigned char Digit;
SEGMENT++;
if (SEGMENT > 4)
SEGMENT = 1;
C1 = 0; C2 = 0; C3 = 0,C4 =0; //Initially Displays are off
switch (SEGMENT){
case 1:
Digit = (unsigned char) (SendVal / 1000); // Suppose ADC value= 1023 This gives you 1.
C1=1; //turn on the display
delay_ms(10);
C1=0; //turn off the display
break;
case 2:
Digit = (unsigned char) ((SendVal / 100) % 10);//This gives you 0.
C2=1; //turn on the display
delay_ms(10);
C2=0; //turn off the display
break;
case 3:
Digit = (unsigned char) ((SendVal / 10) % 100);//This gives you 2.
C3=1; //turn on the display
delay_ms(10);
C3=0; //turn off the display
break;
case 4:
Digit = (unsigned char) (SendVal % 10);//This gives you 3.
C4=1; //turn on the display
delay_ms(10);
C4=0;//turn off the display
break;
}
SendVal = DriveSegment[Digit] & 0xFF;
PORTB = SendVal;
}
unsigned int ADC_reading(void )
{
unsigned int value_adc;
ADC_Init();
value_adc = ADC_Read(1);
delay_us(10);
return(value_adc);
}
void main()
{
unsigned int value;// variable for storing adc value
TRISB=0x00;// B0 to B6 declared as a output
PORTB = 0x00;//Initially PORTB is OFF
TRISD=0x00; // D0 to D3 declared as a output
PORTD = 0x00;// Initially PORTD is OFF
TRISA.F1 =1;
ADCON0.F5=0; //*For channel 1
ADCON0.F4=0; //*For channel 1
ADCON0.F3=1; //*For channel 1
while(1)
{
value = ADC_reading(void) ;//call the ADC_reading function for reading analog channel 1
UpdateDisplay(value);// pass the valor to UpdateDisplay function for showing to seven segment display
}
}
Last edited by a moderator: