 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:333
|
|
11-04-2016, 10:40 AM
المشاركة 4
|
|
برنامج قياس جهد وتردد التيار المتردد بلغة السى مع المترجم ميكروسى :
كود:
/**************************************
Program for AC parameters measurements
2-ac voltage and frequency measurements
MCU: PIC16F877A X-Tal: 8MHz
Date : 10/4/2016
****************************************/
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
char peak_text[] = "PK:000V";
char rms_text[] = "RMS:000V";
char frequency_text[] = "FREQUENCY:00Hz";
/////////////////////
void init(){
TRISA = 0xFF; // set all pins of PORT A as input
ADCON1=0x00; // set all Analog
OPTION_REG = 0b00101000; // set TOCKI as clock counter , PS2:PS0: Prescaler Rate 1:2
/////////////////////////
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
/////////////////////
Lcd_Out(1,1,"Measurement of");
Lcd_Out(2,1,"AC parameter ");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
}
//////
void voltage(){
unsigned int i,peak,rms,temp;
float max1 ;
// Find the peak amplitude of the sine wave...
max1 = 0;
for(i=0;i<5000;i++)
{
temp = ADC_Read(0);
if(temp>max1)
{
max1 = temp;
}
Delay_us(5);
}
max1 = max1*(5.0/1023.0) ;//Input voltage to PIC AN pin
max1 = max1*11.0 ;//Input voltage to voltage divider circuit
max1 = max1+1.4; // voltage drop on bridge
max1 = max1* 220.0/12.0;//Input voltage to voltage transformer
peak = max1; //peak as integer value
rms = peak*0.707; // find the rms value of the line voltage
peak_text[3] = peak/100 + 48; // convert into ASCII
peak_text[4] = (peak/10)%10 +48; // convert into ASCII
peak_text[5] = (peak)%10 +48; // convert into ASCII
Lcd_Out(1,1,peak_text); // Display message on LCD
rms_text[4] = rms/100 + 48; // convert into ASCII
rms_text[5] = (rms/10)%10 +48; // convert into ASCII
rms_text[6] = (rms)%10 +48; // convert into ASCII
Lcd_Out(1,9,rms_text); // Display message on LCD
}
//////////
void frequency(){
unsigned int Hz;
TMR0=0; // clear TMR0
Delay_ms(1000); // Delay 1 Sec to measure Hz
/////
Hz=TMR0/2;// divide by 2 , full wave double the frequency
frequency_text[10] = (Hz/10) + 48; // Extract tens digit as ASCII
frequency_text[11] = (Hz/1)%10 + 48; // Extract ones digit as ASCII
Lcd_Out(2,1,frequency_text); // Display message on LCD
TMR0=0;
}
///////////////////////////
void main()
{
init();
while(1)
{
voltage();
frequency();
}// while
}// void main
النتيجة :

|