chào các anh chị, em đang làm về gửi nhận tin nhắn bằng sim900a, chương trình đã gửi và nhận tin nhắn ổn, nhưng em chỉ gửi được 1 tin nhắn duy nhất thì được, gửi tiếp tin thứ 2 thì nó không báo được nữa, e chưa tìm ra nguyên nhân, mọi người có thể giúp em tìm ra nguyên nhân được không, em cảm ơn nhiều.
#include <mega128.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#include <alcd.h>
unsigned char c,c1,c2,c3,c4,c5;
unsigned char nhan[4],i,n,phone[11],sms[70];
unsigned char count;
unsigned char i,new_sms;
//unsigned char MBD1[]="MBD1",MBD2[]="MBD2",MBD3[]="MBD3",MBD4[]="MBD4";
//unsigned char TBD1[]="TBD1",TBD2[]="TBD2",TBD3[]="TBD3",TBD4[]="TBD4";
//unsigned char MTBB[]="MTBB",TTBB[]="TTBB";
#ifndef RXB8
#define RXB8 1
#endif
#ifndef TXB8
#define TXB8 0
#endif
#ifndef UPE
#define UPE 2
#endif
#ifndef DOR
#define DOR 3
#endif
#ifndef FE
#define FE 4
#endif
#ifndef UDRE
#define UDRE 5
#endif
#ifndef RXC
#define RXC 7
#endif
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 8
char rx_buffer0[RX_BUFFER_SIZE0];
#if RX_BUFFER_SIZE0 <= 256
unsigned char rx_wr_index0,rx_rd_index0,rx_counter0;
#else
unsigned int rx_wr_index0,rx_rd_index0,rx_counter0;
#endif
// This flag is set on USART0 Receiver buffer overflow
bit rx_buffer_overflow0;
// USART0 Receiver interrupt service routine
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
char status,data;
status=UCSR0A;
data=UDR0;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
rx_buffer0[rx_wr_index0++]=data;
#if RX_BUFFER_SIZE0 == 256
// special case for receiver buffer size=256
if (++rx_counter0 == 0)
{
#else
if (rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
if (++rx_counter0 == RX_BUFFER_SIZE0)
{
rx_counter0=0;
#endif
rx_buffer_overflow0=1;
}
}
}
#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter0==0);
data=rx_buffer0[rx_rd_index0++];
#if RX_BUFFER_SIZE0 != 256
if (rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
#endif
#asm("cli")
--rx_counter0;
#asm("sei")
return data;
}
#pragma used-
#endif
// Standard Input/Output functions
#include <stdio.h>
void truyen_mang(char *s)
{
// putchar(0x0d); //xuong dong
while(*s)
{
putchar(*s);
s++;
delay_ms(10);
}
}
void khoi_tao_modul_sim()
{
PORTD.7=1;
delay_ms(3000);
PORTD.7=0;
delay_ms(5000);
truyen_mang("AT");
putchar(13);
putchar(13);
truyen_mang("AT");
putchar(13);
while(getchar()!='K');
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(" SIM READY! ...");
delay_ms(500);
truyen_mang("\n");
truyen_mang("AT+CMGS=\"+84979636769\"\r\n");
delay_ms(100);
truyen_mang("khoi tao sim thanh cong!");
truyen_mang("\n");
putchar(0x1A);
truyen_mang("\n");
i=0;
new_sms =0;
}
void doc_o_nho()
{
putchar(13);
truyen_mang("AT+CMGR=1");
delay_ms(10);
putchar(13);
}
void read()
{
c=getchar();
if(c=='+') c1=c;
if(c=='C') c2=c;
if(c=='M') c3=c;
if(c=='T') c4=c;
if(c=='I') c5=c;
if(c1=='+' && c2=='C' && c3=='M' && c4=='T' && c5=='I') new_sms=1;
if((c!=13)&&(c!=10)){sms=c; i++;}
}
void doc_tn()
{
delay_ms(10);
PORTD.6=0;
delay_ms(500);
PORTD.6=1;
doc_o_nho();
while(getchar()!=':');
while(getchar()!='+');
for(count=0;count<12;count++)
{
phone[count]=getchar();
}
while(getchar()!='\n');
for(n=0;n<4;n++)
{
nhan[n]=getchar();
}
}
void delete_sms()
{
truyen_mang("AT+CMGD=1,4\r\n"); //delete all sms
delay_ms(100);
for(i=0;i<4;i++)
nhan='\0';
}
void reset_sms()
{
c1=c2=c3=c4=c5=0;
for(i=0;i<70;i++)
{
sms=0;
}
}
void reset_all()
{
i=0;
reset_sms();
new_sms=0;
}
void DK_mach_chu()
{
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='1'))
{
PORTB.4=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 1");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='2'))
{
PORTB.5=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 2");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='3'))
{
PORTB.6=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 3");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='4'))
{
PORTB.7=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 4");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='1'))
{
PORTB.4=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 1");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='2'))
{
PORTB.5=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 2");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='3'))
{
PORTB.6=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 3");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='4'))
{
PORTB.7=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 4");
}
if((nhan[0]=='M')&&(nhan[1]=='T')&&(nhan[2]=='B')&&(nhan[3]=='B'))
{
PORTB.4=1,PORTB.5=1,PORTB.6=1,PORTB.7=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo toan he thong");
}
if((nhan[0]=='T')&&(nhan[1]=='T')&&(nhan[2]=='B')&&(nhan[3]=='B'))
{
PORTB.4=0,PORTB.5=0,PORTB.6=0,PORTB.7=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat het he thong");
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xF0;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=1 State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x40;
DDRD=0xC0;
// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;
// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;
// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer3 Stopped
// Mode: Normal top=0xFFFF
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
ETIMSK=0x00;
// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
UCSR0A=0x00;
UCSR0B=0x98;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67;
// USART1 initialization
// USART1 disabled
UCSR1B=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTG Bit 0
// RD - PORTG Bit 1
// EN - PORTG Bit 2
// D4 - PORTB Bit 0
// D5 - PORTB Bit 1
// D6 - PORTB Bit 2
// D7 - PORTB Bit 3
// Characters/line: 16
lcd_init(16);
// Global enable interrupts
#asm("sei")
khoi_tao_modul_sim();
i = 0;
new_sms=0;
while (1)
{
// Place your code here
read();
if(new_sms==1)
{
doc_tn();
delay_ms(30);
DK_mach_chu();
delete_sms();//xoa sms vua nhan
delay_ms(100);
reset_all();//reset cac thong so ve 0
}
}
}
#include <mega128.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#include <alcd.h>
unsigned char c,c1,c2,c3,c4,c5;
unsigned char nhan[4],i,n,phone[11],sms[70];
unsigned char count;
unsigned char i,new_sms;
//unsigned char MBD1[]="MBD1",MBD2[]="MBD2",MBD3[]="MBD3",MBD4[]="MBD4";
//unsigned char TBD1[]="TBD1",TBD2[]="TBD2",TBD3[]="TBD3",TBD4[]="TBD4";
//unsigned char MTBB[]="MTBB",TTBB[]="TTBB";
#ifndef RXB8
#define RXB8 1
#endif
#ifndef TXB8
#define TXB8 0
#endif
#ifndef UPE
#define UPE 2
#endif
#ifndef DOR
#define DOR 3
#endif
#ifndef FE
#define FE 4
#endif
#ifndef UDRE
#define UDRE 5
#endif
#ifndef RXC
#define RXC 7
#endif
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 8
char rx_buffer0[RX_BUFFER_SIZE0];
#if RX_BUFFER_SIZE0 <= 256
unsigned char rx_wr_index0,rx_rd_index0,rx_counter0;
#else
unsigned int rx_wr_index0,rx_rd_index0,rx_counter0;
#endif
// This flag is set on USART0 Receiver buffer overflow
bit rx_buffer_overflow0;
// USART0 Receiver interrupt service routine
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
char status,data;
status=UCSR0A;
data=UDR0;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
rx_buffer0[rx_wr_index0++]=data;
#if RX_BUFFER_SIZE0 == 256
// special case for receiver buffer size=256
if (++rx_counter0 == 0)
{
#else
if (rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
if (++rx_counter0 == RX_BUFFER_SIZE0)
{
rx_counter0=0;
#endif
rx_buffer_overflow0=1;
}
}
}
#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter0==0);
data=rx_buffer0[rx_rd_index0++];
#if RX_BUFFER_SIZE0 != 256
if (rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
#endif
#asm("cli")
--rx_counter0;
#asm("sei")
return data;
}
#pragma used-
#endif
// Standard Input/Output functions
#include <stdio.h>
void truyen_mang(char *s)
{
// putchar(0x0d); //xuong dong
while(*s)
{
putchar(*s);
s++;
delay_ms(10);
}
}
void khoi_tao_modul_sim()
{
PORTD.7=1;
delay_ms(3000);
PORTD.7=0;
delay_ms(5000);
truyen_mang("AT");
putchar(13);
putchar(13);
truyen_mang("AT");
putchar(13);
while(getchar()!='K');
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts(" SIM READY! ...");
delay_ms(500);
truyen_mang("\n");
truyen_mang("AT+CMGS=\"+84979636769\"\r\n");
delay_ms(100);
truyen_mang("khoi tao sim thanh cong!");
truyen_mang("\n");
putchar(0x1A);
truyen_mang("\n");
i=0;
new_sms =0;
}
void doc_o_nho()
{
putchar(13);
truyen_mang("AT+CMGR=1");
delay_ms(10);
putchar(13);
}
void read()
{
c=getchar();
if(c=='+') c1=c;
if(c=='C') c2=c;
if(c=='M') c3=c;
if(c=='T') c4=c;
if(c=='I') c5=c;
if(c1=='+' && c2=='C' && c3=='M' && c4=='T' && c5=='I') new_sms=1;
if((c!=13)&&(c!=10)){sms=c; i++;}
}
void doc_tn()
{
delay_ms(10);
PORTD.6=0;
delay_ms(500);
PORTD.6=1;
doc_o_nho();
while(getchar()!=':');
while(getchar()!='+');
for(count=0;count<12;count++)
{
phone[count]=getchar();
}
while(getchar()!='\n');
for(n=0;n<4;n++)
{
nhan[n]=getchar();
}
}
void delete_sms()
{
truyen_mang("AT+CMGD=1,4\r\n"); //delete all sms
delay_ms(100);
for(i=0;i<4;i++)
nhan='\0';
}
void reset_sms()
{
c1=c2=c3=c4=c5=0;
for(i=0;i<70;i++)
{
sms=0;
}
}
void reset_all()
{
i=0;
reset_sms();
new_sms=0;
}
void DK_mach_chu()
{
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='1'))
{
PORTB.4=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 1");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='2'))
{
PORTB.5=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 2");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='3'))
{
PORTB.6=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 3");
}
if((nhan[0]=='M')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='4'))
{
PORTB.7=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo bong den 4");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='1'))
{
PORTB.4=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 1");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='2'))
{
PORTB.5=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 2");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='3'))
{
PORTB.6=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 3");
}
if((nhan[0]=='T')&&(nhan[1]=='B')&&(nhan[2]=='D')&&(nhan[3]=='4'))
{
PORTB.7=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat bong den 4");
}
if((nhan[0]=='M')&&(nhan[1]=='T')&&(nhan[2]=='B')&&(nhan[3]=='B'))
{
PORTB.4=1,PORTB.5=1,PORTB.6=1,PORTB.7=1;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("mo toan he thong");
}
if((nhan[0]=='T')&&(nhan[1]=='T')&&(nhan[2]=='B')&&(nhan[3]=='B'))
{
PORTB.4=0,PORTB.5=0,PORTB.6=0,PORTB.7=0;
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("tat het he thong");
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xF0;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=1 State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x40;
DDRD=0xC0;
// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;
// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;
// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer3 Stopped
// Mode: Normal top=0xFFFF
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
ETIMSK=0x00;
// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
UCSR0A=0x00;
UCSR0B=0x98;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67;
// USART1 initialization
// USART1 disabled
UCSR1B=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTG Bit 0
// RD - PORTG Bit 1
// EN - PORTG Bit 2
// D4 - PORTB Bit 0
// D5 - PORTB Bit 1
// D6 - PORTB Bit 2
// D7 - PORTB Bit 3
// Characters/line: 16
lcd_init(16);
// Global enable interrupts
#asm("sei")
khoi_tao_modul_sim();
i = 0;
new_sms=0;
while (1)
{
// Place your code here
read();
if(new_sms==1)
{
doc_tn();
delay_ms(30);
DK_mach_chu();
delete_sms();//xoa sms vua nhan
delay_ms(100);
reset_all();//reset cac thong so ve 0
}
}
}
Comment