/************************************************************
To display temperature (0-99) on two common cathode seven segment displays using multiplexing. Pin a,b,c,d,e,f,g and dp of each seven segment display are connected to PORTB pin 0 to pin 7 through
330 Ohm Resistors.
2 pins of PORTC (RC4 & RC5) are connected to the base of two BC548B Transistors respectively through 1K Resistors. Collectors of each Transistor is connected to common pins of each Seven Segment Display. All the emitters are connected to ground.
I use the circuit to display weather temperature which never goes to 3 digits in Celsius scale. That's why I used 2 Seven Segment Displays. You can use the third display as shown in the display connection schematic.
Vref+ is connected to 5V+ supply and Vref- is connected to 0V which gives enough resolution for my need. You can change if you need. Also read Mr. Tahmid 's blogs on ADC. They are really good.
Processor: pic16F876A with 20MHz Xtal Compiler:MPLAB X8 on MPLAB XIDE v1.95
LM35 output pin is connected to AN0 (pin 2 of 16F876A). For display you can get idea from : https://www.edaboard.com/blog371886-attachment66886d1326004489-sch.png
Hera is a picture of the finished model using the above code. Though there are 3 seven segment display modules present on the hardware, the third is not connected. Only 2 are used.
To display temperature (0-99) on two common cathode seven segment displays using multiplexing. Pin a,b,c,d,e,f,g and dp of each seven segment display are connected to PORTB pin 0 to pin 7 through
330 Ohm Resistors.
2 pins of PORTC (RC4 & RC5) are connected to the base of two BC548B Transistors respectively through 1K Resistors. Collectors of each Transistor is connected to common pins of each Seven Segment Display. All the emitters are connected to ground.
I use the circuit to display weather temperature which never goes to 3 digits in Celsius scale. That's why I used 2 Seven Segment Displays. You can use the third display as shown in the display connection schematic.
Vref+ is connected to 5V+ supply and Vref- is connected to 0V which gives enough resolution for my need. You can change if you need. Also read Mr. Tahmid 's blogs on ADC. They are really good.
Processor: pic16F876A with 20MHz Xtal Compiler:MPLAB X8 on MPLAB XIDE v1.95
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 #pragma config FOSC=HS, LVP=OFF, WDTE=OFF #include<stdio.h> #include<pic16f876a.h> #include<xc.h> #define _XTAL_FREQ 20000000 void MSDelay(int itime); void fnd_display(int val,int pos); void read_adc(void); unsigned char lup[10]={0x81,0xF3,0x49,0x61,0x33,0x25,0x05,0xF1,0x01,0x21}; unsigned int result; int digits[2]; float n;int temp,rs; void main() { CMCON=7; //Comperator off TRISB=0; TRISAbits.TRISA0=1; TRISC=0; ADCON0=0b10000000; ADCON1=0b11000000; // select right justify result. A/D port configuration 0 ADCON0bits.ADON=1; // turn on the A2D conversion module MSDelay(30); while(1){ read_adc(); n=result*0.48876; //n+=0.5; temp=n; rs=temp; digits[0]=rs%10; digits[1]=rs/10; fnd_display(digits[1],0); MSDelay(50); fnd_display(digits[0],1); MSDelay(20); } } void read_adc(void) { unsigned short i; unsigned long result_temp=0; for(i=500;i>0;i-=1) //looping 500 times (better 2000 times) for getting average value { ADCON0bits.GO = 1; //ADGO is the bit 2 of the ADCON0 register while(ADCON0bits.GO==1); //ADC start, ADGO=0 after finish ADC progress result=ADRESH; result=result<<8; //shift to left for 8 bit result=result|ADRESL; //10 bit result from ADC result_temp+=result; //MSDelay(1); } result = result_temp/500; //getting average value } void MSDelay(int itime){ int i,j; for(i=0;i<itime;i++) for(j=0;j<135;j++); return; } void fnd_display(int val,int pos){ switch(pos){ case 0: PORTC=0b00010000; break; case 1: PORTC= 0b00100000; break; } PORTB=lup[val]; return ; }
LM35 output pin is connected to AN0 (pin 2 of 16F876A). For display you can get idea from : https://www.edaboard.com/blog371886-attachment66886d1326004489-sch.png
Hera is a picture of the finished model using the above code. Though there are 3 seven segment display modules present on the hardware, the third is not connected. Only 2 are used.