سلام دوستان
من یه پروژه کنترل چند رله با استفاده از ماژول بلوتوث hc05 و میکرو دارم میسازم
وقتی که برنامه به قسمتی میرسه که میکرو برای بلوتوث دستورات کامند رو ارسال میکنه در همون قسمت میمونه و جلوتر نمیره تا اینکه سیم اتصال سریال میکرو رو قطع کنم تا برنامه ادامه پیدا کنه
لطفا راهنمایی کنید خیلی واجبه
این برنامه:
/************************************************** ***
Project : Relay Control by HC-05
Version : 1.0
Date : 10/20/2013
Author : Ali Imanifar
Company : ECA
Comments: وب سایت تخصصی برق و الکترونیک ECA
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <delay.h>
// Standard Input/Output functions
#include <stdio.h>
#include <string.h>
void getstr(char *str)
{
char ch = 0;
ch = getchar();
while((ch == 10) || (ch == 13) || (ch == 0))
ch = getchar();
while((ch != 10) && (ch != 13))
{
*str++ = ch;
ch = getchar();
}
*str = 0;
}
// Declare your global variables here
char str[50];
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=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
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=T State0=T
PORTD=0x00;
DDRD=0x08;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
// Make a delay to enter AT Mode 1
// if No delay HC-05 goes to AT Mode 2
delay_ms(1000);
PORTD.3 =1;
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("eca");
delay_ms(3000);
به این قسمت که میرسه جلوتر نمیره
printf("AT\r\nf");
scanf("%s",str);
lcd_gotoxy(0,0);
lcd_puts(str);
//++++++++++++++++++++++++++++++++++
printf("AT+PSWD=1234\r\n");
scanf("%s",str);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("Set Pairing Pass\nto 1234 -->");
lcd_gotoxy(13,1);
lcd_puts(str);
delay_ms(3000);
//++++++++++++++++++++++++++++++++++
printf("AT+UART?\r\n");
scanf("%s",str);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("UART Config :");
lcd_gotoxy(0,1);
lcd_puts(str);
delay_ms(3000);
//++++++++++++++++++++++++++++++++++
printf("AT+NAME=farhadi\r\n");
scanf("%s",str);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("Set Bluetooth\nName -->");
lcd_gotoxy(11,1);
lcd_puts(str);
scanf("%s",str);
delay_ms(3000);
//++++++++++++++++++++++++++++++++++
PORTD.3 =0;
lcd_gotoxy(0,0);
lcd_puts("Now Connect By\nLaptop Bluetooth");
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" btcontrol\n Waiting ...");
while (1)
{
// Place your code here
getstr(str);
lcd_gotoxy(0,1);
lcd_puts(str);
delay_ms(700);
if(!strcmp(str,"Relay0 ON")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay0 ON");
PORTC.0 = 1;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay1 ON")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay1 ON");
PORTC.1 = 1;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay2 ON")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay2 ON");
PORTC.2 = 1;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay3 ON")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay3 ON");
PORTC.3 = 1;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay0 OFF")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay0 OFF");
PORTC.0 = 0;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay1 OFF")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay1 OFF");
PORTC.1 = 0;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay2 OFF")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay2 OFF");
PORTC.2 = 0;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else if(!strcmp(str,"Relay3 OFF")) {
printf("Command Accepted\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Relay3 OFF");
PORTC.3 = 0;
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
else {
printf("Command Rejected!\r\n");
printf("Wrong Command!\r\n");
lcd_clear();
lcd_gotoxy(0,1);
lcd_puts("Wrong Command!");
delay_ms(1700);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(" http://www.ECA.ir\n Waiting ...");
}
}
}