P16F1827 and LCD Problems


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1


    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

Members who have read this thread : 0

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