CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

memory problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

memory problem
PostPosted: Sun Mar 07, 2010 4:59 pm     Reply with quote

Hi everyone.

I have a code for a work. But when I compile it, I got:
Quote:

''out of rom,a segment or the program is too large''
seg 00004-007ff,0522 left,need 0700
seg 00800-00fff,0800 left,need 0812
seg 01000-017ff,0800 left,need 0812
seg 01800-01fff,0000 left,need 0812
seg 00004-007ff,0522 left,need 0812

When I comment out one or two 'write_eeprom(...)' statements, I get 34% rom 5% ram usage. Only a few line needs 55-60% rom ???
By the way, I use 16f876 pic with 8 mhz crystal osc. My code is about 500 lines, so I did not post it here. But if anyone wants to examine it to find the problem, I can.
How can I overcome this problem? Any advice?
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Mar 07, 2010 6:12 pm     Reply with quote

Have you tried the search option of this forum?
When you have tried this option and still have problems then come back and post your compiler version.
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

PostPosted: Mon Mar 08, 2010 4:49 pm     Reply with quote

First of all thank you ckielstra.

Yes I tried, but I can't resolve the problem. My compiler version is 4.068.
I thought it might be helpful to find the problem. Here is my code.
Sorry for the length Smile

Code:
#include <16F876.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES RC                       //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define use_portb_lcd TRUE       // b portundan veri alincak
#include <lcd.c>


void main()
{
   int device=0;             //baslangic olarak 1.cihaz secili
   int device_position=0;    //baslangic olarak yuksek konum secili
   
   float voltage;         //ra1 bacagindaki analog input
   int digital;           //ra1 bacagindaki digital input
   
   int battery_digital;      //pilin doluluk oraninin dijital karsiligi,pin a2 den okunan analog voltajin digital karsiligi
   float battery_voltage;    //pin a2 den okunan analog voltaj degeri,pilin bataryasi

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL); 
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,1);
   setup_ccp1(CCP_PWM);   
   set_pwm1_duty(0);


   set_tris_a(0xff);             //a portu tamamen giris
   set_tris_b(0x00);             //b portu tamamen cikis
   set_tris_c(0xf0);             //c7 c6 c5 c4 giris c3 c2 c1 c0 cikis (cikisler pwm icin,girisler rx ve tx icin)
   lcd_init();                   //lcd yi initialize et
   printf(lcd_putc,"\fmerhaba"); // baslangic noktasini gormek icin meraba yaz
   delay_ms(750);
   
   device=read_eeprom(0);           //hangi cihazda kalindigini burasi tutucak
   //device_position=read_eeprom(1);  //hangi konumda oldugumuzu burasi tutucak
   
   
   while(1)           //sonsuz dongu,program bu dongu icinde calisacak
   
   {     
   
      //////////////////// cihaz secimi ve ona gore duty ayari ///////////////////
     
     
      if (!input(pin_a2))
      {
         delay_ms(100);            // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
         device=device+1;          // cihaz degeri 1 arttiriliyor

       if (device==10)             // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
       {
            device=0;              // cihaz 10 u gecince,cihaz degeri sifirlaniyor
       }
      }

         switch(device)
         {
     
            case 0:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M929  ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);         // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;           // cihaz degeri 1 arttiriliyor
                       if (device_position==2)            // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;       // pozisyon 2 olunca,degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(60);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/1");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(10);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/4");
                                      break;
                     }
                     
              break;
            }
     

            case 1:
            { 
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M929A ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor                 
                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(65);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/1");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(15);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/4");
                                      break;
                     }
                     
              break;
           
            }   


            case 2:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M978  ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor
                       
                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(70);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/4");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(20);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-N/A");
                                      break;
                     }
                     
              break;
 
            }
     
           
            case 3:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M978A ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor

                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(75);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/5");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(25);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/3");
                                      break;
                     }
                     
              break;
 
            }
     
     
            case 4:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M983  ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor
                       
                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(80);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/1");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(30);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/4");
                                      break;
                     }
                     
              break;
 
            }
           
           
            case 5:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M983A ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor
                       
                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(85);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-4/2");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(35);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/6");
                                      break;
                     }
                     
              break;
 
            }
           
           
            case 6:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M993  ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor
                       
                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(90);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-5/6");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(40);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-N/A");
                                      break;
                     }
                     
              break;
 
            }
           

            case 7:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M993A ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor

                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(95);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-6/1");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(45);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-2/1");
                                      break;
                     }
                     
              break;
 
            }
           

            case 8:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M995  ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor

                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(100);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-6/2");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(50);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-N/A");
                                      break;
                     }
              break;
 
            }
           
               
            case 9:
            {
               write_eeprom(0,device);
               lcd_gotoxy(1,1);
               printf(lcd_putc,"M995A ");
               
                    if (!input(pin_a4))
                    {
                        delay_ms(100);                     // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
                        device_position=device_position+1;                  // cihaz degeri 1 arttiriliyor

                       if (device_position==2)              // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
                       {
                                 device_position=0;                 // cihaz degeri sifirlaniyor
                       }
                    }
                   
                    switch(device_position)
                    {
                               case 0://write_eeprom(1,device_position);
                                      set_pwm1_duty(105);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"y-6/3");
                                      break;
                                           
                               case 1://write_eeprom(1,device_position);
                                      set_pwm1_duty(55);
                                      lcd_gotoxy(7,1);
                                      printf(lcd_putc,"d-N/A");
                                      break;
                     }
              break;
 
            }
     
         }  // switch in sonu
     
 
                 
      /////////////////pil durumu olcumu ////////////////////
                                                     
      set_adc_channel(3);           //3 nolu analog pin adc cevriminde kullanilacak
      delay_us(20);
      battery_digital=read_adc();               //analog veriyi oku,digital olarak digital degiskeninde sakla
      battery_voltage=battery_digital*0.0351563;          //     9/256=0.0351563
   
      if(battery_voltage>7.5 && battery_voltage<=9)
      {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"B:|||||");
      }
     
      else if(battery_voltage>6 && battery_voltage<=7.5)
      {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"B:|||| ");
      }
     
      else if(battery_voltage>=4 && battery_voltage<=6)
      {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"B:|||  ");
      }
     
      else if(battery_voltage>=2 && battery_voltage<=4)
      {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"B:||   ");
      }
     
      else if(battery_voltage>=0 && battery_voltage<=2)
      {
            lcd_gotoxy(1,2);
            printf(lcd_putc,"B:|    ");
      }
         
         
     
      ///////////////////// kalibrasyon ledi ile ilgili kisim //////////////////////
                 
      set_adc_channel(1);           //1 nolu analog pin adc cevriminde kullanilacak
      delay_us(20);
      digital=read_adc();               //analog veriyi oku,digital olarak digital_a1 degiskeninde sakla
      voltage=digital*0.0195313;          //     5/256=0.0195313
     
      if(voltage<2.7)         //IR ledini yakmak icin gerekli kisim
      {
         printf(lcd_putc,"\fkal!");
         set_pwm1_duty(0);
         while(1);   // sonsuz dongu,kalibrasyon ledi surekli yansin...
      }
     
      else;
         
   } //while in sonu
     
}     //main in sonu

It is very long I know. Sorry for that but the code is actually simple.
It does same thing for ten different devices with a switch statement.
Only the duty cycle values are different. My problem is that if you
examine the code you will see 20 "write_eeprom(1,device_position)"
statements, all of them inside the super loop, fragmented in switch
statement. And a device_position=read_eeprom(1) statement just above
the super loop.

All of them are commented out initially. When I remove the first 5 "//" 's,
there is no problem (%34 rom %5 ram usage), but if I add the 6th or
any one of the remainings from 6th to 21th (1 read + 20 write), I get this
error. I could not find how to resolve the problem. Actually I want to use
also receive data enable interrupt to set up initial duty cycles by serial
port, but when I add this again I had the rom problem again. Does a PIC
add subroutines just below the call statement, when it is to be written on
program memory? Or is there a problem with my compiler version
maybe?
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 08, 2010 4:59 pm     Reply with quote

See ckielstra's post about using a wrapper function with write_eeprom()
to save ROM space:
http://www.ccsinfo.com/forum/viewtopic.php?t=25555&start=16
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Mar 09, 2010 9:46 am     Reply with quote

I compiled your code, as posted, with version 3.249 with no issues. My results are:

ROM used: 2549 words (31%)
Largest free fragment is 2048
RAM used: 19 (11%) at main() level
31 (18%) worst case
Stack: 4 locations

It might be a bug with your version since this compiles fine with an older one.

Ronald
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Tue Mar 09, 2010 10:56 am     Reply with quote

Uncommenting all the write_eeprom statements, I got the same results (as the original poster) for both 3.249 and 4.104 (i.e. not enough ROM space).

Replacing the write_eeprom with the my_write_eeprom wrapper functions by ckielstra, code compile and with 24% ROM usage.
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

PostPosted: Tue Mar 09, 2010 4:51 pm     Reply with quote

I replaced all write_eeprom and read_eeprom statements with ckielstra's
functions and remove all '' // '' 's. Now I get %31 usage of rom Smile
Thank you guys. But I wonder why languer, rnielsen and I have different results.
Should not I trust ccs c program???
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 09, 2010 5:00 pm     Reply with quote

Quote:

But I wonder why languer, rnielsen and I have different results.
My compiler version is 4.068.

You are testing it with a different compiler version than rnielsen and
languer. All versions are different.
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

PostPosted: Sat Mar 13, 2010 4:50 am     Reply with quote

Thank you pcm programmer for your reply. I changed my code a little bit, but there is a problem with eeprom. I want the device to work where it was closed. I mean think about you power off the pic when the device 4 is selected, and when you power up pic it should start from device 4 not device 1.

I added some my_eeprom_read and my_eeprom_write codes but it did not work for the real network, whereas it works for a Proteus simulation. Also I managed to insert the RDA_interrupt but it did not work for the purpose. Could anyone correct my wrongs or mistakes?

By the way, I will try to tell what the whole code does. It does:
-Battery measurement
-Calibration control (only measures a pin - whether it is below 2.7 volts)
- Recognizes 10 different devices and generates 2 different duty cycles for each device, one is low duty cycle and other is high duty cycle.

There are 2 buttons. One is for choosing device (10 device exist) and other is for choosing the position, duty high or duty low positions. And all of the stuff will be displayed on a 8x2 lcd display.

I initially put this duty cycles into eeprom and program reads it. I am also supposed to change this initial duty cycles via serial port. In RDA_interrupt service routine I tried to read the data first and update it according to the character which is entered from the keyboard. But I could not make this.

So there are two problems now:
1- I could not manage eeprom thing,pic stays printf(lcd_putc,"Merhaba") part, I could not get into devices.

2- Serial port part, which is to find the data position on eeprom, read it, update it and write eeprom permanently. I mean when you power up the pic, it should read the updated duty cycles.

Here is my code. Again sorry for the length:
Quote:

#include <16F876.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define use_portb_lcd TRUE // b portundan veri alincak
#include <lcd.c> // lcd.c dosyasini programa dahil et

/////degisken tanimlamalari///////////

int device=0; //baslangic olarak 1.cihaz secili
int device_position=0; //baslangic olarak yuksek konum secili
float voltage; //ra1 bacagindaki analog input
int digital; //ra1 bacagindaki digital input
int battery_digital; //pilin doluluk oraninin dijital karsiligi,pin a2 den okunan analog voltajin digital karsiligi
float battery_voltage; //pin a2 den okunan analog voltaj degeri,pilin bataryasi
int duty_high_cycles[10]={221,100,92,115,100,106,109,98,91,85}; //yuksek konumlarin duty cycle lari
int duty_low_cycles[10]={10,30,26,2,5,16,23,21,36,31}; //dusuk konumlarin duty cycle lari
int eeprom_adress;
//char char_input='0';
//int temp;

/////fonksiyon tanimlamalari////

int8 my_read_eeprom(int8 Address) //e2prom dan veri okuyan fonksiyon
{
return read_eeprom(Address);
}

void my_write_eeprom(int8 Address, int8 Value) //e2prom a veri yazan fonksiyon
{
write_eeprom(Address, Value);
}

void calibration_check(void) //kalibrasyon ledinin yanip yanmayacagini kontrol eden fonksiyon
{
set_adc_channel(1); //1 nolu analog pin adc cevriminde kullanilacak
delay_us(20);
digital=read_adc(); //analog veriyi oku,digital olarak digital_a1 degiskeninde sakla
voltage=digital*0.0195313; // 5/256=0.0195313

if(voltage<2.7) //IR ledini yakmak icin gerekli kisim
{
printf(lcd_putc,"\fKalib!");
set_pwm1_duty(0);
while(1); // sonsuz dongu,kalibrasyon ledi surekli yansin...
}

else;
}

void battery_check(void) ///// pil durumunu olcen fonksiyon
{
set_adc_channel(3); //3 nolu analog pin adc cevriminde kullanilacak
delay_us(20);
battery_digital=read_adc(); //analog veriyi oku,digital olarak digital degiskeninde sakla
battery_voltage=battery_digital*0.0195313; // 5/256=0.0195313

if(battery_voltage>4 && battery_voltage<=5)
{
lcd_gotoxy(6,2);
printf(lcd_putc,"B:5");
}

else if(battery_voltage>3 && battery_voltage<=4)
{
lcd_gotoxy(6,2);
printf(lcd_putc,"B:4");
}

else if(battery_voltage>=2 && battery_voltage<=3)
{
lcd_gotoxy(6,2);
printf(lcd_putc,"B:3");
}

else if(battery_voltage>=1 && battery_voltage<=2)
{
lcd_gotoxy(6,2);
printf(lcd_putc,"B:2");
}

else if(battery_voltage>=0 && battery_voltage<=1)
{
lcd_gotoxy(6,2);
printf(lcd_putc,"B:1");
}
}

///////kesme service routines////////

/*
#int_RDA
void serialport_incoming_char_interrupt(void) //klavyeden rs232 uzerinden girilen karakterlerin olusturdugu kesme fonksiyonu
{
char_input=getc(); //karakteri al ve girdi degiskenine aktar
delay_ms(100); //karakteri aldiktan sonra buton arkini onlemek icin bir sure bekle

if(char_input=='1') //girilen karakter '1' ise
{
temp=duty_high_cycles[device]; //duty cycle'i temp degiskenine aktar
temp=temp+10; //temp i 5 artir
duty_high_cycles[device]=temp; //temp i array icine geri koy
printf(lcd_putc,"\fduty:%d",duty_high_cycles[device]); //lcd de duty cycle goster
delay_ms(500);
my_write_eeprom(device,duty_high_cycles[device]);
}

else if(char_input=='2') //girilen karakter '2' ise
{
temp=duty_high_cycles[device]; //duty cycle'i temp degiskenine aktar
temp=temp-10; //temp i 5 artir
duty_high_cycles[device]=temp; //temp i array icine geri koy
printf(lcd_putc,"\fduty:%d",duty_high_cycles[device]); //lcd de duty cycle goster
delay_ms(500);
my_write_eeprom(device,duty_high_cycles[device]);
}

else if(char_input=='4') //girilen karakter '4' ise
{
temp=duty_low_cycles[device]; //duty cycle'i temp degiskenine aktar
temp=temp+10; //temp i 5 artir
duty_low_cycles[device]=temp; //temp i array icine geri koy
printf(lcd_putc,"\fduty:%d",duty_low_cycles[device]); //lcd de duty cycle goster
delay_ms(500);
my_write_eeprom(device+10,duty_low_cycles[device]);
}

else if(char_input=='5') //girilen karakter '5' ise
{
temp=duty_low_cycles[device]; //duty cycle'i temp degiskenine aktar
temp=temp-10; //temp i 5 artir
duty_low_cycles[device]=temp; //temp i array icine geri koy
printf(lcd_putc,"\fduty:%d",duty_low_cycles[device]); //lcd de duty cycle goster
delay_ms(500);
my_write_eeprom(device+10,duty_low_cycles[device]);
}

else;

//char_input='0';
}*/



/////////////////////// ana program //////////////////////////////


void main()
{
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,255,1);
//enable_interrupts(INT_RDA);
//enable_interrupts(GLOBAL);
setup_ccp1(CCP_PWM);
set_pwm1_duty(0);


set_tris_a(0xff); //a portu tamamen giris
set_tris_b(0x00); //b portu tamamen cikis
set_tris_c(0xf0); //c7 c6 c5 c4 giris c3 c2 c1 c0 cikis (cikisler pwm icin,girisler rx ve tx icin)
lcd_init(); //lcd yi initialize et
lcd_gotoxy(1,1);
printf(lcd_putc,"\fMerhaba"); // baslangic noktasini gormek icin meraba yaz
delay_ms(1200);

device=my_read_eeprom(20); //hangi cihazda kalindigini burasi tutucak
device_position=my_read_eeprom(21); //hangi konumda oldugumuzu burasi tutucak


for(eeprom_adress=0;eeprom_adress<9;eeprom_adress++) //yuksek cycle degerleri 2-12. adreslere yaziliyor
my_write_eeprom(eeprom_adress,duty_high_cycles[eeprom_adress]);

for(eeprom_adress=10;eeprom_adress<20;eeprom_adress++) //dusuk cycle degerleri 12-21. adreslere yaziliyor
my_write_eeprom(eeprom_adress,duty_low_cycles[eeprom_adress]);





while(1) //sonsuz dongu,program bu dongu icinde calisacak

{

//////////////////// cihaz secimi ve ona gore duty ayari ///////////////////


if (!input(pin_a2))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device=device+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a2)); //butondan el cekilene kadar

if (device==10) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device=0; // cihaz 10 u gecince,cihaz degeri sifirlaniyor
}
}

switch(device)
{

case 0:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M929 ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // pozisyon 2 olunca,degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/1");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/4");
break;
}

break;
}


case 1:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M929A ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/1");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/4");
break;
}

break;

}


case 2:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M978 ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/4");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"DN/A");
break;
}

break;

}


case 3:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M978A ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/5");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/3");
break;
}

break;

}


case 4:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M983 ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/1");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/4");
break;
}

break;

}


case 5:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M983A ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y4/2");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/6");
break;
}

break;

}


case 6:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M993 ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y5/6");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"DN/A");
break;
}

break;

}


case 7:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M993A ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y6/1");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"D2/1");
break;
}

break;

}


case 8:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M995 ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y6/2");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"DN/A");
break;
}
break;

}


case 9:
{
my_write_eeprom(20,device);
lcd_gotoxy(1,1);
printf(lcd_putc,"M995A ");

if (!input(pin_a4))
{
delay_ms(25); // Butona basilinca meydana gelen arkin etkisini önlemek için verilen gecikme
device_position=device_position+1; // cihaz degeri 1 arttiriliyor
while(!input(pin_a4)); //butondan el cekilene kadar

if (device_position==2) // cihaz degeri test ediliyor.i degeri 10 olunca sifirlaniyor.
{
device_position=0; // cihaz degeri sifirlaniyor
}
}

switch(device_position)
{
case 0:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_high_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"Y6/3");
break;

case 1:my_write_eeprom(21,device_position);
set_pwm1_duty(duty_low_cycles[device]);
lcd_gotoxy(1,2);
printf(lcd_putc,"DN/A");
break;
}
break;

}

} // switch in sonu



/////////////////pil durumu olcumu ////////////////////

battery_check();


///////////////////// kalibrasyon ledi ile ilgili kisim //////////////////////

calibration_check();

} //while in sonu

} //main in sonu

_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group