Microcontroller › AVR › Esp8266 interfacing with Atmega 8/16
- This topic has 1 reply, 2 voices, and was last updated 6 years, 7 months ago by
Hari Prasaath K.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
September 25, 2017 at 9:07 am #4692
rohini
ParticipantI am not getting OK response when I am sending "ATrn" command to ESP8266. I am working on 9600bps and my module(esp) is also working on 9600bps, I checked it through Hyper terminal and it works fine.//************************************************************//Project: ESP-8266 with Atmega8(16Mhz)//Author: Bivashkumar singh//Module description: 4-bit Lcd//************************************************************#include <stdio.h>#include <avr/io.h>#include <util/delay.h>#include <stdlib.h>#include "lcd.h"unsigned char recive[50] = {0};#define LCD_DPRT PORTC#define LCD_DDDR DDRC#define LCD_DPIN PINC#define LCD_CPRT PORTB#define LCD_CDDR DDRB#define LCD_CPIN PINB#define LCD_RS 0#define LCD_RW 1#define LCD_EN 2int i=0;void lcdcommand(unsigned char cmnd){unsigned char chr = cmnd;chr = (cmnd>>4);LCD_DPRT = chr;LCD_CPRT &= ~(1<<LCD_RS);LCD_CPRT &= ~(1<<LCD_RW);LCD_CPRT |= (1<<LCD_EN);_delay_ms(1000);LCD_CPRT &= ~(1<<LCD_EN);for(i=0;i<=2;i++)_delay_ms(500);LCD_DPRT = (cmnd & 0x0f);LCD_CPRT |= (1<<LCD_EN);_delay_ms(1000);LCD_CPRT &= ~(1<<LCD_EN);for(i=0;i<;i++)
_delay_ms(500);}void lcd_init(){LCD_DDDR = 0XFF;LCD_CDDR = 0XFF;LCD_CPRT &=~(1<<LCD_EN);for(i=0;i<=1;i++)_delay_ms(1000);lcdcommand(0x33);_delay_ms(1000);lcdcommand(0x32);_delay_ms(1000);lcdcommand(0x28);_delay_ms(1000);lcdcommand(0x0e);_delay_ms(1000);lcdcommand(0x01);for(i=0;i<=1;i++)_delay_ms(1000);lcdcommand(0x06);}void lcddata(unsigned char data){unsigned char chr = data;chr = (data>>4);LCD_DPRT = chr;LCD_CPRT |= (1<<LCD_RS);LCD_CPRT &= ~(1<<LCD_RW);LCD_CPRT |= (1<<LCD_EN);_delay_ms(100);LCD_CPRT &= ~(1<<LCD_EN);LCD_DPRT = (data & 0X0F);LCD_CPRT |= (1<<LCD_EN);_delay_ms(500);LCD_CPRT &= ~(1<<LCD_EN);for(i=0;i<=4;i++)_delay_ms(500);}void lcd_gotoxy(unsigned char x,unsigned char y){unsigned char firstchar[]={0x80,0xc0,0x94,0xd4};lcdcommand(firstchar[y-1]+x-1);_delay_us(500);}void lcd_print(char *ch){unsigned char i = 0;while(ch !=0){lcddata(ch);i++;}}int lcd(unsigned char *recive){lcd_init();lcd_gotoxy(1,1);// while(recive)lcd_print(recive);while(1);return 0;}//****************************************ESP-8266***************************//***************************************************************************unsigned char recive[10] = {0};//____________________________UART INIT______________________________________//___________________________________________________________________________void usart_init(void){UCSRB = (1<<TXEN) | (1<<RXEN);UCSRC = (1<<UCSZ1) | (1<<UCSZ0) | (1<<URSEL);UBRRL = 103; //baud rate 9600 (atmega8 16MHz)}//____________________________UART SEND_______________________________________//____________________________________________________________________________void usart_send(char *ch){char i=0;while(ch != 0){while(!(UCSRA & (1<<UDRE)));UDR = ch;i++;}}//_____________________________UART RECIVE_____________________________________//_____________________________________________________________________________void usart_recive(){while(UDR){while(!(UCSRA &(1<<RXC)));recive[i++] = UDR;}}//
main
//
int main(void){int i=0;cahr ch[50] = "ATrn"usart_init();usart_send(ch);usart_send("rn");_delay_ms(500);for(i=0;i<=20;i++)recive=usart_recive();lcd(recive);return 0;}//################################### END ###########################################//###################################################################################July 17, 2018 at 5:14 pm #14861Hari Prasaath K
ParticipantCheck with below link to have look on more details about ESP interfacing
electronicwings.com/avr-atmega/atmega16-interface-with-esp8266-module
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.