FAILED TO CORRECT THE ERRORS FOUND.
Posted: 12 Mar 2012 11:36
THIS IS MY C SOURCE CODE AND I HAVE FAILED TO RECTIFY THE ERRORS IN IT.
AM USING PIC16F887.
PLEASE HELP
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_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 TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_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;
char txt1[] = "ELDI ";
char txt2[] = "DIGITAL ENERGY";
char txt3[] = "METER";
char txt4[] = "ENERGY METER";
char txt5[] = "KWH";
int volt_res;
int curent_res;
long power;
int energy,i;
long powerlong;
power_dis[4];
#define INT_RANGE 1000
#define DEC_RANGE 10
LCD_printFix (unsigned int v)
{
unsigned int w;
unsigned int d;
unsigned char n;
unsigned char blk = 1 ;
v = abs (v) ;
w = v / DEC_RANGE;
for (d = INT_RANGE / 10; d > 0; d /= 10)
{
n = (w / d) % 10;
if (n)
{
blk = 0;
}
If (blk)
{
LCD_Chr_Cp (' ') ;
}
else
{
LCD_Chr_Cp ('0' + n) ;
}
}
}
void Move_Delay () { // Function used for text moving
Delay_ms (100); // You can change the moving speed here
}
void Compute_Energy ()
{
}
void adc_fetch ()
{
volt_res = ADC_Read (1);
// Lcd_Out (2,4,"234");
curent_res = 1; //ADC_Read (0);
power = volt_res * curent_res;
powerlong = (long)power * 5000;
powerlong = powerlong / 1023;
power_dis[3] = powerlong / 10000;
power_dis[2] = (powerlong / 1000) % 10;
power_dis[1] = (powerlong / 100) % 10;
power_dis[0] = powerlong % 10;
}
void Time_Hour ()
{
Compute_Energy ();
}
void main ()
{
// ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
ANSEL = 0x0b; // Pin RA0 and RA1 are configured as an analog inputs
TRISA = 0x0b;
TRISB = 0x00;
// C1ON_bit = 0; // Disable comparators
//C2ON_bit = 0;
Lcd_Init (); // Initialize LCD
ADCON1.F4 = 1; // Voltage reference is brought to the RA3 pin.
// ADCON1 = 0x82; // A/D voltage reference is VCC
Lcd_Cmd (_LCD_CURSOR_OFF);
Lcd_Out (1, 10, txt1);
Lcd_Cmd (_LCD_CLEAR); // Clear display
Lcd_Out (1,11,txt1);
Move_Delay();
// for (i=0; i<6; i++) { // Move text to the left 7 times
// Lcd_Cmd (_LCD_SHIFT_RIGHT);
// Delay_ms (20);
// }
// for (i=0; i<6; i++) { // Move text to the left 7 times
// Lcd_Cmd (_LCD_SHIFT_LEFT);
// Delay_ms (20);
// }
Lcd_Cmd (_LCD_CLEAR); // Clear display
Lcd_Out (1,2,txt2); // Write text in first row
Lcd_Out (2,6,txt3); // Write text in second row
Delay_ms (100);
//Lcd_Out (1,1,txt2); // Write text in first row
//Lcd_Out (2,5,txt3); // Write text in second row
//Delay_ms (2000);
Lcd_Cmd (_LCD_CLEAR);
Lcd_Out (1,3,txt4); // Write text in first row
Lcd_Out (2,12,txt5); // Write text in second row
While (1) { // Endless loop
//Lcd_Out (2,4,"234");
adc_fetch ();
// power = volt_res * curent_res;
Lcd_Out (2,6,power);
For (i=0; i<8; i++) {
Lcd_Chr (2,5,48+power_dis[3]); // Write result in ASCII format
Lcd_Chr (2,6,48+power_dis[2]); // Write result in ASCII format
Lcd_Chr (2,7,48+power_dis[1]); // Write result in ASCII format
Lcd_Chr (2,8,'.');
Lcd_Chr (2,9,48+power_dis[0]); // Write result in ASCII format
// Delay_ms (500);
}
}
}
AM USING PIC16F887.
PLEASE HELP
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_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 TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_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;
char txt1[] = "ELDI ";
char txt2[] = "DIGITAL ENERGY";
char txt3[] = "METER";
char txt4[] = "ENERGY METER";
char txt5[] = "KWH";
int volt_res;
int curent_res;
long power;
int energy,i;
long powerlong;
power_dis[4];
#define INT_RANGE 1000
#define DEC_RANGE 10
LCD_printFix (unsigned int v)
{
unsigned int w;
unsigned int d;
unsigned char n;
unsigned char blk = 1 ;
v = abs (v) ;
w = v / DEC_RANGE;
for (d = INT_RANGE / 10; d > 0; d /= 10)
{
n = (w / d) % 10;
if (n)
{
blk = 0;
}
If (blk)
{
LCD_Chr_Cp (' ') ;
}
else
{
LCD_Chr_Cp ('0' + n) ;
}
}
}
void Move_Delay () { // Function used for text moving
Delay_ms (100); // You can change the moving speed here
}
void Compute_Energy ()
{
}
void adc_fetch ()
{
volt_res = ADC_Read (1);
// Lcd_Out (2,4,"234");
curent_res = 1; //ADC_Read (0);
power = volt_res * curent_res;
powerlong = (long)power * 5000;
powerlong = powerlong / 1023;
power_dis[3] = powerlong / 10000;
power_dis[2] = (powerlong / 1000) % 10;
power_dis[1] = (powerlong / 100) % 10;
power_dis[0] = powerlong % 10;
}
void Time_Hour ()
{
Compute_Energy ();
}
void main ()
{
// ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
ANSEL = 0x0b; // Pin RA0 and RA1 are configured as an analog inputs
TRISA = 0x0b;
TRISB = 0x00;
// C1ON_bit = 0; // Disable comparators
//C2ON_bit = 0;
Lcd_Init (); // Initialize LCD
ADCON1.F4 = 1; // Voltage reference is brought to the RA3 pin.
// ADCON1 = 0x82; // A/D voltage reference is VCC
Lcd_Cmd (_LCD_CURSOR_OFF);
Lcd_Out (1, 10, txt1);
Lcd_Cmd (_LCD_CLEAR); // Clear display
Lcd_Out (1,11,txt1);
Move_Delay();
// for (i=0; i<6; i++) { // Move text to the left 7 times
// Lcd_Cmd (_LCD_SHIFT_RIGHT);
// Delay_ms (20);
// }
// for (i=0; i<6; i++) { // Move text to the left 7 times
// Lcd_Cmd (_LCD_SHIFT_LEFT);
// Delay_ms (20);
// }
Lcd_Cmd (_LCD_CLEAR); // Clear display
Lcd_Out (1,2,txt2); // Write text in first row
Lcd_Out (2,6,txt3); // Write text in second row
Delay_ms (100);
//Lcd_Out (1,1,txt2); // Write text in first row
//Lcd_Out (2,5,txt3); // Write text in second row
//Delay_ms (2000);
Lcd_Cmd (_LCD_CLEAR);
Lcd_Out (1,3,txt4); // Write text in first row
Lcd_Out (2,12,txt5); // Write text in second row
While (1) { // Endless loop
//Lcd_Out (2,4,"234");
adc_fetch ();
// power = volt_res * curent_res;
Lcd_Out (2,6,power);
For (i=0; i<8; i++) {
Lcd_Chr (2,5,48+power_dis[3]); // Write result in ASCII format
Lcd_Chr (2,6,48+power_dis[2]); // Write result in ASCII format
Lcd_Chr (2,7,48+power_dis[1]); // Write result in ASCII format
Lcd_Chr (2,8,'.');
Lcd_Chr (2,9,48+power_dis[0]); // Write result in ASCII format
// Delay_ms (500);
}
}
}