tình hình là e có 1 đoạn code thế này mà khi nhận dữ liệu thì nó nhảy vào làm trong ngắt nhưng mãi mà new_sms e ko lên bằng 1 mà cứ làm hoài dem++,các bác giúp e với!khi gửi dữ liệu đến nó sẽ new_sms e cần là 1 để thực hiện lệnh ở dưới! các bác cho e hỏi thêm '\r' là sao e chưa hiểu?
#include <16f877a.h>
#device PIC16F877A*=16 ADC=10
#include <string.h>
#include <lcd_lib_4bit.c>
#fuses nowdt,hs,noput,noprotect,nodebug,nobrownout,nolvp, nocpd,nowrt
#use delay(clock=12000000)
#use fast_io(b)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
char chuoi[90];
int8 dem,new_sms,z,x,adc,f;
/*********** Khai bao ngat nhan noi tiep ***********/
#INT_RDA
void ngat()
{
chuoi[dem]=getc();
if(chuoi[dem]=='\r')
{
z++;
if(z==2)new_sms=1;
}
dem++;
}
void main()
{
enable_interrupts(global);//Cho phep ngat toan cuc
enable_interrupts(int_rda);//Cho phep ngat nhan noi tiep
setup_adc(ADC_clock_internal); // thiet lap tan so lay mau ADC
setup_adc_ports(AN0); // ngo vao A0
set_adc_channel(0); // chan doc gia tri adc bang read_adc()
LCD_init(); //khoi tao LCD
Printf(LCD_putchar," DKTB QUA SMS ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"Dang cau hinh ");delay_ms(1000);
LCD_putcmd(0xC0);Printf(LCD_putchar,"Cau hinh xong ");delay_ms(2000);
new_sms=0;
z=0;
while(1)
{
signed int16 x;
signed int16 adc;
x=read_ADC();
adc=x/2; // do C
f=adc*1.8+32; // do F
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80);Printf(LCD_putchar," Nhiet do phong ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"%u",adc);LCD_ putcmd(0xC0+4);Printf(LCD_putchar,"C");
LCD_putcmd(0xC0+8);Printf(LCD_putchar,"%u",f);LCD_ putcmd(0xC0+12);Printf(LCD_putchar,"F");
if(new_sms==1)
{
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80); Printf(LCD_putchar,"Co tin nhan moi ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Dang xu ly");
puts("at+cmgr=1");
delay_ms(500);
LCD_putcmd(0x01);// xoa man hinh chi thi
delay_ms(200);
puts("at+cmgd=1");
delay_ms(500);
}}}
#include <16f877a.h>
#device PIC16F877A*=16 ADC=10
#include <string.h>
#include <lcd_lib_4bit.c>
#fuses nowdt,hs,noput,noprotect,nodebug,nobrownout,nolvp, nocpd,nowrt
#use delay(clock=12000000)
#use fast_io(b)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
char chuoi[90];
int8 dem,new_sms,z,x,adc,f;
/*********** Khai bao ngat nhan noi tiep ***********/
#INT_RDA
void ngat()
{
chuoi[dem]=getc();
if(chuoi[dem]=='\r')
{
z++;
if(z==2)new_sms=1;
}
dem++;
}
void main()
{
enable_interrupts(global);//Cho phep ngat toan cuc
enable_interrupts(int_rda);//Cho phep ngat nhan noi tiep
setup_adc(ADC_clock_internal); // thiet lap tan so lay mau ADC
setup_adc_ports(AN0); // ngo vao A0
set_adc_channel(0); // chan doc gia tri adc bang read_adc()
LCD_init(); //khoi tao LCD
Printf(LCD_putchar," DKTB QUA SMS ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"Dang cau hinh ");delay_ms(1000);
LCD_putcmd(0xC0);Printf(LCD_putchar,"Cau hinh xong ");delay_ms(2000);
new_sms=0;
z=0;
while(1)
{
signed int16 x;
signed int16 adc;
x=read_ADC();
adc=x/2; // do C
f=adc*1.8+32; // do F
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80);Printf(LCD_putchar," Nhiet do phong ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"%u",adc);LCD_ putcmd(0xC0+4);Printf(LCD_putchar,"C");
LCD_putcmd(0xC0+8);Printf(LCD_putchar,"%u",f);LCD_ putcmd(0xC0+12);Printf(LCD_putchar,"F");
if(new_sms==1)
{
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80); Printf(LCD_putchar,"Co tin nhan moi ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Dang xu ly");
puts("at+cmgr=1");
delay_ms(500);
LCD_putcmd(0x01);// xoa man hinh chi thi
delay_ms(200);
puts("at+cmgd=1");
delay_ms(500);
}}}
Comment