imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,493
Please let me know that the code I written for PIC16F676 4Mhz internal oscillator in mikroC pro for PIC but it gives enough RAM error but it has 8-channel 10-bit ADC, how to resolve this error please let me know but same program is successfully compile in PIC16F72 and PIC16F688.
Code:
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
unsigned long PV,BV,PA,BA;
unsigned char *Pvolt = "P V: 00.0V";
unsigned char *Bvolt = "BAT: 00.0V";
unsigned char *Pamp = "00.0A";
unsigned char *Bamp = "00.0A";
void main()
{
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001111; // PORTA All Outputs, Except RA3 and RA2
ADC_Init();
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
do
{
PV = ADC_Read(0); // Read analog value from channel 0
PA = ADC_Read(1); // Read analog value from channel 1
BV = ADC_Read(2); // Read analog value from channel 2
BA = ADC_Read(3); // Read analog value from channel 3
PV = ((PV*4.89)/5)*90; // V GOES FROM 0 TO 90 volts
BV = ((BV*4.89)/5)*30; // V GOES FROM 0 TO 20 volts
PA = ((PA*4.89)/5)*20; // V GOES FROM 0 TO 20 volts
BA = ((BA*4.89)/5)*35; // V GOES FROM 0 TO 20 volts
Pvolt[5] = (PV/10000)+48; // Extract volts (thousands of millivolts) from result
Pvolt[6] = (PV/1000)%10+48; // Extract thousands of mv
Pvolt[8] = (PV/100)%10+48; // Extract hundreds of mv
Lcd_Out(1,1,Pvolt);
Delay_ms(150);
Pamp[0] = (PA/10000)+48; // Extract volts (thousands of millivolts) from result
Pamp[1] = (PA/1000)%10+48; // Extract thousands of mv
Pamp[3] = (PA/100)%10+48; // Extract hundreds of mv
Lcd_Out(1,12,Pamp);
Delay_ms(150);
Bvolt[5] = (BV/10000)+48; // Extract volts (thousands of millivolts) from result
Bvolt[6] = (BV/1000)%10+48; // Extract thousands of mv
Bvolt[8] = (BV/100)%10+48; // Extract hundreds of mv
Lcd_Out(2,1,Bvolt);
Delay_ms(150);
Bamp[0] = (BA/10000)+48; // Extract volts (thousands of millivolts) from result
Bamp[1] = (BA/1000)%10+48; // Extract thousands of mv
Bamp[3] = (BA/100)%10+48; // Extract hundreds of mv
Lcd_Out(2,12,Bamp);
Delay_ms(150);
} while(1);
}