Sie sind auf Seite 1von 6

ola amigos aguel poderia me ajuda preciso fazer um multimetro com os sguinte int es: todos ele em mikroc

Pro 1.Voltimetro 2.Amperimetro 3.Conta giro 4.Frequencimetro 5.Termometro 6.Capacimetro 7.Resistor espero que me ajude meu email e albertoice@yahoo.com.br Ja possuo os codigo seguinte com men adaptado abaixo: //declr funes void escreveVet(char *vet,int linha); void conv_freq(long temp); // Lcd pinout settings sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit sbit sbit sbit sbit sbit sbit LCD_RS_Direction at TRISB4_bit; LCD_EN_Direction at TRISB5_bit; LCD_D4_Direction at TRISB0_bit; LCD_D5_Direction at TRISB1_bit; LCD_D6_Direction at TRISB2_bit; LCD_D7_Direction at TRISB3_bit; SelectButton at Rd7_bit;

sbit Gate_Enable at RC1_bit; // Define Messages char message3[] = "T="; char message4[] = "I="; char message5[] = "Freq= Hz"; // End Message unsigned char ch; unsigned int adc_rd; char *text; long tlong; //unsigned int Num; char *freq = "00000.00"; long counter, Num, lowfreq; unsigned short CountDone, upscale, prescaler;

void Display_Freq(long freq2write) { freq[0] = (freq2write/10000000) + 48; // Extract tens digit freq[1] = (freq2write/1000000)%10 + 48; // Extract ones digit freq[2] = (freq2write/100000)%10 + 48; freq[3] = (freq2write/10000)%10 + 48; freq[4] = (freq2write/1000)%10 + 48; freq[6] = (freq2write/100)%10 + 48; freq[7] = (freq2write/10)%10 + 48; // Display Frequency on LCD Lcd_Out(2, 6, freq); } long count_pulse(){ long ff = 0; Gate_Enable = 0; CountDone = 0; Num = 0; TMR1L = 0xDC; //TMR1 start time = 3036 for 100 ms TMR1H = 0x0B; TMR0 = 0; T1CON.TMR1ON = 1; do { }while(!CountDone); Gate_Enable = 1; T1CON.TMR1ON = 0; // Disable Timer1 ff = 256*Num + TMR0; ff = ff*10*prescaler; return ff; } // Interrupt service routine void interrupt() { if(INTCON.T0IF){ Num ++; // Interrupt causes Num to be incremented by 1 INTCON.T0IF = 0; // Bit T0IF is cleared so that the interrupt could reoccur } if (PIR1.TMR1IF){ //Let me use this even if no other interrupts are enabled CountDone = 1; PIR1.TMR1IF = 0; //reset timer1 flag } } unsigned int select, update_select; void debounce_delay(void){ Delay_ms(200); } char texto1[7], numflancos=0; int rpm, rads; ///////////////////////// int counts,oldCounts; char txt[6]; void showdata(unsigned int); void showdata(unsigned int ia) { WordToStr(ia, txt); // Transform counter value to string

} ///////////////////// void main(){ //inicializando os registradores TRISC = 0b00000001; // PORTC All Outputs CMCON = 0x07; // Turn off comparators TRISB= 0X00; // Porta B como saida para o LCD TRISA=0XFF; //Porta A como entrada TRISC=0XFF; //Porta C como entrada ADCON1=0X00; //Configura conversor AD da porta A T1CON=0X06; //Configura timer 1 OPTION_REG=0X80; //Desabilita pull-up internas ///0x80 PIE1=0X00; //Desabilita algumas interrupcoes PIR1=0X00; //Desabilita algumas interrupcoes INTCON=0X00; //Desabilita todas as interrupcoes PORTB=0X00; //Inicia Porta B com zero TRISd=0XFF; //Porta A como entrada PORTD=0XFF; //Porta A como entrada Gate_Enable = 1; // TMR1 settings T1CON.TMR1CS = 0; // Fosc / 4 T1CON.T1CKPS1 = 1; // Setting prescale value to 1:8 T1CON.T1CKPS0 = 1; PIE1.TMR1IE = 1; INTCON.PEIE = 1; INTCON.T0IE = 1; INTCON.GIE = 1; Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

select = 0; update_select = 1; do { if (Button(&PORTd, 5, 10, 0)) {counts--; if(counts<=0)counts =0;} if (Button(&PORTd, 6, 1, 0)) ///1000 {counts++; if(counts>=150000)counts=150000;} if(oldCounts!=counts) { showdata(counts); oldCounts = counts; } if(!SelectButton){ debounce_delay(); update_select = 1; switch (select) { case 0 : select=1; break; case 1 : select=2;

break; case 2 : select=3; break; case 3 : select=0; break; } //case end } if(select == 0){ // Diode Tester if(update_select){ Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,Message3); Lcd_Chr(1,7,'V'); Lcd_Out(1,9,Message4); Lcd_Chr(1,16,'A'); Lcd_Out(2,1,message5); // Clear display update_select=0; } // Read Current adc_rd = ADC_read(1); // get ADC value from 2nd channel tlong = (long)adc_rd * 1000; // covert adc reading to milivolts tlong = tlong / 1023; // 0..1023 -> 0-5000mV ch = tlong / 1000; // extract volts digit LCD_Chr(1,11,48+ch); // write ASCII digit at 2nd row, 9th column ch = (tlong / 100) % 10; // extract 0.1 LCD_Chr_CP(48+ch); // write ASCII digit LCD_Chr_CP('.'); ch = (tlong / 10) % 10; // extract 0.01 LCD_Chr_CP(48+ch); // write ASCII digit volts digit at cursor point volts digit at cursor point

ch = tlong % 10; // extract 0.001 volts digit LCD_Chr_CP(48+ch); // write ASCII digit at cursor point Delay_ms(333); // Read Voltage adc_rd = ADC_read(0); // get ADC value from 2nd channel tlong = (long)adc_rd * 9000; // covert adc reading to milivolts tlong = tlong / 1023; // 0..1023 -> 0-5000mV ch = tlong / 1000; // extract volts digit LCD_Chr(1,3,48+ch); // write ASCII digit at 2nd row, 9th column ch = (tlong / 100) % 10; // extract 0.1 LCD_Chr_CP(48+ch); // write ASCII digit LCD_Chr_CP('.'); ch = (tlong / 10) % 10; // extract 0.01 LCD_Chr_CP(48+ch); // write ASCII digit volts digit at cursor point volts digit at cursor point

LCD_Chr_CP('V'); Delay_ms(333); // Calculate Frequency // First begin with prescaler 1:64 OPTION_REG = 0b00110101; // Prescaler (1:64), TOCS =1 prescaler = 64; Counter = count_pulse(); if (Counter > 99990) { Display_Freq(Counter); Lcd_Chr(2,14,'K'); //lowfreq = Counter*1000; //Lcd_Out(2,1,message5); //Display_Freq(lowfreq); } if (Counter <= 99990) { OPTION_REG = 0b00111000; // Prescaler (1:1), TOCS =1 prescaler = 1; Counter = count_pulse(); Counter = 1000*Counter; Display_Freq(Counter); Lcd_Chr(2,14,' '); } delay_ms (333); } // End if(select == 0) ///////////////////////// if(select == 1){ // Diode Tester if(update_select){ Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Termometro"); Lcd_Out(2,1,"Temp.="); // Clear display update_select=0; } adc_rd = ADC_read(2); // get ADC value from 2nd channel adc_rd = ADC_read(2); // get ADC value from 2nd channel // print string a on LCD, 2nd row, 1st column tlong = (long)adc_rd * 5000; // covert adc reading to milivolts tlong = tlong / 1023; // 0..1023 -> 0-5000mV ch = tlong / 1000; // extract volts digit LCD_Chr(2,7,48+ch); // write ASCII digit at 2nd row, 9th column ch = (tlong / 100) % 10; // extract 0.1 volts digit LCD_Chr_CP(48+ch); // write ASCII digit at cursor point ch = (tlong / 10) % 10; // extract 0.01 volts digit LCD_Chr_CP(48+ch); // write ASCII digit at cursor point LCD_Chr_CP('.');

ch = tlong % 10; // extract 0.001 volts digit LCD_Chr_CP(48+ch); // write ASCII digit at cursor point Lcd_Chr(2,12,223); Lcd_Chr(2,13,'C'); Delay_ms(333); } // End if(select == 0) if(select == 2){ // Diode Tester if(update_select){ Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Conta Giro"); Lcd_Out(2,1,"Rpm="); // Clear display update_select=0; } TMR0=0; //Inicializa el registro TMR0. Delay_1sec(); //Cuenta durante 1 segundo. numflancos=TMR0; //numflancos=velocidad en rps. rpm=60*numflancos; //Transformacin a rpm. rads=6.28*numflancos; //Transformacin a rad/s. IntToStr(rpm,texto1); //Transformacin de rpm a texto. Lcd_Out(2,5,texto1); Delay_ms(1000); //Espera para la nueva medicin. } // End if(select == 2) if(select == 3){ // Diode Tester if(update_select){ Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Contador de evento"); // Clear display update_select=0; } Lcd_Out(2, 1, "N"); Lcd_Out(2, 8, txt); Delay_ms(333); } // End if(select == 3) } while(1); // endless loop }

Das könnte Ihnen auch gefallen