Hello Friends,
I am using MCB-STR9 Vers.4 board and µvision4. i want to send one character form com1 from my board and display on hyperterminal. if my board is receive some thing then it ll clear lcd. Sending is working perfecty but receving is not working. i was found the sending programme from keil blog(http://www.keil.com/forum/8493/) directly and the added one more loop for receving which is not working.
#include <91x_lib.h> #include "LCD.h" void sendchar(char ch); int receivechar(void); int retval=0;
void wait (void) { /* Wait function */ long d=950000L;/* 950,000 gives a delay of about 1 sec*/ while (d--); /* Only to delay for LED flashes */ }
void wait1 (void) { /* Wait function */ long d=9500000L; /* 950,000 gives a delay more then 1 sec. */ while (d--); }
int main (void) { unsigned int i; SCU->GPIOOUT[7]=0x5555;/* P7.0..7 output - mode 1 */ GPIO7->DDR= 0xFF;/* P7.0..7 Outputs (LED Data)*/
/* LCD setup*/ GPIO8->DDR=0xFF;/* P8.0..7 Outputs (LCD Data)*/ GPIO9->DDR= 0x07;/* P9.0..2 Outputs (LCD Control)*/
/* UART0 Setup*/ SCU->GPIOOUT[3]&=0xFFF3;/* Enable UART0_TX (COM1) connected to P3.1, by setting bits 6 & 7 to 0 first */
SCU->GPIOOUT[3] |= 0x0008;/* then by setting bit 7 to 1, this sets GPIOOUT[3] to "Alternate Output 2" */
SCU->GPIOIN[3] |= 0x01;/* Enable UART0_RX (COM1) connected to P3.0, by setting bit 0 to 1, this sets GPIOIN[3] to "Alternate Input 1" */
UART0->IBRD = 0x0D;/* Integer divider for 115kBaud when BRCLK=24MHz*/ UART0->FBRD = 0x01;/* Fractional divider */ UART0->LCR = 0x0060;/* 8 bits, no Parity, 1 Stop bit, FIFO disabled */ UART0->CR = 0x0301;/* Enable UART, Receive Enable, Transmit Enable */
lcd_init(); lcd_clear(); lcd_print (" UART "); set_cursor (0, 1); lcd_print (" Sept. 16,2010 "); for (i = 0; i < 5; i++) wait();/* Wait for initial display */
while (1) { /* Loop forever */
sendchar('c'); wait1();
retval=receivechar(); if(retval==0x61) /* received caharcter is "a then it´ll clead the lcd" */
{ lcd_clear(); wait(); } } }
void sendchar (char ch) { /* Debug output to serial port. */
if (ch == '\n') { while (!(UART0->FR & 0x0080)); UART0->DR = '\r'; } UART0->DR =ch; /* output DR */ }
int receivechar (void) { return(UART0->DR); /* input from UART0_DR */ }
i am not abble to find whether it´s a problem is with my code or with my hadware or something else. i am very glad if someone is help me to solve this problem. thanks in advance.