PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 25-11-2009, 08:23 PM   #1
0903579509
Đệ tử 4 túi
 
Tham gia ngày: Mar 2007
Nơi Cư Ngụ: Da Nang
Bài gửi: 69
:
Lỗi Out of ROM

Tôi có một đề tài cho PIC6F877A viết trên CCS C, khi compile thì chỉ báo khoảng 60% ROM nhưng khi viết thêm một số Code nữa thì báo lỗi : Out of ROM, A segment or the program too large. Tôi muốn viết thêm một ít code nữa nhưng không biết làm sao, nếu tối ưu hóa Code thì mất công quá! Xin các sư huynh chỉ giáo.

Code:
#include "D:\PIC\x quang dd2.h"
#include "D:\PIC\lcd xray877.c"
// CAC HAM
// xuat du lieu ra cong
// chu y phai thao tac tren byte tuong ung cong truoc khi xuat
// thao tac set bit dung phep OR
// thao tac clr bit dung phep AND

#ROM 0x2100 = {0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,0,0x10,
               0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,0,0x9,
               0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,0,0x8,
               0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,0,0x7,
               0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6,
               0,0x5,0,0x6,0,0x6,0,0x6,0,0x6,0,0x6   }
#ROM 0x2170 = {0,0x1}               
void outputPort(byte name, byte data)
   {
   port_b = data;
   delay_us(1);
   ttPortC = (ttPortC & 0b11111000 )|name;
   port_c = ttPortC;
   addEnable = 1;
   delay_us(1);
   addEnable = 0;
   }
//----------------------------
// kiem tra ngo vao
int1 inputPort(byte name)
   {
   int8 tam;
   in1 = 1;
   in2 = 1; 
   tam = name & 0b00001000;
   port_e = name;
   if (tam) in2 = 0;
   else in1 = 0;
   return input(dataIn);
   }

//----------------------------
// phu trach viec dem xung cua mAs
#int_RTCC
void  RTCC_isr(void) 
{

}
//----------------------------

// Phu trach thoi gian ready va exposure
// moi 1ms se ngat 1 lan
// tan so 20.000.000, 1ms = 5.000
// set_timer1(60535)
// thoi gian Ready 3 giay => expCount = 3.000

#int_TIMER1
void  TIMER1_isr(void) 
{
set_timer1(60535);
soNgat1++;
if (soNgat1>=expCount)
      {
      dat = 1;
      soNgat1 = 0;
      }
   
}
//----------------------------
// phu trach field light 
// moi lan ngat la 10ms, can dat setup_timer_2(T2_DIV_BY_16,195,16)
// de co 30s can 3000 lan ngat

#int_TIMER2
void  TIMER2_isr(void) 
{

soNgat2++;
if(soNgat2 >= timeLight)
      {
      datT2 = 1;
      light = 0;
      soNgat2 = 0;
      // tat den
      //dieu khien 60Hz Inverter
      enable60Hz = 0;
      ttU16 = ttU16 & 0b11011111;
      outputPort(clockU16,ttU16);
      }
}   
//----------------------------

void banPhim(void)
{
//tim phim KV UP duoc nhan
phimNhan=input(kvUpKey);
if(!phimNhan)
   {
   delay_ms(50);
   phimNhan = input(kvUpKey);
   if (!phimNhan)
      {
      keyCode = kvUpCode;
 //  while(!phimNhan)  {phimNhan = input(kvUpKey);}
   delay_ms(150);
      }
   }
//tim phim push duoc nhan
phimNhan=input(kvDownKey);
if(!phimNhan)
   {
   delay_ms(50);
   phimNhan = input(kvDownKey);
   if (!phimNhan)
      {
      keyCode = kvDownCode;
   //   while(!phimNhan){phimNhan = input(kvDownKey);}
   delay_ms(150);
      }
   }

//tim phim inc duoc nhan
phimNhan=input(masUpKey);
if(!phimNhan)
   {
   delay_ms(50);
   phimNhan = input(masUpKey);
   if (!phimNhan)
      {
      keyCode = masUpCode;
    //  while(!phimNhan){phimNhan = input(masUpKey);}
    delay_ms(150);
      }
   }

//tim phim start duoc nhan
phimNhan=input(masDownKey);
if(!phimNhan)
   {
   delay_ms(50);
   phimNhan = input(masDownKey);
   if (!phimNhan)
      {
      keyCode = masDownCode;
     // while(!phimNhan){phimNhan = input(masDownKey);}
     delay_ms(150);
      }
   }
// tim phim field light duoc nhan
phimNhan=input(lightIn);
if(!phimNhan)
   {
   delay_ms(100);
   phimNhan = input(lightIn);
   if (!phimNhan)
      {
      keyCode = lightInCode;
      while(!phimNhan){phimNhan = input(lightIn);}
      }
   }
}
//-----------------------------------
//neu phim ready nhan thi rdyKey = 1, neu khong nhan thi rdyKey = 0;
//----------------------------------

void ktReady(void)
   {
   int1 readyKey;
   rdyKey = 0;
   readyKey = input(readyIn);
   if (readyKey) goto exitKtReady;
   delay_ms(10);
   readyKey = input(readyIn);
   if (readyKey) goto exitKtReady;
   rdyKey =1;   
   exitKtReady: 
   delay_us(1);
   }
//--------------------------   
//neu phim exposure nhan thi expKey = 1, neu khong nhan thi expKey = 0;   

void ktExposure(void)
   {
   int1 exposureKey;
   expKey = 0;
   exposureKey = input(exposureIn);
   if (exposureKey) goto exitKtExposure;
   delay_ms(10);
   exposureKey = input(ExposureIn);
   if (exposureKey) goto exitKtExposure;
   expKey =1;   
   exitKtExposure: 
   delay_us(1);
   }
//--------------------------------
// Kiem tra 60Hz inverter OK
void ktInv60OK(void)
   {
   loi = 0;
   dataInput = inputPort(inv60OK);
   if(dataInput)  // bao loi 
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("INVERTER 60 OK ERROR !");
      }
   }
//--------------------------------
 // Kiem tra Rotor Interlock
 void ktInterlock(void)
   {
   loi = 0;
   dataInput = inputPort(rotorInterlock);
   if(dataInput)  // bao loi 
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("ROTOR INT-LOCK ERROR !");
      }
   }
//--------------------------------
// Kiem tra Filament Short, muc 1 la OK
void ktFilShort(void)
   {
   loi = 0;
   dataInput = inputPort(filShort);
   if(dataInput)  // bao loi 
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("FILAMENT ERROR !");
      }
   }
//--------------------------------
// Kiem tra Inverter Ready
void ktInvReady(void)
   {
   loi = 0;
   dataInput = inputport(invReady);
   if(dataInput)  // bao loi 
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("INVERTER RDY ERROR !");
      }
   }
//--------------------------------
// kiem tra taps
void ktTaps(void)
   {
   int8 bienTap = 0b00000110;
   loi = 0;
   // Kiem tra Taps
   dataInput = inputPort(tap6);
   bienTap = (bienTap |dataInput) <<1;
   dataInput = inputPort(tap5);
   bienTap = (bienTap |dataInput) <<1;
   dataInput = inputPort(tap4);
   bienTap = (bienTap |dataInput) <<1;
   dataInput = inputPort(tap3);
   bienTap = (bienTap |dataInput) <<1;
   dataInput = inputPort(tap2);
   bienTap = (bienTap |dataInput) <<1;
   dataInput = inputPort(tap1);
   bienTap = bienTap |dataInput;
   bienTap = ~bienTap;
   if (bienTap != tapString[kvPointer])
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("TAPS ERROR !");
      }
   }
//--------------------------------
 // Kiem tra Inverter OK
 void ktInvOK(void)
   {
   loi = 0;
   dataInput = inputport(invOK);
   if(dataInput)  // bao loi 
      {
      loi = 1;
      clear_line2();
      lcd_gotoxy(1,2);
      lcd_putc("INVERTER OK ERROR !");
      }
   }
//--------------------------------

int16 decHex(int16 data)
   {
   int16 tam1, tam2;
   tam1 = data;
   tam1 = tam1 & 0xf;
   tam2 = tam1;
   tam1 = data;
   tam1 = (tam1>>4) & 0xf;
   tam2 = tam2 + tam1 * 10;
   tam1 = data;
   tam1 = (tam1 >>8) & 0xf;
   tam2 = tam2 + tam1 * 100;
   tam1 = data;
   tam1 = (tam1 >>12) & 0xf;
   tam2 = tam2 + tam1 * 1000;
   return tam2;
   }
   //---------------------------
   // lay gia tri tai cac dia chi KV eeprom dac de dieu khien mA o moi muc KV
void dacKV(int8 address)
   {
   int8 dataL, dataH;
   int16 tam16;
   daWr = 1;
   dataL = read_eeprom((address - 50)*2);
   dataH = read_eeprom((address - 50)*2 +1);
   // chuyen doi decimal hexa
   tam16 = dataH ;
   tam16 = (tam16 << 8) | dataL;
   tam16 = decHex(tam16);
   dataL = tam16;
   dataH = tam16 >>8;
   
   port_b = dataH;
   delay_us(1);
   port_c = daMaHigh;
   addEnable = 1;
   delay_us(1);
   daWr = 0;
   delay_us(1);
   daWr = 1;
   addEnable = 0;
   
   port_b = dataL;
   delay_us(1);
   port_c = daMaLow;
   addEnable = 1;
   delay_us(1);
   daWr = 0;
   delay_us(1);
   daWr = 1;
   addEnable = 0;
 
    }
//--------------------------
// lay gia tri tai dia chi eeprom 112 va 113 dac dieu khien mA
void dacMA(void)
   {
   int8 dataL, dataH;
   int16 tam16;
   dataL = read_eeprom(112);
   dataH = read_eeprom(113);
   // chuyen doi decimal hexa
   tam16 = dataH ;
   tam16 = (tam16 << 8) | dataL;
   tam16 = decHex(tam16);
   dataL = tam16;
   dataH = tam16 >>8;
   
   port_b = dataH;
   delay_us(1);
   port_c = daKvHigh;
   addEnable = 1;
   delay_us(1);
   daWr = 0;
   delay_us(1);
   daWr = 1;
   addEnable = 0;
   
   port_b = dataL;
   delay_us(1);
   port_c = daKvLow;
   addEnable = 1;
   delay_us(1);
   daWr = 0;
   delay_us(1);
   daWr = 1;
   addEnable = 0;
  
   }
//--------------------------
int16 daySo(int8 x, int8 y, int16 data)
   {
   data = data <<4;
   lcd_displayD(x,y,data);
   return data;
   }
//--------------------------
int16 tangSo(int8 x, int8 y, int16 data)
   {
   int8 tam8;
   tam8 = data & 0x000f;
   tam8++;
   if (tam8 ==10) tam8 = 0;
   data = (data & 0xfff0) | tam8 ;
   lcd_displayD(x,y,data);
   return data;
   }
//--------------------------
int8 adc(int8 address)
   {
   output_e(address);
   delay_ms(5);
   return read_adc();
   }
//------------------   
void testDienAp(void)
   {
   adcValue = adc(duong15)/12;
      if (adcValue < 10)
         {
         lcd_putc("\f");
         lcd_gotoxy(1,1);
         lcd_putc("    +15V LOST !");
         lcd_gotoxy(1,2);
         lcd_putc("+15V:");
         lcd_gotoxy(6,2);
         printf(lcd_putc,"%u",adcValue);
         while(keyCode != lightInCode)
            {
            banPhim();
            }
            keyCode = 0;
         }
      
      adcValue = adc(am15)/7;
      if (adcValue < 10)
         {
         lcd_putc("\f");
         lcd_gotoxy(1,1);
         lcd_putc("    -15V LOST !");
         lcd_gotoxy(1,2);
         lcd_putc("-15V:");
         lcd_gotoxy(6,2);
         printf(lcd_putc,"%u",adcValue);
         while(keyCode != lightInCode)
            {
            banPhim();
            }
            keyCode = 0;
         }
      
      adcValue = adc(duong24)/6;
      if (adcValue < 15)
         {
         lcd_putc("\f");
         lcd_gotoxy(1,1);
         lcd_putc("    +24V LOST !");
         lcd_gotoxy(1,2);
         lcd_putc("+24V:");
         lcd_gotoxy(6,2);
         printf(lcd_putc,"%u",adcValue);
         while(keyCode != lightInCode)
            {
            banPhim();
            }
            keyCode = 0;
         }
      
      adcValue = adc(duong114);
      if (adcValue < 104)
         {
         lcd_putc("\f");
         lcd_gotoxy(1,1);
         lcd_putc("  BATTERY LOST !");
         lcd_gotoxy(1,2);
         lcd_putc("BATTERY:");
         lcd_gotoxy(9,2);
         printf(lcd_putc,"%u",adcValue);
         while(keyCode != lightInCode)
            {
            banPhim();
            }
            keyCode = 0;
         }
      
   }
//------------------

void testADC(void)
   {
   lcd_putc("\f");
   lcd_gotoxy(1,1);
          // 12345678901234567890
   lcd_putc("+V:    -V:    24:   ");
   lcd_gotoxy(1,2);
   lcd_putc("114:    V:    mA:   ");
   while(keyCode != lightInCode)
      {
      // kiem tra dien luoi
      if(inputPort(lineOn))  relayCharge = 0;
      else   relayCharge = 1;
      adcValue = adc(duong15)/12;
      lcd_gotoxy(4,1);
      printf(lcd_putc,"%u",adcValue);
      
      adcValue = adc(am15)/7;
      lcd_gotoxy(11,1);
      printf(lcd_putc,"%u",adcValue);
      
      adcValue = adc(duong24)/6;
      lcd_gotoxy(18,1);
      printf(lcd_putc,"%u",adcValue);
      
      adcValue = adc(duong114);
      lcd_gotoxy(5,2);
      printf(lcd_putc,"%u",adcValue);
      
      adcValue = adc(kvFb);
      lcd_gotoxy(11,2);
      printf(lcd_putc,"%u",adcValue);
      
      adcValue = adc(maFb);
      lcd_gotoxy(18,2);
      printf(lcd_putc,"%u",adcValue);
      
      delay_ms(100);
      banPhim();
      }
      keyCode = 0;
   }     

//--------------------------- 
// Doan code nhap du lieu cho eeprom
// phim kvUp tang kV
// phims kvDown giam kV
// phim masUp tang digit 
// phim masDown dich digit qua trai
// phim field light la enter
// giam het hoac tang het kV se den mA
// so duoc nhap vao eeprom la so decimal gom 4 digit toi da len den 4095
// du lieu nay khi lay ra se doi thanh hexa

void calibration(void)
   {
   int8 tam8;
   int1 kvMark =1;
   kv = 50;
   lcd_putc("\f");
   lcd_gotoxy(1,1);
   lcd_putc("CALIBRATION mA:");
   lcd_gotoxy(1,2);
   lcd_putc("KV:     X:");
   lcd_displayH(4,2,kV);
   giaTriKV = read_eeprom((kV - 50)*2+1)<<8;
   tam8 = read_eeprom((kv - 50)*2);
   giaTriKV = giaTriKV |tam8;
   lcd_displayD(11,2,giaTriKV);
   giaTriMA = read_eeprom(113)<<8;
   tam8 = read_eeprom(112);
   giaTriMA = giaTriMA |tam8;
   lcd_displayD(16,1,giaTriMA);
   while (1)
      {
      banPhim();
      switch (keyCode)
         {
         case kvUpCode:
            {
            keyCode = 0;
            kV++;
            if (kv >= 107) kv =50;
            if (kv < 106)
            {
            kvMark =1;
            lcd_displayH(4,2,kV);
            giaTriKV = read_eeprom((kV - 50)*2+1)<<8;
            tam8 = read_eeprom((kV - 50)*2);
            giaTriKV = giaTriKV |tam8;
            lcd_displayD(11,2,giaTriKV);
            }
            else
               {
               kvMark =0;
               lcd_gotoxy(4,2);
               lcd_putc("    ");
               giaTriMA = read_eeprom(113)<<8;
               tam8 = read_eeprom(112);
               giaTriMA = giaTriMA |tam8;
               lcd_displayD(16,1,giaTriMA);
                              
               }
            break;
            }
         case kvDownCode:
            {
            keyCode = 0;
            kV--;
            if (kV <=48) kv = 105;
            if (kv >= 50 )
            {
            
            kvMark =1;
            lcd_displayH(4,2,kV);
            giaTriKV = read_eeprom((kV - 50)*2+1)<<8;
            tam8 = read_eeprom((kV - 50)*2);
            giaTriKV = giaTriKV |tam8;
            lcd_displayD(11,2,giaTriKV);
            }
            else 
               {
               kvMark = 0;
               lcd_gotoxy(4,2);
               lcd_putc("    ");
               giaTriMA = read_eeprom(113)<<8;
               tam8 = read_eeprom(112);
               giaTriMA = giaTriMA |tam8;
               lcd_displayD(16,1,giaTriMA);
               }
            break;
            }
         case masUpCode:
            {
            keyCode = 0;
            if (kvMark)  giaTriKV = tangSo(11,2,giaTriKV);
            else         giaTriMA = tangSo(16,1,giaTriMA);
            break;
            }
         case masDownCode:
            {
            keyCode = 0;
            if (kvMark) giaTriKV = daySo(11,2,giaTriKV);
            else        giaTriMA = daySo(16,1,giaTriMA);
            break;
            }
         case lightInCode:
            {
            keyCode = 0;
            if (kvMark)
               {
               tam8 = giaTriKv;
               write_eeprom((kv-50)*2,tam8);
               tam8 = giaTriKV >>8;
               write_eeprom((kv-50)*2+1,tam8);
               }
            else
               {
               tam8 = giaTriMA;
               write_eeprom(112,tam8);
               tam8 = giaTriMA >>8;
               write_eeprom(113,tam8);
               }
            
            
            }
         }
         // thuc hien viec xuat du lieu ra DAC
      ktReady();
      if (rdyKey) { rdyKey = 0; dacMA();}
      ktExposure();
      if (expKey) { expKey = 0; dacKV(kv);}
      delay_ms(50);
      }
   }
  
   //--------------------------
void testInPut(void)
   {
   lcd_putc("\f");
   while(1)
   {
   // kiem tra dien luoi
   if(inputPort(lineOn))  relayCharge = 0;
   else   relayCharge = 1;
   

//-----------------------------
// Đoạn này phải bỏ bớt mới compile được
/*   lcd_gotoxy(1,1);
   if (inputPort(0))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
      
   lcd_gotoxy(3,1);
   if (inputPort(1))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
      
   lcd_gotoxy(5,1);
   if (inputPort(2))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
      
   lcd_gotoxy(7,1);
   if (inputPort(3))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(9,1);
   if (inputPort(4))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
      
   lcd_gotoxy(11,1);
   if (inputPort(5))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(13,1);
   if (inputPort(6))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
    lcd_gotoxy(15,1);
   if (inputPort(7))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
      
   lcd_gotoxy(1,2);
   if (inputPort(8))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(3,2);
   if (inputPort(9))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(5,2);
   if (inputPort(10))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(7,2);
   if (inputPort(11))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(9,2);
   if (inputPort(12))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(11,2);
   if (inputPort(13))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(13,2);
   if (inputPort(14))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }
   lcd_gotoxy(15,2);
   if (inputPort(15))
      {
      lcd_putc("1");
      }
    else
      {
      lcd_putc("0");
      }           */

//--------------------
   delay_ms(200);
   banPhim();
   if (keyCode ==masUpCode)
      {
      keyCode = 0;
      testADC();
      lcd_putc("\f");
      }                 
   if (keyCode ==kvUpCode)
      {
      keyCode = 0;
      calibration();
      } 
   }
   }

//--------------------------
void kiemTraCharge(void)
   {
   adcValue = adc(duong114);
   if (adcValue > 120) // Tat mach Charge
      {
      relayCharge = 0;
      dkCharge = 1; // Da charge
      }
   if (adcValue <105)   // bat mach Charge
      {
      relayCharge = 1;
      dkCharge =0;   // chua charge
      }
   if ((adcValue >107) & (adcValue <120))
      {
      if(dkCharge) relayCharge = 0;
      else relayCharge =1;
      }
   
   }
//-------------------------
void main()
{
int1 a;
int8 thu;
int8 tam8;


   setup_adc_ports(an0);
   setup_adc(ADC_CLOCK_DIV_32);
   //setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0( RTCC_EXT_L_TO_H );
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DIV_BY_16,195,16); // ngat 10ms
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_ccp1 (CCP_OFF)  ;  
   setup_ccp2 (CCP_OFF) ;   
   set_adc_channel(0);

//   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);

   // TODO: USER CODE!!
   set_timer1(60535);
   kv = 50;
   mas = 10;
   expTime = 100;
   keyCode = 0;
   ttTaps = 0;
   loi = 0;
   
set_tris_a(0b1110001);
set_tris_b(0);
set_tris_c(0b01110000);
set_tris_d(0b00001111);
set_tris_e(0);
port_d = 0b01101111;
addEnable = 0;
relayCharge = 0;
daWr = 1;
dacKV(kV);
dacMA();
// doan nay truy cap Taps
outputPort(clockU16,0);
outputPort(taps,ttTaps);
enable60Hz = 0;
lcd_init();

//Phan mem calibration
banPhim();
if (keyCode == lightInCode) //calibration();
   {
   keyCode = 0;
   testInput(); 
   }
//Phan mem chinh   
   
lcd_putc("\f");
LCD_GOTOXY(1,1);
  lcd_putc("MOBILE X RAY DEVICE ");
lcd_putc("\n  GENERAL ELECTRIC");
delay_ms(100);
lcd_putc("\f");
LCD_GOTOXY(1,1);
         // 01234567890123456789
  lcd_putc("   SEFLTESTING... ");
lcd_putc("\n   PLEASE WAIT !");
testDienAp();
delay_ms(100);
lcd_putc("\f");
LCD_GOTOXY(1,1);
         // 01234567890123456789
  lcd_putc("     SYSTEM OK ");
lcd_putc("\n   READY FOR UES !");
delay_ms(100);
lcd_putc("\f");
LCD_GOTOXY(1,1);
         // 01234567890123456789
  lcd_putc("GE MOBIL XRAY SYSTEM");
lcd_putc("\nkV:    mAs:    V:");
lcd_displayH(4,2,kv);
lcd_displayH(12,2,mas);
expTime = mas*10;
//lcd_displayH(18,2,expTime);

while (1)
   {
   delay_ms(100);
   // kiem tra dien luoi
   if(inputPort(lineOn))  relayCharge = 0;
   else   
      {
       //Kiem tra dien apCharge
      kiemTraCharge();
      }
   // hien thi dien ap battery
   adcValue = adc(duong114);
   lcd_gotoxy(18,2);
   printf(lcd_putc,"%u",adcValue);
    //kiem tra phim den diagphram
   if (!inputPort(fieldLight))
   {
      if (!light)
      {
      // Bat den field light 30 giay
      ttTaps = 0;
      outputPort(taps,ttTaps);
      set_timer2(0);
      light = 1;
      datT2 = 0;
      soNgat2 = 0 ;
      enable_interrupts(int_timer2);
      // dieu khien bat den 
      // cho phep 60Hz enable (pin D4)
      // dong relay 60Hz inverter
      enable60Hz = 1;
      ttU16 = ttU16 |0b00100000;
      outputPort(clockU16,ttU16);
      }
      else
         {
         datT2 = 0;
         soNgat2 = 0;
         light = 0;
      disable_interrupts(int_timer2);
      // dieu khien bat den 
      // cho phep 60Hz enable (pin D4)
      // dong relay 60Hz inverter
      enable60Hz = 0;
      ttU16 = ttU16 & 0b11011111; 
      outputPort(clockU16,ttU16);
         }
      }
   while (!inputPort(fieldLight)){}
    
   banPhim();
   switch (keyCode)
   {
   case kvUpCode:
      {
      if (kv<105)
      {
      kv++;
      lcd_displayH(4,2,kv);
      kvPointer = (kv-50)/2;
      dacKV(kV);
      
      
   //   ttTaps =  tapString[kvPointer];
      }
      break;
      }
   case kvDownCode:
      {
      if (kv>50)
      {
      kv-- ;
      lcd_displayH(4,2,kv);
      kvPointer = (kv-50)/2;
      dacKV(kV);
      
      
 //     ttTaps = tapString[kvPointer];
      }
      break;
      }
   case masUpCode:
      {
      if (mas<99)
      {
      mas++;
      lcd_displayH(12,2,mas);
      expTime = mas*10;
      //lcd_displayH(18,2,expTime);
      }
      break;
      }
   case masDownCode:
      {
      if (mas>1)
      {
      mas--;
      lcd_displayH(12,2,mas);      
      expTime = mas*10;
      //lcd_displayH(18,2,expTime);
      }
      break;
      }
   case lightInCode:
      {
      if (!light)
      {
      // Bat den field light 30 giay
      ttTaps = 0;
      outputPort(taps,ttTaps);
      set_timer2(0);
      light = 1;
      datT2 = 0;
      soNgat2 = 0 ;
      enable_interrupts(int_timer2);
      // dieu khien bat den 
      // cho phep 60Hz enable (pin D4)
      // dong relay 60Hz inverter
      enable60Hz = 1;
      ttU16 = ttU16 |0b00100000;
      outputPort(clockU16,ttU16);
      }
      else
         {
         datT2 = 0;
         soNgat2 = 0;
         light = 0;
      disable_interrupts(int_timer2);
      // dieu khien bat den 
      // cho phep 60Hz enable (pin D4)
      // dong relay 60Hz inverter
      enable60Hz = 0;
      ttU16 = ttU16 & 0b11011111; 
      outputPort(clockU16,ttU16);
         }
      }
   }
   keyCode = 0;


// do bit datT2 de tat field light
if ( datT2)
   {
   disable_interrupts(int_timer2);
   datT2 = 0;
   soNgat2 = 0;
   light = 0;
   enable60Hz = 0;
   ttU16 = ttU16 & 0b11011111; 
   outputPort(clockU16,ttU16);
   }
    
   // Qui trinh chup
  
   ktReady();
   if (rdyKey)    // phim ready nhan
      {
      set_timer0(0);
      // tat field light
      disable_interrupts(int_timer2);
      datT2 = 0;
      soNgat2 = 0;
      light = 0;
      enable60Hz = 0;
      ttU16 = ttU16 & 0b11011111; 
      outputPort(clockU16,ttU16);
      // thuc hien chuan bi chup
       //set ready timer
      dat = 0;
      soNgat1 = 0;
      expCount = 2000; // thoi gian ready = 2s la 2000 
      set_timer1(60535);
      enable_interrupts(INT_TIMER1);
       // Dieu khien 60Hz Inverter
      enable60Hz = 1; // cho phep 60Hz enable
      ttU16 = ttU16 |0b00100000; // set bit 60Hz Inv Relay
      outputPort(clockU16,ttU16);
      
      ttTaps = ttTaps | 0b01000000; // set  Rotor select
      outputPort(taps,ttTaps);
      delay_ms(100);
       // kiem tra cac dieu kien cua 60Hz Inverter
      ktInv60OK();
      if(loi) goto eXitExp;
       // Dieu khien Fil/KV
        //nhap gia tri vao DA mA
      dacMA();
       // nhap gia tri vao DA kV
      dacKV(kV);
       ttU16 = ttU16 | 0b00010001; // cho phep 16KHz va 2KHz enable
       outputPort(clockU16,ttU16);
        
      delay_ms(300);
      // kiem tra filament short
      ktFilShort();
      if (loi) goto exitExp;    
      //cho du thoi gian
      cho:
      ktReady();        // kiem tra phim ready con nhan khong
      if (!rdyKey)  goto exitExp;
      if (!dat) goto cho;
      dat = 0; 
      // da du thoi gian Ready
      disable_interrupts(INT_TIMER1);
       // kiem tra inverter Ready
      ktInvReady();
      if(loi) goto exitExp;
      // kiem tra rotor
      
      ktInterlock();
      if(loi) goto exitExp;
      // cho phep chup
      ttTaps = ttTaps | 0b10000000; // set Safety Contactor 
      outputPort(taps,ttTaps);
      delay_ms(100);
      // Dong cac Taps
      kvPointer = (kv-50)/2;
      ttTaps = (ttTaps & 0b11000000) | tapString[kvPointer];
      outputPort(taps,ttTaps);
      delay_ms(300);
      // kiem tra cac Taps
      ktTaps();
      if (loi) goto exitExp;
      // da day du cac dieu kien de chup
      // cho phim exposure
      choExp:
      ktReady();
      if (!rdyKey)   goto exitExp;
      ktExposure();
      if(!expKey) goto choExp;
      
      // da nhan phim Exposure
      expCount = expTime;
      soNgat1 = 0;
      set_timer1(60535);
      enable_interrupts(INT_TIMER1);
      dat = 0;
      // dieu khien chup
      ttU16 = ttU16 | 0b01000000; // bat Xray Lamp
      outputPort(clockU16,ttU16);
      ttU16 = ttU16 | 0b00000100; //cho phep 1KHz enable
      outputPort(clockU16,ttU16);
      delay_ms(1);
      
      ttU16 = ttU16 | 0b00000010; // kich xung exposure, xung kich co thoi gian suot thoi gian phat tia
      outputPort(clockU16,ttU16);
     
      
      choKthuc:
      // kiem tra UV
      
      // kiem tra ready key
      
      // kiem tra exposure key
      
      // kiem tra bit dat
      ktReady();
      if (!rdyKey)   goto exitExp;
      ktExposure();
      if(!expKey) goto exitExp;
      if(!dat)    goto choKThuc;
      masCounter = get_timer0()/10;    
      
      exitExp:
      
      disable_interrupts(INT_TIMER1);
      ttU16 = ttU16 & 0b11111101; // huy kich xung exposure 
       // phat xung expStop
      ttU16 = ttU16 |  0b00001000;
      outputPort(clockU16,ttU16);
      delay_ms(100);
      ttU16 = ttU16 & 0b11110111;
      outputPort(clockU16,ttU16);
      ttU16 = ttU16 & 0b10111111; // tat Xray Lamp
      outputPort(clockU16,ttU16);
       ttU16 = ttU16 & 0b11111011; //bat hoat 1KHz enable
      outputPort(clockU16,ttU16);
       // Dieu khien 60Hz Inverter
      enable60Hz = 0; // bat hoat 60Hz enable
       ttU16 = ttU16 & 0b11011111 ; // clear bit 60Hz Inv Relay
      outputPort(clockU16,ttU16);
      ttTaps = 0;                // clr Safety Contactor Rotor select va taps
      outputPort(taps,ttTaps);
       // kiem tra cac dieu kien cua 60Hz Inverter
       // Dieu khien Fil/KV
       ttU16 = ttU16 & 0b11101110; // bat hoat 16KHz va 2KHz enable
       outputPort(clockU16,ttU16);
      
      // bat loa bao ket thuc khi da chup xong
      if (dat)
         {
         dat = 0;
         ttU16 = ttU16 | 0b10000000;
         outputPort(clockU16,ttU16);
         lcd_putc("\f");      // bao hieu man hinh
         LCD_GOTOXY(1,1);
         lcd_putc("X RAY GENERATED OK !");
         lcd_gotoxy(1,20);
         lcd_putc("mAs : ");
         printf(lcd_putc,"%u",masCounter);
         delay_ms(1000);
         ttU16 = ttU16 & 0b01111111;
         outputPort(clockU16,ttU16);
         
         }
      // neu loi thi nhan phim Field Light    se thoat
      if (loi)
         {
         lap:
         banPhim();
         if (keyCode != lightInCode) goto lap;
         keyCode = 0;
         loi = 0;
         lcd_putc("\f");
         LCD_GOTOXY(1,1);
         // 01234567890123456789
         lcd_putc("GE MOBIL XRAY SYSTEM");
         lcd_putc("\nkV:    mAs:    V:");
         lcd_displayH(4,2,kv);
         lcd_displayH(12,2,mas);
         //lcd_displayH(18,2,expTime);
         }
      // cho nha phim ready va exposure
      choNhaReady:
      ktReady();
      if (rdyKey)   goto choNhaReady;
      delay_ms(1000);
      lcd_putc("\f");
      LCD_GOTOXY(1,1);
         // 01234567890123456789
         lcd_putc("GE MOBIL XRAY SYSTEM");
         lcd_putc("\nkV:    mAs:    V:");
         lcd_displayH(4,2,kv);
         lcd_displayH(12,2,mas);
         //lcd_displayH(18,2,expTime);
   }  

}

}
Các file đính kèm:
File Kèm Theo
File Type: zip pic877.zip (8.7 KB, 15 lần tải)

thay đổi nội dung bởi: namqn, 25-11-2009 lúc 09:13 PM. Lý do: định dạng code
0903579509 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 25-11-2009, 09:17 PM   #2
namqn
Trưởng lão PIC bang
 
Tham gia ngày: Feb 2006
Nơi Cư Ngụ: Tp. HCM, Việt Nam
Bài gửi: 3,025
:
Send a message via Yahoo to namqn
Giữa mất công và không được gì cả, bạn chọn cái nào?

Đề tài này của bạn dùng cho mục đích học tập hay kinh doanh?

Thân,
__________________
Biển học mênh mông, sức người có hạn.

Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau:
http://www.picvietnam.com/forum/showthread.php?t=1263
namqn vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 25-11-2009, 09:34 PM   #3
cskiller
Đệ tử 4 túi
 
Tham gia ngày: Aug 2008
Bài gửi: 89
:
Trích:
Nguyên văn bởi 0903579509 View Post
Tôi có một đề tài cho PIC6F877A viết trên CCS C, khi compile thì chỉ báo khoảng 60% ROM nhưng khi viết thêm một số Code nữa thì báo lỗi : Out of ROM, A segment or the program too large. Tôi muốn viết thêm một ít code nữa nhưng không biết làm sao, nếu tối ưu hóa Code thì mất công quá! Xin các sư huynh chỉ giáo.
Theo kinh nghiệm viết code cho PIC16 không nên viết quá nhiều cho 1 hàm, thay vào đó chia nhỏ ra các hàm nhỏ hơn và gọi các hàm nhỏ này. Cụ thể bạn nên thay thế đoạn code hàm main trong while(1) bởi các hàm nhỏ hơn chứa code đó.

Regards
__________________
Quang báo RG/RGB 6/8/12/16 bits màu
Phone No: 0905.034.086
Email: lmquyen@gmail.com
cskiller vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 25-11-2009, 10:11 PM   #4
picpen
Đệ tử 5 túi
 
picpen's Avatar
 
Tham gia ngày: Jun 2008
Bài gửi: 112
:
Trong CCS không cho phép viết một chương trình con quá lớn . Khi 1 chương trình con quá lớn sẽ bị báo lỗi như của bạn . Bạn nên chia nhỏ các chương trình con ra vừa rễ kiểm soát vừa ko bị lỗi
__________________
** xin hãy cho tôi là tượng đá
** Để muôn đời không nhớ thương ai ..!!
picpen vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 26-11-2009, 07:42 PM   #5
0903579509
Đệ tử 4 túi
 
Tham gia ngày: Mar 2007
Nơi Cư Ngụ: Da Nang
Bài gửi: 69
:
Trong CCS C, đoạn Code sau khi compile, ta mở file LST ra xem sẽ thấy code được sắp xếp theo các địa chỉ lung tung, không theo một trật tự nào cả. Có thể đó là lý do gây lỗi out of ROM. Không biết làm thế nào để CCS C sắp xếp code có trật tự hơn?

Đây là một đoạn code có địa chỉ mất trật tự:

....................
.................... //Phan mem calibration
.................... banPhim();
10B7: BCF 0A.4
10B8: CALL 499
10B9: BSF 0A.4
.................... if (keyCode == lightInCode) //calibration();
10BA: MOVF 2A,W
10BB: SUBLW 05
10BC: BTFSS 03.2
10BD: GOTO 1DE
.................... {
.................... keyCode = 0;
10BE: CLRF 2A
.................... testInput();
.................... }
.................... //Phan mem chinh
....................
.................... lcd_putc("\f");
* <- Không hiểu tại sao ở đây có dấu này và một đoạn địa chỉ bị mất
11DE: CLRF 48
11DF: MOVF 48,W
11E0: BCF 0A.4
11E1: CALL 0F0
11E2: BSF 0A.4
11E3: IORLW 00
11E4: BTFSC 03.2
11E5: GOTO 1EC
11E6: INCF 48,F
11E7: MOVWF 58
11E8: BCF 0A.4
11E9: CALL 530
11EA: BSF 0A.4
11EB: GOTO 1DF
.................... LCD_GOTOXY(1,1);
0903579509 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-12-2010, 07:04 PM   #6
thienanh0000
Nhập môn đệ tử
 
Tham gia ngày: Oct 2009
Bài gửi: 7
:
Out of rom

Các bác xem giúp . Code trong chương trình test led thôi , hiện tại CCS dịch báo 30% , mà viết thêm bất kỳ câu lệnh , hoặc chương trình con nào vào chương trình chính , dịch lập tức được thông báo lỗi " out of rom ". Các bác xem có cách nào khắc phục để viết thêm code không .
Thanks !
File Kèm Theo
File Type: rar test led 16f57.rar (14.7 KB, 6 lần tải)

thay đổi nội dung bởi: thienanh0000, 14-12-2010 lúc 07:06 PM. Lý do: chèn file
thienanh0000 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 15-12-2010, 08:57 AM   #7
herrtien
Banned
 
Tham gia ngày: Nov 2006
Bài gửi: 107
:
Bạn sử dụng lệnh này sẽ có hiệu quả: #separate
Tìm hiểu cách sử dụng trong tài liệu của CCS.
herrtien vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 09-05-2012, 06:15 PM   #8
bubu250591
Nhập môn đệ tử
 
Tham gia ngày: Feb 2012
Bài gửi: 1
:
chào mọi người.
mình cũng vừa làm bài tập lớn về đề tài quạt thông minh dùng PIC16F877A và cũng bị lỗi như vậy! & mình cũng đã sửa ok! lỗi đó là do tràn bộ nhớ ROM
bạn kích vào compile -> chọn Call Tree -> sẽ có 1 file bên cạnh chương trình của bạn tên là "file_name.tre" (file_name là tên chương trình bạn đg viết).
bạn vào chọn cái file_name.tre đó thì nó sẽ cho bạn biết dung lượng ROM tiêu tốn trong mỗi cây tại cột ROM(do nó hoạt động theo kiểu cây, gần giống như theo kiểu cây-> lá -> cành mình mới tìm hiểu nên ngôn từ có j không chính xác thì mọi người thông cảm nhé )
như của mình vừa viết thì nó gồm :
MAIN: 1992
ISR_timer0: 519
ISR_timer1: 579
lúc trước khi bị lỗi thì là
MAIN: 2077
ISR_timer0: 519
ISR_timer1: 540
và mình ngộ ra 1 điều cái nào mà quá 2048 là bị lỗi do mình cũng đã thử thay đổi 1 chút và ở file *.tre ấy MAIN có lên đến 2047 vẫn ko lỗi mà cứ quá 2048 là lỗi (hình như giới hạn ROM CCS nó chỉ cho 2kb thôi thì phải)

hy vọng cái này sẽ giúp cho những gặp phải lỗi như thế này thì có thể biết cách sửa !
bubu250591 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 02:49 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam