Hi , I'm A , from Thailand and I'm new in coding microcontroller
I have problem with my project. I want to connect microcontroller from PC to PIC by Xbee.
My Xbee base is connected with PC by USB ( I use PDG-U Serial Converter to USB ) , my remote Xbee is connected with PIC
by RS-232 connect to RC7(RxD) ( My board microcontroller has slot and named it completely )
now I have no idea to make my project successfully , I have read older forum that use Usart library but it's still doesn't work.
Please help me
Best Regards
A
How to PIC 16F887 connected with Xbee X24 by RS232 to PC
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: How to PIC 16F887 connected with Xbee X24 by RS232 to PC
Hi!
Please, visit the links below:
http://www.mikroe.com/eng/products/view ... bee-board/
http://www.mikroe.com/eng/products/view ... ee3-board/
There, you'll find information about connecting mikroElektronika's EasyBee boards and also demo examples written in our compilers.
I'm sure that this will help you get started with your project.
Please, visit the links below:
http://www.mikroe.com/eng/products/view ... bee-board/
http://www.mikroe.com/eng/products/view ... ee3-board/
There, you'll find information about connecting mikroElektronika's EasyBee boards and also demo examples written in our compilers.
I'm sure that this will help you get started with your project.
Best regards
Slavisa
Slavisa
Re: How to PIC 16F887 connected with Xbee X24 by RS232 to PC
thank you very much Salavisa ,, I love your webboard 'coz make me know a lot of information about PIC and MikroC
Re: How to PIC 16F887 connected with Xbee X24 by RS232 to PC
Hi , I can't fix my problem now .. data is not collect from usart Rx that I sent to from PC serial port !
please help , I'm sick of it now and so tried ;(
thanks
please help , I'm sick of it now and so tried ;(
Code: Select all
//#include<adc.h>
int c_switch = 0 , c_o2 = 0 ;
int pause = 40000 ;
int count = 0 ;
unsigned char * data ;
unsigned char receive ;
unsigned short i = 0;
void interrupt(){
char temp ;
while(!Usart_Data_Ready()) ;
i = 0;
do{
temp = Usart_Read();
PIR1.RCIF=0;
data[i] = temp ;
i++;
}while(!Usart_Data_Ready());
} // end void
void main()
{
Usart_init(9600);
//INTCON.GIE = 1;
//INTCON.PEIE = 1;
PIE1.RCIE = 1; //enable receive interrupt
//IPR1.RCIP =1 ;
//TRISC=0x80;
//TXSTA=0x24; // TX9=0 (8 data bits) , TXEN=1 (activate) ,BRGH=1(High speed)
//RCSTA=0x90; // SREN=1 (activate) , CREN=1 (continius receive)
//SPBRG=0x19; // baude rate 9600 , crystall 4MHz
//TXREG = 0 ;
//RCREG = 0 ;
//RCSTA.F7 = 1 ;
//RCSTA.F4 = 1 ;
//TXSTA.F4 = 1 ; // rev = 1 , trans = 0
//TXSTA.F5 = 1 ;
//Soft_Uart_Init(PORTC, 7, 6, 9600, 0);
//UART1_Init(115000);
ADCON0.F7 = 0 ;
ADCON0.F6 = 0 ;
ADCON0.F4 = 1 ;
ADCON0.F3 = 1 ;
ADCON0.F2 = 1 ;
ADCON0.F0 = 1 ;
/* Initial port for control motor */
ANSELH = ANSEL =0x00 ; // Set PORTB => Digital
TRISB.F1=0;TRISB.F2=0; // Motor B 2A,Motor B 2B
TRISD.F0=0;TRISD.F1=0; // Motor A 1A,MOtor A 1B
TRISC.F1=0;TRISC.F2=0; // Motor B 2E,Motor A 1E
PORTC.F1=1;PORTC.F2=1; // Enable Motor B,Enable Motor A
ANSELH.F4=0; // RA4 ==> Digital IO
ANSELH.F5=0; // RA5 >> Digit IO
ANSELH.F1=0; // RA1 >> Digit IO
TRISC = 0 ; //********************
TRISB.F3=0; // RB3 ==> Digital Output
TRISA.F0=0; // RA0 >> Output
Sound_Init(&PORTC, 0); // Init Sound
Lcd_Init(&PORTD); // Config PORTD connect LCD
Lcd_Cmd(LCD_CURSOR_OFF); // Setting cursor of LCD off
while(1) // Infinite Loop
{
Lcd_Out(1,4,"Test"); // Show "Innovative" in Line 1
Lcd_Out(2,4,data);
Delay_ms(5000);
Lcd_Cmd(LCD_CLEAR); // Blink LCD
//USART_Init(115000);
//if (PIR1.F5==1){ // if something received from the serial port
//data = RCREG;
//delay_ms(500);
//getdata(data);
if(strcmp(data,"00000001") == 1)
{
PORTB.F3=1;
Lcd_Out(1,4,"Test"); // Show "Innovative" in Line 1
Lcd_Out(2,4,data);
Delay_ms(5000);
Lcd_Cmd(LCD_CLEAR); // Blink LCD
delay_ms(5000);
PORTB.F3=0;
}
/*
if (Usart_Data_Ready())
{
PORTB.F3=1;
delay_ms(5000);
PORTB.F3=0;
}
receive = Usart_Read() ;
if ( receive != 0 )
{
PORTB.F3=1;
delay_ms(5000);
PORTB.F3=0;
}
//Usart_Write(1);
//check = Adc_Rd(7);
*/
/////////////////////////////////////////////////////
/*
while(!*rec){
data = Soft_Uart_Read(rec);
}
if ( data == 0x01)
{
PORTB.F3=1;
delay_ms(5000);
PORTB.F3=0;
}
*/
c_switch = adc_read(7);
c_o2 = adc_read(1);
if ( c_o2 < 900 ) // check for O2 device
{
PORTB.F3=1; // ON ==> RB3
sound_play(500,1000); // 2 kHz sound ON RC0 at 100 ms
PORTB.F3=0;
}
else if ( c_switch < 1000 ) // Press to Solenoid Out
{
PORTB.F3=1; // ON ==> RB3
sound_play(1000,500); // 2 kHz sound ON RC0 at 100 ms
sound_play(1000,500); // 2 kHz sound ON RC0 at 100 ms
PORTA.F0 = 1 ;
while(count < 20) // delay 20 s
{
Delay_ms(1000);
sound_play(1000,500);
count ++ ;
}
PORTA.F0 = 0;
PORTB.F3=0;
}
//else
//{
else if(PORTB.F0==0) // Check RB0 Press to Feed
{
count = 0 ;
Change_Duty(255);
PORTB.F3= 1; // ON ==> RB3
sound_play(2000,500); // 2 kHz sound ON RC0 at 100 ms
Motor_A_FWD() ;
Delay_ms(2000); // 4s
//Motor_A_Off() ;
//while(count < 3)
//{
//Delay_ms(1000); // delay 5 s
//sound_play(1000,500);
//count ++ ;
//}
Motor_A_BWD();
Delay_ms(2000); // 4s
Motor_A_Off();
PORTB.F3=0;
}
else if(PORTA.F4==0) // Check RA4 Press to Solenoid In
{
Change_Duty(255);
PORTB.F3=1; // OFF ==> RB3
sound_play(2000,100); // 2 kHz sound ON RC0 at 100 ms
Motor_B_FWD() ;
//Vdelay_ms(pause); // ~ 5 min pause
while(count < 20) // delay 20 s
{
Delay_ms(1000);
sound_play(1000,500);
count ++ ;
}
Motor_B_Off() ;
PORTB.F3=0;
}
Delay_ms(1000);
}
}