Ðề tài: mạch buck-boost
View Single Post
Old 11-04-2009, 09:20 AM   #13
tronghung101
Nhập môn đệ tử
 
Tham gia ngày: Mar 2009
Bài gửi: 5
:
em viết chương trình như thế này với kết nối LCD và ấn phím. nhưng sao mô phỏng không được, các anh chỉ cho em với!!
Code:
#include <16f877A.h>
#include <def_877a.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, LVP, NOCPD, NOWRT
#use delay(clock=10000000)
#use Fast_IO(C)

#include <lcd_lib_4bit.c>

#priority INT_EXT,int_timer1
#bit C0=portC.0
#bit C1=portC.1
#bit C7=portC.7
int8 Vref;
int16 value,duty;
int8 tempt,disp;
int8 high,low;

#INT_EXT
void ngat_ngoai()
{
   if(C0==0)
      {
          Vref=5;
          tempt=26;// gia tri ADC ung voi dau ra 5V la 26.
          duty=375;
          //chon chu ki lam viec ban dau la 0.15ms=0.1us*4*duty
      }
   if(C1==0)
      { 
         Vref=12;
         tempt=63;
         //gia tri ADc la 63
         duty=625;
         //chon chu ki lam viec ban dau la 0.25ms=0.1us*4*duty
      }
   if(C7==0)
      { 
        Vref=24 ;
        tempt=126;
        duty=825;
        //chon chu ki lam viec luc dau la 0.33ms=0.1us*4*duty;
        
      }
}
#INT_TIMER1
void ngat_timer1()
{ 
  disable_interrupts(int_timer1);
  setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
  set_timer1(64911); 
  value=read_adc();
  enable_interrupts(int_timer1);
}
Void convert_bcd(int8 x)
{
   high=x/10 + 0x30;
   low=x/10+ 0x30;
}
Void LCD()
{
  delay_ms(10);
  disp=(float)(value*5)/255;
  disp=disp*10;
  convert_bcd((int8)(disp));
  lcd_putcmd(0xC0);
  printf(lcd_putchar, "V = ");
  lcd_putchar(high);
  lcd_putchar(low);
}
void main()
{

lcd_init();
Vref=0;// chon Vref bang 0
duty=0;
//----------------------------------------------------------------
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
set_timer1(64911);             //chon chu ki trich mau la 10ms
//--------------  ---------------------
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_4,311,1);//chon chu ki mang la 0.5ms
set_pwm1_duty(duty);
while(1)
    {
      if(value<tempt) duty=duty+12;//neu V<5V thi tang chu ki lam viec len 4.8us
      if(value>tempt) duty=duty-12;//neu V>5V thi giam chu ki lam viec di 4.8us
      set_pwm1_duty(duty);
//----------------------------------------     
      lcd_putcmd(0x80);
      printf(lcd_putchar,"nhap gia tri dat");
      LCD();
      
    }
}
Hình Kèm Theo
File Type: jpg 1.JPG (239.7 KB, 45 lần tải)

thay đổi nội dung bởi: namqn, 11-04-2009 lúc 05:06 PM. Lý do: định dạng code
tronghung101 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn