 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:333
|
|
04-05-2016, 10:05 AM
المشاركة 6
|
|
التدريب السادس :
تطوير للبرنامج الأول مع إزالة حرف "C" واستخدام خانة الآحاد لبيان كسر الآحاد مع عرض النقطة العشرية على وحدة السفن سيجمنت :
الدائرة الكهربية :

البرنامج :
كود:
/*
* Project name: Multiplexing_7-Segment 4 UNITS
MCU: PIC16F877A , ADC , LM35 MOD
Oscillator: HS, 8.0000 MHz
SW: mikroC PRO
*/
#define Digit1 PORTD.B0 // DIGIT 1 FROM LEFT , THOUTHAND
#define Digit2 PORTD.B1 // DIGIT 2 FROM LEFT , HUNDRED
#define Digit3 PORTD.B2 // DIGIT 3 FROM LEFT , TENS
#define Digit4 PORTD.B3 // DIGIT 4 FROM LEFT , 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 ;
float result; //
unsigned int result1;
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 ,0 to 1023
result = result * (5000.0/1023.0); // input analog voltage
result = result /10.0 ; // input temp in C for LM35 0.0 to 150.0
///////////
result = result *10.0 ; // float 0.0 to 1500.0
result1=result; //integer 0 to 1500 to get fraction
/////////////
DD1 = result1 / 1000; //Extract DD1 from result >>THOUTHAND(hundred)
PORTB = Display(DD1); //Display the DD1
Digit1 = 1; //Enable digit 1
Delay_Ms(10); //a short 10ms delay
Digit1 = 0; //Disable digit 1
/////////
DD2 = (result1/100) % 10; // DD2 digit >>>HUNDRED (tens)
PORTB = Display(DD2); //Display the DD3
Digit2 = 1; //Enable digit 2
Delay_Ms(10); //a short 10ms delay
Digit2 = 0; //Disable digit 2
////////////
DD3 = (result1/10) % 10; //Extract DD3 from result >>TENS (ones)
PORTB = Display(DD3); //Display the DD3
Digit3 = 1; //Enable digit 3
Delay_Ms(10); //a short 10ms delay
Digit3 = 0; //Disable digit 3
/////////
DD4 = result1 % 10; //Extract DD4 from result >>ONES(fraction)
//PORTB = 0x39; //Display C CHARACTER
PORTB = Display(DD4);
Digit4 = 1; //Enable digit 4
Delay_Ms(10); //a short 10ms delay
Digit4 = 0; //Disable digit 4
}
}
|