View Single Post
Old 27-05-2008, 10:40 PM   #1
chizardxx
Nhập môn đệ tử
 
Tham gia ngày: Oct 2007
Bài gửi: 7
:
giúp mình với , mình gặp vấn đề trong hiển thị LCD và dùng ngắt

mình dùng proteus mô phỏng
Mạch gồm pic6f877a,lm335,mpx4115 nối vào đầu vào của AN0 và AN1, RB0 và RB1 nối với 2 button
khi button1=1
+hiển thị gia tri cua mpx (cảm biến áp suất) button2=1 hiển thị Vp
button2=0 hiển thị P
khibutton1=0
+hiển thị giá trị của lm335

CT:
Code:
#include <16F877A.h>
#include <def_877a.h>
#device *=16 adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)

#include <lcd_lib_4bit.c>

void convert(int16 x);
void test();
void temp_2_buff();
void xuatralcd();
void chongrung(int8 x);


int1 blink;
int8 mint,maxt,minp,maxp;
int8 nghin,tram,chuc,donvi,mode;
int16 volt,adc1,adc2;


void xuat_nhietdo();
void alarm();




void main()
{
   trisa = 0xFF;
   trisb = 0x03;
   trisd = 0x00;
   mint=15;
   maxt=45;
   minp=15;
   maxp=100;
   blink=0;
   
   lcd_init();
   setup_adc_ports(RA0_RA1_RA3_ANALOG );
   setup_adc(ADC_CLOCK_INTERNAL);
   delay_us(10);
// Khoi tao cho ngat ngoai
   enable_interrupts (INT_EXT);
   ext_int_edge(H_TO_L);
   enable_interrupts (GLOBAL);
//---------------------------   
   lcd_putcmd(0x01);
   lcd_putcmd(0x80);
   printf(lcd_putchar,"   V--P--T");
   delay_ms(1000);
//---------------------------   
   while(1){
   if (RB0==1) {
   set_ADC_channel(0);
   delay_ms(10);
   adc1 = read_adc();
   volt = adc1;   
      if(RB1==1) {
      volt = (volt*5)/1.023;
      convert((int16)volt);
      lcd_putcmd(0xC0);
      printf(lcd_putchar,"Vp=");
      xuatralcd();
      delay_ms(1000);
      }
      if (RB1==0) {
   adc1 = (adc1-0.268*1023/5)/((45.9*1.023)/5)+15;
   convert((int16)adc1);
   lcd_putcmd(0xC0);
   printf(lcd_putchar,"P=");
   xuatralcd();
   lcd_putchar("kpA");
   if ((int16)adc1>100 || (int16)adc1<15 ) alarm();
   delay_ms(1000);
      }
   }
   
   else {
   set_ADC_channel(1);
   set_timer0(0);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); // Tran = 13.1ms
   adc2=read_adc();
   volt=adc2;
      if (RB1==1) {
      volt=(volt*5)/1.023;
      convert((int16)volt);
      lcd_putcmd(0xC0);
      printf(lcd_putchar,"Vt=");
      xuatralcd();
      }
      else {
      adc2 = (adc2 - 558.5)/2.048;
      convert((int16)adc2);
      lcd_putcmd(0xC0);
      printf(lcd_putchar,  "V2=");
      xuatralcd();
      delay_ms(100);
      }
   
   } }}  
void convert(int16 x)
{  nghin = x / 1000 + 48;
   x  = x % 1000;
   tram  = x / 100 + 0x30;
   x  = x % 100;
   chuc  = x / 10 + 48;
   donvi = x % 10 + 48;
}
void xuatralcd()
{  lcd_putchar(nghin);
   lcd_putchar(".");
   lcd_putchar(tram);
   lcd_putchar(chuc);
   lcd_putchar(donvi);
 }
void alarm()
{  if (blink==0) { LCD_putchar("!!!!!");blink=1;delay_ms(10);}
       else          {LCD_putchar(" ");blink=0;delay_ms(10);}
}

mình ko hiểu , khi mình ấn button2 thì ko xảy ra hiện tượng gì xảy ra mình đã thử test nếu ko có kiểm tra button thì từng cái vẫn có thể hiển thị đc
ah giúp mình đoạn nào nên xài timer để tối ưu hơn nhé
chizardxx vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn