P16F1827 and LCD Problems


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Location
    Michigan
    Posts
    31

    Default P16F1827 and LCD Problems

    I am new to all of this:
    I have triple checked my wiring to the PIC<16F1827> and LCD as follows:

    PIC LCD
    RB0 = D4
    RB1 = D5
    RB2 = D6
    RB3 = D7
    RB4 = RS
    RB5 = E
    The R/W is tied to ground. VCC = +5 volts.
    I have tried just about every sample program I could find on this forum and they will either not compile (Pic Basic Pro) or I could not figure out the correct ports to change around to match my configuration. I am using a PICKIT3 to program with and it does see and properly identify my chip.
    Would be wonderful if someone could point me at some proper sample code to just initialize the LCD.... let alone make it say hello.
    I have not done any PIC programming, and haven't done much basic programming since the days of my Atari 800. Most of the compile errors I was receiving were stating that "Program" was expected. Newbie error I guess.
    Some one please re-aim my compass

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you post the code you have along with your config settings?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2010
    Location
    Michigan
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Here is the latest code I have been trying to build.
    And this is the error message I receive :
    3 304 Syntax error: Expected "program" but "module" found TEST.mbas

    '*Header****************************************** ************/

    module TEST
    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

    unsigned char ch; //
    unsigned int adc_rd; // Declare variables
    char *text; //
    long tlong; //

    void main() {
    INTCON = 0; // All interrupts disabled
    ANSEL = 0x04; // Pin RA2 is configured as an analog input
    TRISA = 0x04;
    ANSELH = 0; // Rest of pins are configured as digital

    Lcd_Init(); // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

    text = "mikroElektronika"; // Define the first message
    Lcd_Out(1,1,text); // Write the first message in the first line
    text = "LCD example"; // Define the second message
    Lcd_Out(2,1,text); // Define the first message

    ADCON1 = 0x82; // A/D voltage reference is VCC
    TRISA = 0xFF; // All port A pins are configured as inputs
    Delay_ms(2000);

    text = "voltage:"; // Define the third message

    while (1) {
    adc_rd = ADC_Read(2); // A/D conversion. Pin RA2 is an input.
    Lcd_Out(2,1,text); // Write result in the second line
    tlong = (long)adc_rd * 5000; // Convert the result in millivolts
    tlong = tlong / 1023; // 0..1023 -> 0-5000mV
    ch = tlong / 1000; // Extract volts (thousands of millivolts)
    // from result
    Lcd_Chr(2,9,48+ch); // Write result in ASCII format
    Lcd_Chr_CP('.');
    ch = (tlong / 100) % 10; // Extract hundreds of millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    ch = (tlong / 10) % 10; // Extract tens of millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    ch = tlong % 10; // Extract digits for millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    Lcd_Chr_CP('V');
    Delay_ms(1);

    Bob

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Try asking here mikroC PRO for PIC General
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bobw55 View Post
    Here is the latest code I have been trying to build.
    And this is the error message I receive :
    3 304 Syntax error: Expected "program" but "module" found TEST.mbas

    '*Header****************************************** ************/

    module TEST
    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

    unsigned char ch; //
    unsigned int adc_rd; // Declare variables
    char *text; //
    long tlong; //

    void main() {
    INTCON = 0; // All interrupts disabled
    ANSEL = 0x04; // Pin RA2 is configured as an analog input
    TRISA = 0x04;
    ANSELH = 0; // Rest of pins are configured as digital

    Lcd_Init(); // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

    text = "mikroElektronika"; // Define the first message
    Lcd_Out(1,1,text); // Write the first message in the first line
    text = "LCD example"; // Define the second message
    Lcd_Out(2,1,text); // Define the first message

    ADCON1 = 0x82; // A/D voltage reference is VCC
    TRISA = 0xFF; // All port A pins are configured as inputs
    Delay_ms(2000);

    text = "voltage:"; // Define the third message

    while (1) {
    adc_rd = ADC_Read(2); // A/D conversion. Pin RA2 is an input.
    Lcd_Out(2,1,text); // Write result in the second line
    tlong = (long)adc_rd * 5000; // Convert the result in millivolts
    tlong = tlong / 1023; // 0..1023 -> 0-5000mV
    ch = tlong / 1000; // Extract volts (thousands of millivolts)
    // from result
    Lcd_Chr(2,9,48+ch); // Write result in ASCII format
    Lcd_Chr_CP('.');
    ch = (tlong / 100) % 10; // Extract hundreds of millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    ch = (tlong / 10) % 10; // Extract tens of millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    ch = tlong % 10; // Extract digits for millivolts
    Lcd_Chr_CP(48+ch); // Write result in ASCII format
    Lcd_Chr_CP('V');
    Delay_ms(1);

    Bob

    http://forums.basicmicro.net/feedbac...ead-t9279.html
    Last edited by mark_s; - 19th January 2011 at 22:07. Reason: Wrong

  6. #6
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default 1333

    Hi;
    That program is writen in MicroC. It will not work in PBP.

    Regards
    Thanks and Regards;
    Gadelhas

  7. #7
    Join Date
    Dec 2010
    Location
    Michigan
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    I knew it had to be something supidly simple. I have been looking at and trying to understand some of the coding, they all start to look the same to me. Have to see if I can compile it with MPLAB.


    THANKS

  8. #8
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    No, you will not be able to compile that program with MPLAB, only with MicroC.
    Thanks and Regards;
    Gadelhas

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bobw55 View Post
    I am new to all of this:
    I have triple checked my wiring to the PIC<16F1827> and LCD as follows:

    PIC LCD
    RB0 = D4
    RB1 = D5
    RB2 = D6
    RB3 = D7
    RB4 = RS
    RB5 = E
    The R/W is tied to ground. VCC = +5 volts.
    I have tried just about every sample program I could find on this forum and they will either not compile (Pic Basic Pro) or I could not figure out the correct ports to change around to match my configuration. I am using a PICKIT3 to program with and it does see and properly identify my chip.
    Would be wonderful if someone could point me at some proper sample code to just initialize the LCD.... let alone make it say hello.
    I have not done any PIC programming, and haven't done much basic programming since the days of my Atari 800. Most of the compile errors I was receiving were stating that "Program" was expected. Newbie error I guess.
    Some one please re-aim my compass
    Hello Bob,
    To be clear, you DO / Do Not have the Pic Basic Pro compiler from MeLabs?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  10. #10
    Join Date
    Dec 2010
    Location
    Michigan
    Posts
    31


    Did you find this post helpful? Yes | No

    Talking

    I only have the demo version which does NOT support the 16F1827.
    I have:
    MPLAB 8.63 PICKIT3
    MikroBasic
    MikroC-Pro
    MikroPro-Suite

    I found the Assembly template file for the 16F1827 and will start using that to build with.
    From my reading last night I figured out that I have to define or tell the program the pinout of the LCD to the PIC. Set the LCD for 4bit High nibble, then I can send the initialization string to it. (I think)
    My first goal is just to get it to Initialize.
    Second Print some text.
    Third read and display the value of a switch.
    I will do this, even if it takes a sledge hammer

  11. #11
    Join Date
    Dec 2010
    Location
    Michigan
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Getting there

    Managed to get some code written and displayed.

    THANK YOU ALL FOR THE POINTERS


    Bob
    Attached Images Attached Images  

  12. #12
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default



    Awesome Bob!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  13. #13
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Well Done Bob!
    Thanks and Regards;
    Gadelhas

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts