Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

program written in mikroc for 16f877a pic

Status
Not open for further replies.

Gaber2611

Member level 1
Member level 1
Joined
Apr 21, 2012
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,677
hello everybody here,

my pleasure to be here seeking help from professionals here.

my target is to do simulation for that attached circuit on proteus, and what i have problem with is programming the pic, as it's my 1st time with programming, so not familiar with, and that's why i am here.

the circuit is to work as multimeter, measuring voltage and ampere, with two probes to take the readings (0-5v)&(0-2A), and display that on 2*16 lcd, 4-bit mode.

i searched a lot, and tried a lot from references and using help file from mikroc-but never arrived to what i need, i found similar programs which are ready to compile and build the hex file, and tried to modify to work for my attached circuit, but never worked, and gave errors all the time.

so any kind of help here?, to put me on the right start of that program?, or to provide me with a hex file?, hope so

Note: i found many threads similar to mine, but as i said previously, i tried, but with no result.
View attachment multimeter circuit.bmp
will appreciate your reply,

thanks.
 

Do you know CCS then I can help you with codes;you need to use adc module of the pic,can you provides your codes here then we can help
 

i didn't use adc module, as the pic has it's own built in it, i only used operational amplifier to give accurate readings of the voltage and ampere, and by the way here is a code program which measure voltage, ampere, watt and resistance, and i need to modify it to only measure voltage and current.


unsigned char ch;
unsigned int Napon_rd, Struja_rd;
unsigned long u, i, power, res;

#include "Ar2r.h"

void main()
{
INTCON = 0; // Disable all interrupts
Usart_Init(19200); // Initialize USART module (8 bit, 38400 baud rate, no parity)
// (I think this is bug in MikroC, Init is on 19200 but it
// actualy works at speed 38400)

Lcd_Init(&PORTB); // Lcd_Init, see Autocomplete
LCD_Cmd(LCD_CURSOR_OFF); // send command to LCD (cursor off)
Ar2r(); // Show splash screen :)
LCD_Cmd(LCD_CLEAR); // send command to LCD (clear LCD)

ADCON1 = 0x88; // configure Vref, and analog channels
TRISA = 0xFF; // designate PORTA as input

while (1)
{
// Voltage
Napon_rd=ADC_read(1); // get ADC value for U from channel 1
u=(long)Napon_rd*3500; // covert adc reading to milivolts
u=u/1023; // 0..1023 -> 0-3500mV

ch=u/1000; // extract 10.00 U digit
Usart_Write(48+ch); // write ASCII digit on serial port
if (ch==0)
{
LCD_Chr(1,2, 32); // write empty space if digit is 0
}
else
{
LCD_Chr(1,2,48+ch); // write ASCII digit at 1st row, 2nd column
}

ch=(u/100) %10; // extract 01.00 U digit
Usart_Write(48+ch); // write ASCII digit on serial port
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('.'); // write '.' at cursor point
Usart_Write(','); // write ',' on serial port

ch=(u/10) %10; // extract 00.10 U digit
Usart_Write(48+ch); // write ASCII digit on serial port
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

ch=u %10; // extract 00.01 U digit
Usart_Write(48+ch); // write ASCII digit on serial port
//if (Button(&PORTD, 1, 1, 0)) // read jumper 2 ON/OFF for last digit of U
{
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
}
//else
{
//LCD_Chr_CP(32); // write empty space at cursor point
}
LCD_Chr_CP('V'); // write 'V' at cursor point
Usart_Write('V'); // write 'V' on serial port
Usart_Write('\n'); // write '\n' on serial port

// Curent
Struja_rd=ADC_read(0); // get ADC value for I from channel 0
i=(long)Struja_rd*3500; // covert adc reading to milivolts
i=i/1023; // 0..1023 -> 0-3500mV

ch=i/1000; // extract 1.000 I digit
Usart_Write(48+ch); // write ASCII digit on serial port
LCD_Chr(1,10,48+ch); // write ASCII digit at 1st row, 10th column
LCD_Chr_CP('.'); // write '.' at cursor point
Usart_Write(','); // write ',' on serial port

ch=(i/100) %10; // extract 0.100 I digit
Usart_Write(48+ch); // write ASCII digit on serial port
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

ch=(i/10) %10; // extract 0.010 I digit
Usart_Write(48+ch); // write ASCII digit on serial port
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

ch=i %10; // extract 0.001 I digit
Usart_Write(48+ch); // write ASCII digit on serial port
//if (Button(&PORTD, 0, 1, 0)) // read jumper 1 ON/OFF for last digit of I
{
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
}
//else
{
//LCD_Chr_CP(32); // write empty space at cursor point
}
LCD_Chr_CP('A'); // write 'A' at cursor point
Usart_Write('A'); // write 'A' on serial port
Usart_Write('\n'); // write '\n' on serial port

//Power Calculation
power=u*i/1000;
ch=power/1000; // extract 10.00 P digit
if (ch==0)
{
LCD_Chr(2,2, 32); // write empty space if digit is 0
}
else
{
LCD_Chr(2,2,48+ch); // write ASCII digit at 2nd row, 2nd column
}

ch=(power/100) %10; // extract 01.00 P digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('.'); // write '.' at cursor point

ch=(power/10) %10; // extract 0.10 P digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

ch=power %10; // extract 0.01 P digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('W'); // write 'W' at cursor point

// Resistance Calculation
if(power==0)
{
LCD_Out(2,10," "); // write empty space
LCD_Chr_CP(243); // write 'infinity' at cursor point
LCD_Out(2,13," "); // write empty space
LCD_Chr_CP(244); // write 'ohm' at cursor point
}
else
{
res=u*100/i;
if(res>=10000)
{
LCD_Out(2,10," > 1K"); // write " > 1K"
LCD_Chr_CP(244); // write 'ohm' at cursor point
}
else
{
ch=res/1000; // extract 100.0 R digit
if (ch==0)
{
LCD_Chr(2,10, 32); // write empty space if digit is 0
}
else
{
LCD_Chr(2,10,48+ch); // write ASCII digit at 2nd row, 10th column
}

ch=(res/100) %10; // extract 010.0 R digit
if (ch==0 && res<=99)
{
LCD_Chr_CP(32); // write empty space if digit is 0
}
else
{
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
}

ch=(res/10) %10; // extract 001.0 R digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('.'); // write '.' at cursor point

ch=res %10; // extract 000.1 R digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP(244); // write 'ohm' at cursor point
}
}

//Delay_ms(50); // Waits 50ms
}
}

- - - Updated - - -

that program display the readings on both lcd and pc, and what i need is to only show on pc--can this be modified to work for my circuit goal?
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top