 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,832
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:
|
|
04-05-2016, 12:43 PM
المشاركة 64
|
|
التدريب الرابع :
قياس درجة حرارة باستخدام الحساس LM35 وعرضها على 4 وحدات سفن سيجمنت
الدائرة الكهربية :



البرنامج :
كود:
/*
* Project name: Multiplexing_7-Segment 4 UNITS
MCU: PIC16F877A , ADC , LM35
Oscillator: HS, 8.0000 MHz
SW: mikroC PRO
*/
#define Digit1 PORTD.B0 // THOUTHAND
#define Digit2 PORTD.B1 // HUNDRED
#define Digit3 PORTD.B2 // TENS
#define Digit4 PORTD.B3 // ONES
unsigned char Display (unsigned char digit)
{
unsigned char pattern;
unsigned char SEGMENT_MAP[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
pattern = SEGMENT_MAP[digit] ; //The pattern to return
return (pattern);
}
void main() {
unsigned char DD1,DD2, DD3,DD4 ;
unsigned int result; //
float scale ;
char num ;
ADCON1= 0; //
TRISA.B0=1; // AN0 INPUT
TRISD = 0; // Configure PORTD as outputs , COMMON CATHODES
TRISB = 0; // Configure PORTB as outputs ,7 SEGMENT DATA PORT
Digit1 = 0; //Disable digit 1
Digit2 = 0; //Disable digit 2
Digit3 = 0; //Disable digit 3
Digit4 = 0; //Disable digit 4
while(1){
result=ADC_Read(0); // Read analog value from channel 0
scale = result * (5000.0/1023.0); // input analog voltage
scale = scale /10.0 ; // input temp inc for LM35
num = scale ;
///////////
DD1 = num / 1000; //Extract DD1 from result >>THOUTHAND
PORTB = Display(DD1); //Display the DD1
Digit1 = 1; //Enable digit 1
Delay_Ms(10); //a short 10ms delay
Digit1 = 0; //Disable digit 1
/////////
DD2 = (num/100) % 10; // DD2 digit >>>HUNDRED
PORTB = Display(DD2); //Display the DD3
Digit2 = 1; //Enable digit 2
Delay_Ms(10); //a short 10ms delay
Digit2 = 0; //Disable digit 2
////////////
DD3 = (num/10) % 10; //Extract DD3 from result >>TENS
PORTB = Display(DD3); //Display the DD3
Digit3 = 1; //Enable digit 3
Delay_Ms(10); //a short 10ms delay
Digit3 = 0; //Disable digit 3
/////////
DD4 = num % 10; //Extract DD4 from result >>ONES
PORTB = Display(DD4); //Display the DD4
Digit4 = 1; //Enable digit 4
Delay_Ms(10); //a short 10ms delay
Digit4 = 0; //Disable digit 4
}
}
|