Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f72 to 16f676 conversion

Status
Not open for further replies.

sahu

Member
i have need microc source code conversion with 16f72 to 16f676.
16f72 microc source code as...

Code:
float ch; //
unsigned int adc_rd; // Declare variables
long tlong;
void main()
{
TRISA = 0x3F; // setting AD0 for input
TRISB = 0x00; // setting port B as output.
TRISC = 0b11000000; // selecting port c as output
ADCON0=0x01;
ADCON1=0x00;
//PORTB = 0x00;
loop:

RC0_bit = 1; // delay indicator on
RC1_bit = 0; // mains indicator off
RC5_bit = 0; // Output relay off

/*................................................. ...............................
Delay mode selection for user friendly... 
.................................................. ...............................*/

if(RC6_bit = 0)
{
Delay_ms(5000);
}
else
{
Delay_ms(100);
}

/* .................................................. .............................
Main working starts here
.................................................. ................................*/
RC0_bit = 0; // delay indicator off.
while(1)
{
adc_rd = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 255; // 0..1023 -> 0-5000mV
ch =(float) tlong / 1000; // Extract volts (thousands of millivolts)

/*................................................. ...............................
Main stabilizing is done here
.................................................. ...............................*/

if((ch<=1.9)&&(ch>=1.30))
{

if(ch>1.33)
{
if(ch>1.40)
{
if(ch>1.48)
{
if(ch>1.56)
{
if(ch>1.63)
{
if(ch>1.704)
{
if(ch>1.78)
{
if(ch>1.85)
{
PORTB =0b00000001;
}
else
PORTB =0b00000011;
}
else
PORTB =0b00000111;
}
else
PORTB =0b00001111;
}
else
PORTB =0b00011111;
}
else
PORTB =0b00111111;
}
else
PORTB =0b01111111;
}
else
PORTB =0b11111111;

}
else
PORTB = 0x00;

RC5_bit = 1; // output relay on.
RC1_bit = 1; // mains indicator on
RC3_bit = 1; // normal indicator on.
RC4_bit = 0; // high voltage indicator off
RC2_bit = 0; // low voltage indicator off
}

/*................................................. ...............................
High voltage protection for load is done here
.................................................. ...............................*/

if(ch > 2.10)
{
RC4_bit = 1; // high voltage indicator on
RC2_bit = 0; // low voltage indicator off
RC5_bit = 0; // relay off
RC1_bit = 0; // Mains normal indicator off
RC3_bit = 0; // normal indicator off.
PORTB = 0x00;
goto loop;
}
/*................................................. ...............................
Low voltage protection is done here
.................................................. ...............................*/

if(ch <= 1.30)
{
RC2_bit = 1; // low voltage indicator on
RC5_bit = 0; // O/P relay off
RC3_bit = 0; // Mains normal indicator off
RC4_bit = 0; // high indicator on.
RC1_bit = 0; // Mains normal indicator off
PORTB = 0x00;
goto loop;
}


}

}

16f676 microc source code as...

Code:
float ch;
unsigned int ADC_Value;
long tlong;
/*................................................. ...............................
 Define relay selection port pins
.................................................. ...............................*/
sbit RL1 @ PORTA:1;
sbit RL2 @ PORTC:0;
sbit RL3 @ PORTC,1;
sbit RL4 @ PORTC,2;
sbit RL5 @ PORTA,2;
//defined RL1 at PORTA,1;//PIN 12
//sbit RL2 at RC0_bit;//PIN 10
//sbit RL3 at RC1_bit;//PIN 09
//sbit RL4 at RC2_bit;//PIN 08
//sbit RL5 at PORTA,2;//PIN 11
/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/
sbit L1 at  Rc5_bit;//PIN 05 hi\lo cut
sbit L2 at  Rc4_bit;//PIN 06 mains normal
sbit BZR at Rc3_bit;//PIN 07 SOUND
 
/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/
 
sbit SW1 at  PORTA,5;//PIN 03 hi\lo cut enabol
sbit SW2 at  PORTA,4;//PIN 02 QEK SATART
 
 
void main()
{
//ANSEL = 0x01;  // RA0 analog input
    TRISA = 0x39; // setting RA0 analog input & RA3 -RA5 digital i\p
    TRISC = 0x00; // setting port C as output.
    // Configure ADCON0 for channel AN0
    ADCON0=0x01;
    ADCON1=0x00;
 
 
loop_01:
 
    L2 = 1;// mains normal on
    L1 = 0;// hi\lo cut off
    BZR = 0;// SOUND off
    RL4 = 0;// Output relay off R4
 
    /*................................................. ...............................
    Delay mode selection for user friendly...
    .................................................. ...............................*/
 
    if(SW2 == 0)
    {
        Delay_ms(5);
    }
    else
    {
        Delay_ms(1);
    }
 
    /* .................................................. .............................
    Main working starts here
    .................................................. ................................*/
    L1 = 0; // delay indicator off.
    while(1)
    {
        ADC_Value = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
        tlong =(long)ADC_Value*5000; // Convert the result in millivolts
        tlong = tlong/1023; // 0..1023 -> 0-5000mV
        ch =(float)tlong/1000; // Extract volts (thousands of millivolts)
 
        /*................................................. ...............................
        Main stabilizing is done here
        .................................................. ...............................*/
 
        if((ch<=4.60)&&(ch>=1.40))
        {
 
            if(ch>4.65)
            {
                if(ch>4.00)
                {
                    if(ch>3.65)
                    {
                        if(ch>3.15)
                        {
                            if(ch>2.56)
                            {
                                if(ch>1.48)
                                {
                                    //if(ch>1.40)
                                    //{
                                    RL5 = 1;
                                    RL3 = 1;
                                    RL2 = 1;
                                    RL1 = 0;//STP7
                                }
                                //else
                                RL5 = 1;
                                RL2 = 1;
                                RL1 = 0;
                                RL3 = 0;//STP6
                            }
                            //else
                            RL3 = 1;
                            RL2 = 1;
                            RL1 = 0;
                            RL5 = 0;//STP5
                        }
                        //else
                        RL2 = 1;
                        RL1 = 0;
                        RL5 = 0;
                        RL3 = 0;//STP4
                    }
                    //else
                    RL3 = 1;
                    RL1 = 0;
                    RL5 = 0;
                    RL2 = 0;//STP3
                }
                //else
                RL1 = 0;
                RL3 = 1;
                RL5 = 0;
                RL2 = 0;//STP2
            }
            //else
            RL3 = 1;
            RL1 = 0;
            RL5 = 0;
            RL2 = 0;//STP1
        }
        //else
        RL5 = 1;
        RL3 = 1;
        RL2 = 1;
        RL1 = 0;
 
        RL4 = 1;// output relay on.
        L2 = 1; // mains indicator on
        L1 = 0; // high //low voltage indicator off
        BZR = 0; // high //low voltage indicator off
 
    }
 
    /*................................................. ...............................
    High voltage protection for load is done here
    .................................................. ...............................*/
 
    if(ch > 4.80)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }
    /*................................................. ...............................
    Low voltage protection is done here
    .................................................. ...............................*/
 
    if(ch <= 1.30)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }
 
}  // End main()

found error as..

Code:
error: 102****342****There is not enough ROM space****__Lib_MathDouble.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 1091****392****Address must be greater than 0 Div_32x32_S****__Lib_Math.c
error: 1091****392****Address must be greater than 0 Div_32x32_S****__Lib_Math.c
error: 49****392****Address must be greater than 0 ADC_Read****__Lib_ADC_A_B.c
error: 1903****392****Address must be greater than 0 Longint2Double****__Lib_MathDouble.c
error: 24****392****Address must be greater than 0 __CC2DW****__Lib_System.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 761****392****Address must be greater than 0 Div_32x32_FP****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 245****392****Address must be greater than 0 NRM4032****__Lib_MathDouble.c
error: 0****102****Finished (with errors): 12 Aug 2011, 21:43:39****MyProject.mcppi

pl help me...for conversion ..
 
The 16f676 doesn't have enough Memory to use __Lib_MathDouble.c
There is not enough ROM space****__Lib_MathDouble.c

The 16f676 has haft the Memory that the 16f72 has.
 
Last edited:
The 16f676 doesn't have enough Memory to use __Lib_MathDouble.c

The 16f676 has haft the Memory that the 16f72 has.
have u any other method about adc sensing + relay drive. which can 16f676 memory.
 
Zip your project files up and post it and I'll fix it if you want
 
Zip your project files up and post it and I'll fix it if you want

my dear sir actually i problem is ...

error: 102****342****There is not enough ROM space****__Lib_MathDouble.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c
error: 27****392****Address must be greater than 0 main****MyProject.c

so ...if microc compiler want more than 1k words of flash (ROM) memory for program storage for my code .pl sages me which compiler subtable for my code or any other method adc sense & controlled relay
i have perchege form our local market 16f676 based stabilizer control card . which have all control feacher as my above code.

i think CCS compiler is best for my code ...
**broken link removed**
if posibol help me for conversion my code in CCS C
 
Last edited:
Stop using floating point and instead do all calculations in millivolts. This will reduce the size of your code immensely and it will easily fit.

So, instead of doing,
Code:
if((ch<=4.60)&&(ch>=1.40))

Do,
Code:
if((ch<=4600)&&(ch>=1400))

And change,
Code:
        ch =(float)tlong/1000; // Extract volts (thousands of millivolts)
To,
Code:
        ch = tlong       // Extract volts (thousands of millivolts)


Mike.
 
Stop using floating point and instead do all calculations in millivolts. This will reduce the size of your code immensely and it will easily fit.

So, instead of doing,
Code:
if((ch<=4.60)&&(ch>=1.40))

Do,
Code:
if((ch<=4600)&&(ch>=1400))

And change,
Code:
        ch =(float)tlong/1000; // Extract volts (thousands of millivolts)
To,
Code:
        ch = tlong       // Extract volts (thousands of millivolts)


Mike.


thank u thank u thank u thank u thank u
i hope may be my my problem solve.
but one confession...right now i use as..
Code:
float ch;
Do,
Code:
???
 
Do,

long ch;

Mike.
like this
long ch,tlong;
ok

i was change as above & compile. compiler give as massage ...
warning: 0 1501 Specified search path does not exist: 'C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs'
warning: 0 1501 Specified search path does not exist: 'C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16'
warning: 0 1501 Specified search path does not exist: 'C:\Documents and Settings\Administrator.BDG\My Documents\Projects\MikroC\Sahu'
hint: 0 1139 Available RAM: 48 [bytes], Available ROM: 1024 [bytes]
diagnostics: 0 126 All files Preprocessed in 31 ms
diagnostics: 0 122 Compilation Started sahu.c
diagnostics: 173 123 Compiled Successfully sahu.c
diagnostics: 0 127 All files Compiled in 47 ms
hint: 0 1144 Used RAM (bytes): 15 (31%) Free RAM (bytes): 33 (69%) Used RAM (bytes): 15 (31%) Free RAM (bytes): 33 (69%)
hint: 0 1144 Used ROM (program words): 890 (87%) Free ROM (program words): 134 (13%) Used ROM (program words): 890 (87%) Free ROM (program words): 134 (13%)
diagnostics: 0 125 Project Linked Successfully sahu.mcppi
diagnostics: 0 128 Linked in 203 ms
diagnostics: 0 129 Project 'sahu.mcppi' completed: 375 ms
diagnostics: 0 103 Finished successfully: 14 Aug 2011, 15:48:51 sahu.mcppi
 
Last edited:
Pommie said:
Stop using floating point and instead do all calculations in millivolts. This will reduce the size of your code immensely and it will easily fit.

So, instead of doing,



That's what I was going to do for him thanks Mike But his code had a lot of errors In MikroC pro so I wanted to see the project to see what he was using
 
Last edited:
Some thing like this should work

Code:
long ch;
unsigned int ADC_Value;
long tlong;
/*................................................. ...............................
 Define relay selection port pins
.................................................. ...............................*/
sbit RL1 at RA1_bit;
sbit RL2 at RC0_bit;
sbit RL3 at RC1_bit;
sbit RL4 at RC2_bit;
sbit RL5 at RA2_bit;
//defined RL1 at PORTA,1;//PIN 12
//sbit RL2 at RC0_bit;//PIN 10
//sbit RL3 at RC1_bit;//PIN 09
//sbit RL4 at RC2_bit;//PIN 08
//sbit RL5 at PORTA,2;//PIN 11
/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/
sbit L1  at  Rc5_bit;//PIN 05 hi\lo cut
sbit L2  at  Rc4_bit;//PIN 06 mains normal
sbit BZR at  Rc3_bit;//PIN 07 SOUND

/*................................................. ...............................
 Define LED/ bzr selection port pins
.................................................. ...............................*/

sbit SW1 at  RA5_bit;//PIN 03 hi\lo cut enabol
sbit SW2 at  RA4_bit;//PIN 02 QEK SATART


void main()
{
//ANSEL = 0x01;  // RA0 analog input
    TRISA = 0x39; // setting RA0 analog input & RA3 -RA5 digital i\p
    TRISC = 0x00; // setting port C as output.
    // Configure ADCON0 for channel AN0
    ADCON0=0x01;
    ADCON1=0x00;


loop_01:

    L2 = 1;// mains normal on
    L1 = 0;// hi\lo cut off
    BZR = 0;// SOUND off
    RL4 = 0;// Output relay off R4

    /*................................................. ...............................
    Delay mode selection for user friendly...
    .................................................. ...............................*/

    if(SW2 == 0)
    {
        Delay_ms(5);
    }
    else
    {
        Delay_ms(1);
    }

    /* .................................................. .............................
    Main working starts here
    .................................................. ................................*/
    L1 = 0; // delay indicator off.
    while(1)
    {
        ADC_Value = ADC_Read(0); // A/D conversion. Pin RA2 is an input.
        tlong =(long)ADC_Value*5000; // Convert the result in millivolts
        tlong = tlong/1023; // 0..1023 -> 0-5000mV
        ch =tlong; // Extract volts (thousands of millivolts)

        /*................................................. ...............................
        Main stabilizing is done here
        .................................................. ...............................*/

        if((ch<=4060)&&(ch>=1040))
        {

            if(ch>4065)
            {
                if(ch>4000)
                {
                    if(ch>3065)
                    {
                        if(ch>3015)
                        {
                            if(ch>2056)
                            {
                                if(ch>1048)
                                {
                                    //if(ch>1.40)
                                    //{
                                    RL5 = 1;
                                    RL3 = 1;
                                    RL2 = 1;
                                    RL1 = 0;//STP7
                                }
                                //else
                                RL5 = 1;
                                RL2 = 1;
                                RL1 = 0;
                                RL3 = 0;//STP6
                            }
                            //else
                            RL3 = 1;
                            RL2 = 1;
                            RL1 = 0;
                            RL5 = 0;//STP5
                        }
                        //else
                        RL2 = 1;
                        RL1 = 0;
                        RL5 = 0;
                        RL3 = 0;//STP4
                    }
                    //else
                    RL3 = 1;
                    RL1 = 0;
                    RL5 = 0;
                    RL2 = 0;//STP3
                }
                //else
                RL1 = 0;
                RL3 = 1;
                RL5 = 0;
                RL2 = 0;//STP2
            }
            //else
            RL3 = 1;
            RL1 = 0;
            RL5 = 0;
            RL2 = 0;//STP1
        }
        //else
        RL5 = 1;
        RL3 = 1;
        RL2 = 1;
        RL1 = 0;

        RL4 = 1;// output relay on.
        L2 = 1; // mains indicator on
        L1 = 0; // high //low voltage indicator off
        BZR = 0; // high //low voltage indicator off

    }

    /*................................................. ...............................
    High voltage protection for load is done here
    .................................................. ...............................*/

    if(ch > 4080)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }
    /*................................................. ...............................
    Low voltage protection is done here
    .................................................. ...............................*/

    if(ch <= 1030)
    {
        L1 = 1; // high // low voltage indicator on
        BZR = 1; // cret sound
        RL4 = 0; // relay off
        L2 = 0; // Mains normal indicator off
        goto loop_01;
    }

}  // End main()
 
Last edited:
Bert,

The line,
Code:
        ch =tlong/1000; // Extract volts (thousands of millivolts)
Should be,
Code:
        ch =tlong;     // Extract volts (thousands of millivolts)
Mike.
 
Compiler show as
hint: 0 1139 Available RAM: 48 [bytes], Available ROM: 1024 [bytes]
diagnostics: 0 126 All files Preprocessed in 31 ms
diagnostics: 0 122 Compilation Started MyProject.c
diagnostics: 164 123 Compiled Successfully MyProject.c
diagnostics: 0 127 All files Compiled in 31 ms
hint: 0 1144 Used RAM (bytes): 13 (27%) Free RAM (bytes): 35 (73%) Used RAM (bytes): 13 (27%) Free RAM (bytes): 35 (73%)
hint: 0 1144 Used ROM (program words): 807 (79%) Free ROM (program words): 217 (21%) Used ROM (program words): 807 (79%) Free ROM (program words): 217 (21%)
diagnostics: 0 125 Project Linked Successfully MyProject.mcppi
diagnostics: 0 128 Linked in 188 ms
diagnostics: 0 129 Project 'MyProject.mcppi' completed: 359 ms
diagnostics: 0 103 Finished successfully: 10 Aug 2011, 23:43:47 MyProject.mcppi
but not working prototype & oshon soft.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top