help usart and LCD

Status
Not open for further replies.

justas12

New Member
Hi, i am working with RFID project, but im not good in programming. The deal is that i have source code, where read rfid card bits are send to usart, but i dont need it. I need to send it to LCD. Idont know how to configure lcd. can anyone help me and edit the source code?
 

Attachments

  • RFID.c
    9.1 KB · Views: 532
Last edited:
Look below for a example from Mikro C Pro:

Code:
/*
 * Project name:
     Lcd_Test (Demonstration of the LCD library routines)
 * Copyright:
     (c) Mikroelektronika, 2008.
 * Revision History:
     20080930:
       - initial release;
 * Description:
     This code demonstrates how to use LCD 4-bit library. LCD is first
     initialized, then some text is written, then the text is moved.
 * Test configuration:
     MCU:             PIC16F887
     Dev.Board:       EasyPIC5
     Oscillator:      HS, 08.0000 MHz
     Ext. Modules:    LCD 2x16
     SW:              mikroC PRO for PIC
 * NOTES:
     - Turn on LCD backlight switch (SW9.7) on development board.(board specific)
*/

// 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(){
  ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 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();
    }
  }
}

You should notice the bits at the top which define where the LCD is connected and the port direction.
Code:
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;

Then this:
Code:
Lcd_Init();                        // Initialize LCD
will replace the UART1_Init() routine.
Then you can use LCD_Out to write the text out to the LCD.

Definition of the LCD_Out:
Code:
void Lcd_Out(char row, char column, char *text);

LCD_Cmd writes a command to the LCD display.

This is defined as:
Code:
void Lcd_Cmd(char out_char);
where out_char is the command, and is one of the following:
Code:
Lcd Command Purpose 
_LCD_FIRST_ROW Move cursor to the 1st row 
_LCD_SECOND_ROW Move cursor to the 2nd row 
_LCD_THIRD_ROW Move cursor to the 3rd row 
_LCD_FOURTH_ROW Move cursor to the 4th row 
_LCD_CLEAR Clear display 
_LCD_RETURN_HOME Return cursor to home position, returns a shifted display to its original position. Display data RAM is unaffected. 
_LCD_CURSOR_OFF Turn off cursor 
_LCD_UNDERLINE_ON Underline cursor on 
_LCD_BLINK_CURSOR_ON Blink cursor on 
_LCD_MOVE_CURSOR_LEFT Move cursor left without changing display data RAM 
_LCD_MOVE_CURSOR_RIGHT Move cursor right without changing display data RAM 
_LCD_TURN_ON Turn Lcd display on 
_LCD_TURN_OFF Turn Lcd display off 
_LCD_SHIFT_LEFT Shift display left without changing display data RAM 
_LCD_SHIFT_RIGHT Shift display right without changing display data RAM

Note, all of the above was taken from the Mikro C Manual, so it's very easy to find.

Hope this helps!

Wilksey.
 
Please kindly mention which Microcontroller and compiler you are using. Also can you post your project's circuit diagram (where you have the LCD connected etc)
 
i use pic18fxxx i dont really remember, firstly i tried with pic16f887, but ai need 32Mhz, so i changed it and now there is pic18fxxx. i use mikroc compiler
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…