Elixyra
Newbie level 5
- Joined
- May 24, 2013
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,348
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include <avr/io.h> #include <lcd.h> #include <avr/interrupt.h> #include <stdlib.h> #include "uart.h" #include <util/delay.h> #define UART_BAUD_RATE 9600 /* 9600 baud */ #define xtalCpu 7372800 unsigned char CtrlZ=0x1A; unsigned char msg[] = ""; int main(void) { int k = 0; int j = 0; int i = 0; uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); sei(); lcd_init(LCD_DISP_ON); uart_puts("AT\r\n"); _delay_ms(3000); uart_puts("AT+CMGF=1\r\n");//Message format “AT+CMGF=[mode]1” _delay_ms(200); uart_puts("AT+CMGR=1\r\n");// Read Message while(uart_getc()) { msg[i++]=uart_getc(); } i = 0; while(msg[i++]){ if(msg[i] != '>') lcd_putc(msg[i]); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 #include <avr/io.h> #include <avr/interrupt.h> #include <lcd.h> #include <stdlib.h> #include "uart.h" #include <util/delay.h> #define USART_BAUDRATE 9600 #define BAUD_PRESCALE ((( F_CPU / ( USART_BAUDRATE * 16 UL ))) - 1) unsigned char msg[] = ""; unsigned int i = 0, j = 0; int main (void) { UCSRB |= (1 << RXEN ) | (1 << TXEN ); // Turn on the transmission and //reception circuitry UCSRC |= (1 << URSEL ) | (1 << UCSZ0 ) | (1 << UCSZ1 ); // Use 8-bit character //sizes UBRRH = ( BAUD_PRESCALE >> 8) ; // Load upper 8-bits of the baud rate value //into the high byte //of the UBRR register UBRRL = BAUD_PRESCALE; // Load lower 8 -bits of the baud rate value into the //low byte of the //UBRR register sei () lcd_init(LCD_DISP_ON); uart_puts("AT\r\n"); _delay_ms(3000); uart_puts("AT+CMGF=1\r\n");//Message format “AT+CMGF=[mode]1” _delay_ms(200); uart_puts("AT+CMGR=1\r\n");// Read Message _delay_ms(3000); for (;;) // Loop forever { // Do nothing - echoing is handled by the ISR instead of in the main //loop while(j < 45) lcd_putc(msg[j++]); j = 0; } } ISR (USART_RXC_vect) { msg[i++] = UDR; // Fetch the received byte value into the variable //"ByteReceived" msg[i] = '\0'; if(i == 45) i = 0; //data length 45 characters. }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?