K
kumarprabhatn
Guest
Hej der ..
Jeg brugte dette program bruger codevision AVR.Det prøver med og AT CMGF = 1 kommando ..
Code:
# include <mega32.h>
# include <stdio.h>
# include <delay.h># define RXB8 1
# define TXB8 0
# define UPE 2
# define OVR 3
# define FE 4
# define UDRE 5
# define RXC 7
# define RXCIE 7
# define URSEL 7
# define RXEN 4
# define USBS 3
# define TXEN 3
# define UCSZ0 1# define FRAMING_ERROR (1 <<FE)
# define PARITY_ERROR (1 <<UPE)
# define DATA_OVERRUN (1 <<OVR)
# define DATA_REGISTER_EMPTY (1 <<UDRE)
# define RX_COMPLETE (1 <<RXC)usignerede CHAR på [4] = ( 'A', 'T', '\ r', '\ n ");
usignerede CHAR atcmgf [11] = ( 'A', 'T',' ',' C', 'M', 'G', 'F','=',' 1', '\ r', ' \ n ");
int j;
usignerede CHAR skille;
int gyldig = 0x00;void modem_init_micro ()
(
usignerede int baudr = 103; / * Værdi i UBRR for 9600 Baud * /
/ * Set baudhastighed * /
UBRRH = (usignerede CHAR) (baudr>> 8);
UBRRL = (usignerede CHAR) baudr;
/ * Enable receiver og transmitter * /
UCSRB = (1 <<RXCIE) | (1 <<RXEN) | (1 <<TXEN);
/ * Set frame format: 8data, 2stop bit * /
UCSRC = (1 <<URSEL) | (1 <<USBS) | (3 <<UCSZ0);
)void checkat ()
(
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<UDRE)))
;
/ * Læg data i buffer, sender data * /
Udr = i [j];
)
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<RXC)))
;
/ * Hent og opbevare modtaget indeks fra buffer * /
skille = Udr;
if (skille == 'O')
gyldig = 1;
)
)void checkcmgf ()
(
if (gyldig == 1)
(
gyldig = 0;
for (j = 0; j <11 j )
(
while (! (UCSRA & (1 <<UDRE)))
;
/ * Læg data i buffer, sender data * /
Udr = atcmgf [j];
)
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<RXC)))
;
/ * Hent og opbevare modtaget indeks fra buffer * /
skille = Udr;
if (skille == 'O')
gyldig = 2;
)
)
)void Main (void)
(/ / Input / Output Ports initialisering
/ / Port A initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = Out
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = 0
PORTA = 0x00;
DDRA = 0x01;/ / Port B initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTB = 0x00;
DDRB = 0x00;/ / Port C initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTC = 0x00;
DDRC = 0x00;/ / Port D initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTD = 0x00;
DDRD = 0x00;/ / Timer / Counter 0 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 0 Stoppet
/ / Mode: Normal top = FFH
/ / OC0 output: Afbrudt
TCCR0 = 0x00;
TCNT0 = 0x00;
OCR0 = 0x00;/ / Timer / Counter 1 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 1 Stoppet
/ / Mode: Normal top = FFFFh
/ / OC1A output: Discon.
/ / OC1B output: Discon.
/ / Støj Canceler: Off
/ / Input Capture på Falling Edge
/ / Timer 1 Overflow Interrupt: Off
/ / Input Capture Interrupt: Off
/ / Sammenlign A Match Interrupt: Off
/ / Sammenlign B Match Interrupt: Off
TCCR1A = 0x00;
TCCR1B = 0x00;
TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0x00;
OCR1AL = 0x00;
OCR1BH = 0x00;
OCR1BL = 0x00;/ / Timer / Counter 2 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 2 Stoppet
/ / Mode: Normal top = FFH
/ / OC2 output: Afbrudt
ASSR = 0x00;
TCCR2 = 0x00;
TCNT2 = 0x00;
OCR2 = 0x00;/ / Eksterne Interrupt (s) initialisering
/ / INT0: Off
/ / INT1: Off
/ / INT2: Off
MCUCR = 0x00;
MCUCSR = 0x00;/ / Timer (s) / Counter (s) Interrupt (s) initialisering
TIMSK = 0x00;/ / USART initialisering
/ / Meddelelse Parameters: 8 Data, 2 Stop, ingen paritet
/ / USART Receiver: On
/ / USART Transmitter: On
/ / USART Mode: Asynkron
/ / USART baudhastighed: 115200
UCSRA = 0x00;
UCSRB = 0x18;
UCSRC = 0x8E;
UBRRH = 0x00;
UBRRL = 0x08;/ / Analog sammenligner initialisering
/ / Analog sammenligner: Off
/ / Analog sammenligner Input Capture af Timer / Counter 1: Off
ACSR = 0x80;
SFIOR = 0x00;modem_init_micro ();
checkat ();
delay_ms (100);
checkcmgf ();
delay_ms (100);
if (gyldig == 1)
(
mens (1)
(
PORTA.0 = 1;
delay_ms (1000);
PORTA.0 = 0;
delay_ms (1000);
)
)
ellers hvis (gyldigt == 2)
PORTA.0 = 1;
anden
PORTA.0 = 0
Jeg brugte dette program bruger codevision AVR.Det prøver med og AT CMGF = 1 kommando ..
Code:
# include <mega32.h>
# include <stdio.h>
# include <delay.h># define RXB8 1
# define TXB8 0
# define UPE 2
# define OVR 3
# define FE 4
# define UDRE 5
# define RXC 7
# define RXCIE 7
# define URSEL 7
# define RXEN 4
# define USBS 3
# define TXEN 3
# define UCSZ0 1# define FRAMING_ERROR (1 <<FE)
# define PARITY_ERROR (1 <<UPE)
# define DATA_OVERRUN (1 <<OVR)
# define DATA_REGISTER_EMPTY (1 <<UDRE)
# define RX_COMPLETE (1 <<RXC)usignerede CHAR på [4] = ( 'A', 'T', '\ r', '\ n ");
usignerede CHAR atcmgf [11] = ( 'A', 'T',' ',' C', 'M', 'G', 'F','=',' 1', '\ r', ' \ n ");
int j;
usignerede CHAR skille;
int gyldig = 0x00;void modem_init_micro ()
(
usignerede int baudr = 103; / * Værdi i UBRR for 9600 Baud * /
/ * Set baudhastighed * /
UBRRH = (usignerede CHAR) (baudr>> 8);
UBRRL = (usignerede CHAR) baudr;
/ * Enable receiver og transmitter * /
UCSRB = (1 <<RXCIE) | (1 <<RXEN) | (1 <<TXEN);
/ * Set frame format: 8data, 2stop bit * /
UCSRC = (1 <<URSEL) | (1 <<USBS) | (3 <<UCSZ0);
)void checkat ()
(
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<UDRE)))
;
/ * Læg data i buffer, sender data * /
Udr = i [j];
)
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<RXC)))
;
/ * Hent og opbevare modtaget indeks fra buffer * /
skille = Udr;
if (skille == 'O')
gyldig = 1;
)
)void checkcmgf ()
(
if (gyldig == 1)
(
gyldig = 0;
for (j = 0; j <11 j )
(
while (! (UCSRA & (1 <<UDRE)))
;
/ * Læg data i buffer, sender data * /
Udr = atcmgf [j];
)
for (j = 0; j <4 j )
(
while (! (UCSRA & (1 <<RXC)))
;
/ * Hent og opbevare modtaget indeks fra buffer * /
skille = Udr;
if (skille == 'O')
gyldig = 2;
)
)
)void Main (void)
(/ / Input / Output Ports initialisering
/ / Port A initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = Out
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = 0
PORTA = 0x00;
DDRA = 0x01;/ / Port B initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTB = 0x00;
DDRB = 0x00;/ / Port C initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTC = 0x00;
DDRC = 0x00;/ / Port D initialisering
/ / Func7 = I Func6 = I Func5 = I Func4 = I Func3 = I Func2 = I FUNC1 = I Func0 = I
/ / State7 = T State6 = T State5 = T State4 = T State3 = T State2 = T State1 = T State0 = T
PORTD = 0x00;
DDRD = 0x00;/ / Timer / Counter 0 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 0 Stoppet
/ / Mode: Normal top = FFH
/ / OC0 output: Afbrudt
TCCR0 = 0x00;
TCNT0 = 0x00;
OCR0 = 0x00;/ / Timer / Counter 1 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 1 Stoppet
/ / Mode: Normal top = FFFFh
/ / OC1A output: Discon.
/ / OC1B output: Discon.
/ / Støj Canceler: Off
/ / Input Capture på Falling Edge
/ / Timer 1 Overflow Interrupt: Off
/ / Input Capture Interrupt: Off
/ / Sammenlign A Match Interrupt: Off
/ / Sammenlign B Match Interrupt: Off
TCCR1A = 0x00;
TCCR1B = 0x00;
TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0x00;
OCR1AL = 0x00;
OCR1BH = 0x00;
OCR1BL = 0x00;/ / Timer / Counter 2 initialisering
/ / Clock source: System Clock
/ / Clock værdi: Timer 2 Stoppet
/ / Mode: Normal top = FFH
/ / OC2 output: Afbrudt
ASSR = 0x00;
TCCR2 = 0x00;
TCNT2 = 0x00;
OCR2 = 0x00;/ / Eksterne Interrupt (s) initialisering
/ / INT0: Off
/ / INT1: Off
/ / INT2: Off
MCUCR = 0x00;
MCUCSR = 0x00;/ / Timer (s) / Counter (s) Interrupt (s) initialisering
TIMSK = 0x00;/ / USART initialisering
/ / Meddelelse Parameters: 8 Data, 2 Stop, ingen paritet
/ / USART Receiver: On
/ / USART Transmitter: On
/ / USART Mode: Asynkron
/ / USART baudhastighed: 115200
UCSRA = 0x00;
UCSRB = 0x18;
UCSRC = 0x8E;
UBRRH = 0x00;
UBRRL = 0x08;/ / Analog sammenligner initialisering
/ / Analog sammenligner: Off
/ / Analog sammenligner Input Capture af Timer / Counter 1: Off
ACSR = 0x80;
SFIOR = 0x00;modem_init_micro ();
checkat ();
delay_ms (100);
checkcmgf ();
delay_ms (100);
if (gyldig == 1)
(
mens (1)
(
PORTA.0 = 1;
delay_ms (1000);
PORTA.0 = 0;
delay_ms (1000);
)
)
ellers hvis (gyldigt == 2)
PORTA.0 = 1;
anden
PORTA.0 = 0