project using pic16F690 and 2 x 16 LCD

Discussion in 'Embedded Systems and Microcontrollers' started by yogenchaulagain, Oct 26, 2013.

  1. yogenchaulagain

    Thread Starter New Member

    Jun 3, 2013
    I am new to this forum and just started studying electronics gotta project to build system that takes a message from a PC unit and then sends the message to a PIC and then displays the message on an LCD using pic16F690,max232 and 2 x 16 LCD
    Project includes
    1)develop a program that displays a message on a LCD when button RA1 is pressed.

    2) develop wiring diagrams to connect the PIC to a PC and convert the PC voltage levels to PIC based voltage levels using a MAX232C chip.

    3) develop a program that receives a message through the PIC RS232c communication port when button RA2 is pressed (you can use hyper terminal to test this program).
    7) develop wiring diagrams to connect the PC to a PIC and convert the PC voltage levels to PIC based voltage levels using a MAX232C chip.

    8)connect the PIC to the PC and display a PC information on the LCD display

    I built the circuit and it works fine with computer. I am having trouble to connect LCD to pic16F690. my MPLAB codes are given below. I just compiled it and it works. don't know much about coding though.

    Code ( (Unknown Language)):
    2. #define _LEGACY_HEADERS
    3. #include <htc.h>
    4. #include "lcd.h"
    5. #include <stdio.h>
    6. #include "usart.h"
    7. void pause( unsigned short usvalue ); //Establish pause routine function
    8. unsigned char b0,input,count;
    9. #define number 0x30
    11. void main(void)
    12. {
    13. ANSEL = 0; // Set PORTA all Digital
    14. ANSELH = 0;
    15. CM1CON0 = 0; // Comparator 1 off
    16. CM2CON0 = 0; // Comparator 2 off
    18. TRISA = 0; // All PORTA Outputs
    19. TRISC = 0; // All PORTC Outputs
    21. lcd_init(); // Initialize LCD Display
    22. INTCON=0; // purpose of disabling the interrupts.
    23. init_comms(); // set up the USART - settings defined in usart.h
    24. // running LCD
    26. while (1==1)
    27. {
    28. lcd_clear(); // Clear LCD screen
    29. lcd_goto(0); // select first line
    31. for (b0=0; b0<10; b0=b0+1) // Create counting loop
    32. {
    33. lcd_putch(b0+number); // Display count on LCD
    34. pause (250); // Delay 250 msec to see count
    35. }
    36. lcd_goto(0x40); // Select second line
    38. lcd_puts("Hello World"); // Display Hello World
    39. pause (1000); // Delay for 1 second to read display
    40. }
    41. while(1)
    42. {
    44. for (count = 0x31; count <= 0x39; count = count +1)
    45. {
    46. putch(count); // Send Count in ASCII
    47. input = getch(); // Read a response from the user
    48. putch(input); // Echo back response
    49. }
    50. while(1)
    51. {
    52. printf("Press a key and I will echo it back:\r\n");
    53. input = getch(); // read a response from the user
    54. printf("I detected [%c]\r\n",input); // echo it back
    55. }
    56. }
    57. }
    Could you help me out please.
    Thank You.
    Last edited by a moderator: Nov 2, 2013
  2. JohnInTX


    Jun 26, 2012
    What, specifically, is not working?

    By 'Works fine with computer' do you mean it works with Proteus or some other simulator?

    Does the LCD show anything (other than boxes when you work the contrast control)? Does the LCD display anything at all (characters but the wrong ones etc?)

    Do the comms work?

    Please use CODE tags on your code to make it easier to read.
  3. yogenchaulagain

    Thread Starter New Member

    Jun 3, 2013
    Hello JohnInTX,

    When i compile it, it doesn't show any error. I loaded program in the micro controller but doesn't show any thing on LCD just light and black square boxes.... where it should come up with messeges.

    I am also trying to update code to communicate with pc using RS232 but don't know where to start.
    I am stuffed.
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    You are probably much better off using the native compiler functions for delays. They are __delay_ms(xx) and __delay_us(xx), look them up in the manual. But remember to use the "#define _XTAL_FREQ = 4000000" statement. The default internal osc frequency is 4Mhz(4000000 Hz).
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    "When i compile it, it doesn't show any error" does not mean your program is correct. It merely means you did not make any syntax errors.

    Your best move is to remove any code NOT related to putting "HELLO WORLD" onto that LCD. Once you can see that you've crested the hump and can start using the LCD to debug other code.

    Speaking of debug, do you have a debugger? If you have a PICkit then you do. These can be used to watch the code in your PIC run inside your project. That is great for seeing what is actually happening.

    An LCD works completely statically, meaning you can single step the code and make sure every line has the correct value; all you need is a DVM, or even an LED.

    Do you have the pot on the LCD? Do you have a schematic of the project?
  6. JohnInTX


    Jun 26, 2012
    That would be the first thing, for sure.

    Check the compiler library documentation to ensure that you have the LCD wired like the library expects.
    Next, break things into small parts and debug each one.
    Init PORTB unless that is done by the LCD code..

    If you can, add an LED to an unused output and turn it on after initializing IO. When it lights, you know that the processor is running (at some speed-double check the oscillator settings in CONFIG).

    If you have a PICkit debugger, learn to use it to step through your code, use breakpoints etc. Starting simple with turning on an LED is enough to learn the debugging process.

    Get the button working next. Write a simple loop to turn the LED on/off with button pushes. This will validate lots of things. Once working, set it aside (comment out the button code).

    Init the LCD and write one character to it per RESET. Don't go any further than that until its working.
    Once it is, write two characters to verify inter-character timing.
    Then use the put string functions to finish debugging the LCD.
    Once you have it working, you can use the LCD as a debug aid.

    Add the button back in and have it display something when you press the button. Debug fully.

    For the RS232 - same thing. Check it out by itself.
    First, remove the PIC and jumper RX and TX at the PIC pins. Verify the comms link by typing characters at the terminal. Fix any problems there first.
    Then, like the LCD, write a simple routine that just waits for a character to be received then writes it right back to the terminal. That will debug the baud rate and comms settings. Pay attention to any IO port settings
    Make sure printf etc. are using the UART as the default device (check the library docs). Some compilers require you to provide putc and getc functions to hook printf/scanf to a hardware device (stdout and stdin).

    Once each module (LCD, comms etc) are working, start adding them to the system.

    Good luck.

    EDIT: ErnieM types faster than I do.. Looks like we're thinking along the same lines, though.
    Last edited: Nov 2, 2013
  7. GopherT

    AAC Fanatic!

    Nov 23, 2012
    Do you have the LCD connected correctly with a POT to control contrast?
  8. Brownout

    Well-Known Member

    Jan 10, 2012

    Ah yes, excellent point. Don't believe any literature that says you can just connect constast control to ground. It won't work. Been there, done that.
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Actually, it depends. I have one LCD that does not need the pot, and apparently leaves the contrast pin unconnected. So with that unit yes, you can actually ground the contrast pin and it all works fine.

    While I quite prefer that set up, I've only seen it in the one part, and when I build one of these I always start with the pot in place, and DNP if I later learn it is not necessary.
  10. Brownout

    Well-Known Member

    Jan 10, 2012
    That's the kicker. One just can't depend on that working. Better to set it up correctly and leave luck for the lottery ticket.
  11. John P

    AAC Fanatic!

    Oct 14, 2008
    But aren't the "light and black square boxes" an indication that the LCD is powered, and its screen is viewable, but no data has been loaded? If anything shows on the display, I'd assume that it's turned on, but either the wiring to it isn't right, or the logic, or the timing in the control lines.
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    I believe I already covered this.
  13. yogenchaulagain

    Thread Starter New Member

    Jun 3, 2013
    Thanks guys. Wish me all the best. I have to present it 2moro. I connected LCD and pic kit using forum guide and chuck hellebuyck's books. looks alrite to me. hope fully it works.
    Once again thank you very much.
  14. JohnInTX


    Jun 26, 2012
    Good luck!

    Let us know how it worked.