Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Serial communication using USART

Status
Not open for further replies.
I enabled the local echo option.

Disable the "Local Echo" option. If the the test is successful you should see exactly what you type, no more, no less.


I connected the 2 and 3 pins of the db9 using screwdriver.

If you look closely inside the connector around the pins of the DB9 you should see each pin marked with the actual pin number.

BigDog
 

What are the correct settings that I should give in the hyperterminal? Is this procedure correct?
*Gave a name.
*Selected com1 port
*Bits per second----9600, Databits-8, Parity--None,Stop bits---1, Row control---none
*In the properties window I selected the "settings" tab and then "ascii" button and enabled "local echo".
*Then I typed in the hyperterminal.
 

Do NOT enable "local echo".

Is this a serial port onboard the motherboard, connector physically attached to the motherboard?

If so have you check the BIOS settings to ensure the serial port is enabled.

Do you have any other serial ports installed in the system?

BigDog
 
  • Like
Reactions: iVenky

    iVenky

    Points: 2
    Helpful Answer Positive Rating
Working :)

---------- Post added at 19:23 ---------- Previous post was at 19:22 ----------

I used connecting wire and checked and it was working perfectly. Guess my screwdriver is so rusted.
 

Good.

I usually use a F/F jumper wire or a special loopback cable I've made.

If you still have problems with your code, you may want to write a short routine which outputs a test string to the hyperterminal.

If you can successfully transmit a short message from the MCU to the PC, you know your BAUD rate, and physical connections are setup correctly.

BigDog
 

After giving the necessary connections I typed in the hyperterminal. I am getting the output but each character overwrites the previous one and the lcd screen shows one character.
For eg: If I type "venkat"
the output is 'v' and then it gets overwritten and becomes 'e' and so on. In the end the output is 't' only. Where does the problem lie? I have given the code in the first page itself.
 

Look at your while(1) loop:

while(1)
{
value=usart_getch(); // Call a function to get data from serial port
LCD_cmd(0xC0); // to go in second line and zeroth position on LCD
LCD_write(value); // write data to LCD
}

The statement in red continuely repositions the cursor to the same location, effectively writing the next character over the top of the previous character.

Try move this statement outside the while(1) loop just before you enter the loop.

BigDog
 

if you enable the echo,even without shorting you will get the typed characters.... that is not the way of testing..... you should disable the echo and see that you should get all the characters you type....

if you enable echo the if you type "a", then you should see two times "a" being typed....

make sure the concepts as i have told..... i guess how people missed you to tell this concept...

take a multimeter and see that both ends of pins 2 should be short, and pin 3 at both ends should be shorted and pin 5 at both ends should also show short....
 

I don't know what happened but the same program is not working at all. I have been trying to figure out but in vain. The cursor goes to next line but it doesn't display the character. It's just blank. The first program which worked before is also not working this time. What should be the problem?

---------- Post added at 21:53 ---------- Previous post was at 21:53 ----------

if you enable the echo,even without shorting you will get the typed characters.... that is not the way of testing..... you should disable the echo and see that you should get all the characters you type....

if you enable echo the if you type "a", then you should see two times "a" being typed....

make sure the concepts as i have told..... i guess how people missed you to tell this concept...

take a multimeter and see that both ends of pins 2 should be short, and pin 3 at both ends should be shorted and pin 5 at both ends should also show short....

No problem with the port. I have checked with echo also. I got two times.

---------- Post added at 21:56 ---------- Previous post was at 21:53 ----------

The same program is not working this time. The cursor goes to the next line when I press the key but after that write function is not working properly and I don't get any output.
Waiting for your response.
 

remove the lcd and write a simple program to send message to hyperterminal.... then write a program to receive data typed on hyperterminal, while displaying the data on hyperterminal.. write a lcd program and get the result, then combine lcd and serial receive program...

post your entire program and circuit.....
 

The same program is not working this time. The cursor goes to the next line when I press the key but after that write function is not working properly and I don't get any output.

If you are referring to the code you listed at the beginning of the discussion thread, your problem is most likely the state of the LCD controller.

Try powering down the entire circuit, wait a few minutes and power it back up. This should allow the LCD controller to return to the correct initial state.

Then test your design with the same code and see if it displays the same results you described previously.

As I mentioned before you need to change the contents of your loop and the way the LCD is initialized prior to displaying text.

BigDog
 

Actually I tried with two different lcds and I got the same problem. This is the condition of my lcd 16 x 2
*Once I switch on the power I see the cursor in the first row.
*When I type the character in the hyperterminal the cursor goes to the next row. After that nothing happens though I type in hyperterminal.
I have checked the port and there is no problem with port or db9. The same program worked in the beginning. Please help me.
 

What do you mean by power the entire circuit? I took off the supply, then waited for a few minutes and gave the supply again.
 

That is exactly what I mean. So no difference?

Did you try moving the statement I pointed out earlier outside of the loop, putting it just before the loop?

BigDog
 

Ok,

You now know your UART code section was functioning correctly. So put your code to the side and run MikroE's LCD example modifying it to fit your design.

Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC5";
char txt3[] = "Lcd4bit";
char txt4[] = "example";
char i; // Loop variable
void Move_Delay() { // Function used for text moving
      Delay_ms(500); // You can change the moving speed here
      }

void main(){
      TRISB = 0;
      PORTB = 0xFF;
      TRISB = 0xff;
      ANSEL = 0; // Configure AN pins as digital I/O
      ANSELH = 0;
      Lcd_Init(); // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR); // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
      Lcd_Out(1,6,txt3); // Write text in first row
      Lcd_Out(2,6,txt4); // Write text in second row
      Delay_ms(2000);
      Lcd_Cmd(_LCD_CLEAR); // Clear display
      Lcd_Out(1,1,txt1); // Write text in first row
      Lcd_Out(2,5,txt2); // Write text in second row
      Delay_ms(2000);
      // Moving text
      for(i=0; i<4; i++) { // Move text to the right 4 times
          Lcd_Cmd(_LCD_SHIFT_RIGHT);
          Move_Delay();
      }

      while(1) { // Endless loop
          for(i=0; i<8; i++) { // Move text to the left 7 times
          Lcd_Cmd(_LCD_SHIFT_LEFT);
          Move_Delay();
      }
      for(i=0; i<8; i++) { // Move text to the right 7 times
          Lcd_Cmd(_LCD_SHIFT_RIGHT);
          Move_Delay();
      }
   }
}

MikroC LCD library example.

Sorry about the formatting, but you should be able to copy and paste directly from the user manual.

If the hardware is setup correctly you should be able to modify the above example code and have it display the text correctly.

Once this has been done, we know the problem is in your code and we can debug it.

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
What is this? I don't know anything about MikroC LCD. What should I do with that code?

---------- Post added at 09:59 ---------- Previous post was at 09:57 ----------

As far as my program is concerned I think the problem lies in the write statement.

value=usart_getch(); // Call a function to get data from serial port
LCD_cmd(0xC0); // to go in second line and zeroth position on LCD
LCD_write(value); // write data to LCD

The first two lines are working because the cursor goes to the next line once I type some character in the hyperterminal. So the problem should lie after those two lines which is the write statement.

---------- Post added at 10:01 ---------- Previous post was at 09:59 ----------

But the one thing that I couldn't understand is this- the same program worked in the beginning.
 

What is this? I don't know anything about MikroC LCD. What should I do with that code?

I apologize your function calls look similar to MikroC Pro Compiler for AVR.

As far as my program is concerned I think the problem lies in the write statement.

value=usart_getch(); // Call a function to get data from serial port
LCD_cmd(0xC0); // to go in second line and zeroth position on LCD
LCD_write(value); // write data to LCD

The first two lines are working because the cursor goes to the next line once I type some character in the hyperterminal. So the problem should lie after those two lines which is the write statement.

Ok. What I was attempting to do was cut down the code to the bare minimum and see if your LCD routines could successfully display a simple text message.

Can you write a simple program using your routines and display a 5 or 6 letter word on the LCD?

This would answer several questions I have.


But the one thing that I couldn't understand is this- the same program worked in the beginning.

Yes, that is troubling and another reason I want you to display a word on the LCD with only the necessary routines.

Give it a try and let me know the results.

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Now Lcd is not even getting initialized. I tried "display characters in lcd" program and that is not even working right now. I have to give connections from the beginning I believe.

I have another doubt I often get this when I burn "hfuse changed from c9 to ff do you want to change it back y/n?" What is this? and what should I do? y/n?

---------- Post added at 11:18 ---------- Previous post was at 11:17 ----------

I won't be doing anything now. I will post once I have finished from the beginning.

---------- Post added at 12:21 ---------- Previous post was at 11:18 ----------

I tried displaying "Welcome" in lcd and it worked.
My lcd is acting kind of wierd.
Now when I type in hyperterminal I get some other character in the lcd. That too it is taking so much time to display the string and it is absurd.

---------- Post added at 14:06 ---------- Previous post was at 12:21 ----------

Waiting for your reply.

---------- Post added at 14:07 ---------- Previous post was at 14:06 ----------

As I have told you in the previous post when I type in hyperterminal lcd is showing some other character (some kind of symbol). What should be the problem?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top