سلام عليكم
اخواني عندي مشكلة في ارسال البيانات عبر uart
اذا ارسلت كلمة hasan مفروض تظهر على بورت d قيمة 0xaa لمدة ثانيه وبعدها ينطفئ
مشكلة هي\
اذا ارسل اول مرة كلمة hasan يعمل بشكل طبيعي ويرسلي كلمة yes
ولكن بعدها من أعيد ارسال كلمة مرة اخرى لايقبلها ويرسل كلمة no
وبعد محاولة خامسه يقبل كلمه
اي اذا قبل كلمه فان بعدها لازم ارسل كلمة 5 مرات حتى يقبلها مرة اخرى
ارجو بيان هل يوجد مشكله في كود
علما جربت ذلك عملي وكانت نفس نتيجة!
http://arabsh.com/files/0c374d4f6cf5/uart_test-rar.html
هذا هو كود
كود:
/*
* Project name:
UART (Simple usage of UART module library functions)
* Copyright:
(c) Mikroelektronika, 2011.
* Revision History:
20110929:
- initial release (FJ);
* Description:
This code demonstrates how to use uart library routines. Upon receiving
data via RS232, MCU immediately sends it back to the sender.
* Test configuration:
MCU: PIC18F45K22
http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
Dev.Board: EasyPIC7 - ac:UART
http://www.mikroe.com/easypic/
Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
Ext. Modules: None.
SW: mikroC PRO for PIC
http://www.mikroe.com/mikroc/pic/
* NOTES:
- Turn on RX and TX UART switches (SW1.1 and SW2.1). (board specific)
- Put RX and TX UART jumpers (J3 and J4) in RS-232 or USB position,
depending on your choice (board specific).
*/
char uart_rd , x=0;
char output[5];
void interrupt()
{
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
//UART1_Write(uart_rd); // and send data via UART*/
output[x]=uart_rd;
x++;
}
}
void main() {
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1; // enable all interrupts
ANSELC = 0; // Configure PORTC pins as digital
ANSELd = 0; // Configure PORTd pins as digital
trisd=0;
portd=0;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
UART1_Write_Text("Start");
UART1_Write(13);
UART1_Write(10);
while (1)
{
if(x==5)
{ x=0;
if(output[0]=='h' && output[1]=='a' && output[2]=='s' && output[3]=='a' && output[4]=='n') //hasan
//if( uart_rd=='a')
{
portd=0xaa;
UART1_Write_Text("yes");
delay_ms(1000);
portd=0;
delay_ms(1000);
}
else UART1_Write_Text("NO");
UART1_Write(13);
UART1_Write(10);
}
}
}