Hiện nay e đang làm đồ án là làm mạch đo điện áp xoay chiều dùng linh kiện dán. Nhưng e vẫn chưa thể nào mô phỏng chạy được mặc dù thấy đã làm đúng rồi. khi chayj chi hien thi duoc tan so con dien ap ra 0v
Mong các ae giúp đỡ để e được ra trường :v
Đây là code và mạch mô phỏng của e
E dùng Protues và microCpro để làm
unsigned char ch;
unsigned int adc_rd0;
unsigned int temp0=0,temp1=0;
unsigned max_point0 = 0;
unsigned int i,tlong0,tlong1;
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections
char message1[] = "PK:000V";
char message2[] = "RMS:000V";
char *freq = " 00";
void Display_Freq(unsigned int freq2write)
{
freq[1] = (freq2write/10) + 48; // Extract tens digit
freq[2] = (freq2write/1)%10 + 48; // Extract ones digit
// Display Frequency on LCD
Lcd_Out(2, 11, freq);
Lcd_Out(2,14,"Hz");
}
void main()
{
TRISA = 0xFF; // set all pins of PORT A as input
TRISC = 0x00; // set all pins as output
PORTC = 0x00; // clear port C
PORTB = 0x00; // clear port B
ADCON1=0x00; // set all Analog
Delay_ms(1000);
OPTION_REG = 0b00101000; // set TOCKI as clock counter
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);
while(1)
{
// Find the peak amplitude of the sine wave...
max_point0 = 0;
for(i=0;i<5000;i++)
{
ADCON0 = 0b00000001;
if(temp0 = ADC_Read(0),temp0>max_point0)
{
max_point0 = temp0;
}
Delay_us(5);
}
max_point0 = abs(ceil((long)max_point0));
tlong0 = (long)max_point0*(5/255)*11*220/12; // find the peak amplitude of the line
tlong1 = (long)max_point0*((5/255)*11*220/12)*0.707; // find the rms value of the line voltage
message1[3] = tlong0/100 + 48; // convert into ASCII
message1[4] = (tlong0/10)%10 +48; // convert into ASCII
message1[5] = (tlong0)%10 +48; // convert into ASCII
Lcd_Out(1,1,message1); // Display message on LCD
RC0_bit = ~RC0_bit;
message2[4] = tlong1/100 + 48; // convert into ASCII
message2[5] = (tlong1/10)%10 +48; // convert into ASCII
message2[6] = (tlong1)%10 +48; // convert into ASCII
Lcd_Out(1,9,message2); // Display message on LCD
TMR0=0; // clear TMR0
Delay_ms(1000); // Delay 1 Sec
Lcd_Out(2,1,"FREQUENCY:");
Display_Freq(TMR0/2); // divide by 2
TMR0=0;
}// while
}// void main
Mong các ae giúp đỡ để e được ra trường :v
Đây là code và mạch mô phỏng của e
E dùng Protues và microCpro để làm
unsigned char ch;
unsigned int adc_rd0;
unsigned int temp0=0,temp1=0;
unsigned max_point0 = 0;
unsigned int i,tlong0,tlong1;
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections
char message1[] = "PK:000V";
char message2[] = "RMS:000V";
char *freq = " 00";
void Display_Freq(unsigned int freq2write)
{
freq[1] = (freq2write/10) + 48; // Extract tens digit
freq[2] = (freq2write/1)%10 + 48; // Extract ones digit
// Display Frequency on LCD
Lcd_Out(2, 11, freq);
Lcd_Out(2,14,"Hz");
}
void main()
{
TRISA = 0xFF; // set all pins of PORT A as input
TRISC = 0x00; // set all pins as output
PORTC = 0x00; // clear port C
PORTB = 0x00; // clear port B
ADCON1=0x00; // set all Analog
Delay_ms(1000);
OPTION_REG = 0b00101000; // set TOCKI as clock counter
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);
while(1)
{
// Find the peak amplitude of the sine wave...
max_point0 = 0;
for(i=0;i<5000;i++)
{
ADCON0 = 0b00000001;
if(temp0 = ADC_Read(0),temp0>max_point0)
{
max_point0 = temp0;
}
Delay_us(5);
}
max_point0 = abs(ceil((long)max_point0));
tlong0 = (long)max_point0*(5/255)*11*220/12; // find the peak amplitude of the line
tlong1 = (long)max_point0*((5/255)*11*220/12)*0.707; // find the rms value of the line voltage
message1[3] = tlong0/100 + 48; // convert into ASCII
message1[4] = (tlong0/10)%10 +48; // convert into ASCII
message1[5] = (tlong0)%10 +48; // convert into ASCII
Lcd_Out(1,1,message1); // Display message on LCD
RC0_bit = ~RC0_bit;
message2[4] = tlong1/100 + 48; // convert into ASCII
message2[5] = (tlong1/10)%10 +48; // convert into ASCII
message2[6] = (tlong1)%10 +48; // convert into ASCII
Lcd_Out(1,9,message2); // Display message on LCD
TMR0=0; // clear TMR0
Delay_ms(1000); // Delay 1 Sec
Lcd_Out(2,1,"FREQUENCY:");
Display_Freq(TMR0/2); // divide by 2
TMR0=0;
}// while
}// void main