Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Second line on LCD using XC8 and PIC16F877A

Status
Not open for further replies.
If you want help you need to give a lot more information on what you are doing and how you are trying to do it.
Sending the command 0xC0 does not move the cursor to the next line. 0xC0 will move it to address 0x40. Bit 7 defines the command to move to the display address defined in bits 0 to 6. The position of an address on a display depends on how many rows the display has and the number of characters per row. (And possibly the manufacturer of the display.) You will need to look at the data sheet for your display to find out the layout of addresses.

Les.
 
If the LCDinit() hasn't enabled the second line, then it won't be available..

Delay 15ms
LCDcmd(0x33); // 8bit interface..
Delay 5ms
LCDcmd(0x33); // 8 bit interface..
Delay 5ms
LCDcmd(0x38); // Function set.... 8bit + 2 line + 5x10 font
LCDcmd(0xC); // Display set... Disp on + cursor off + blink off..
LCDcmd(0x6); // Entry set... Increase cursor direction+ no shift

If you miss out 0x38 ( or 0x28 on a 4 bit ) then the second line isn't available..
 
i am using these header files and i am getting trouble in moving cursor to next line.
 

Attachments

  • XLCD.c
    2.2 KB · Views: 202
  • XLCD.h
    2 KB · Views: 238
  • main.c
    1.8 KB · Views: 231
I can't help you programming in "C" I have only written code for LCD displays in assembler.

Les.
 
C:
#include <xc.h> //CONFIG
#include <stdio.h>
#include <stdlib.h>
#include "XLCD.h"
#define _XTAL_FREQ 1000000 // if 8Mhz is HS

#pragma config FOSC = XT // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

unsigned int hienled (void);
unsigned char buffer[20];
unsigned long ADCvalue = 0;
unsigned int voltage;
int x;

void ADCinit (void)// khoi tao adc
   { // chon tan so clock cho bo adc
   ADCS2 = ADCS1 = 0;
   ADCS0 = 1; // chon kenh adc la kenh an0
   CHS2 = CHS1 = CHS0 = 0; // chon cach luu data
   ADFM = 1; // cau hinh cong vao
   PCFG3 = PCFG2 = PCFG1 = 1;
   PCFG0 = 0; // cap nguon cho khoi adc
   }

unsigned int hienled (void)// doc led 7 doan
   {
   ADON = 1;
   GO = 1;
   delayUs(100);
   while(GO);
   return (int)ADRESH*256 + ADRESL;
   }
void main()
   {
   TRISA = 0xff;
   LCD_PORT = 0;
   TRIS_LCD_PORT = 0x00;
   TRIS_RW = TRIS_RS = TRIS_E = 0;
   ADCinit();
   OpenXLCD(0x28);
   while(1)
     {
     ADCvalue = hienled();
     voltage = ADCvalue * 5000 / 1023 ;
     x = voltage / 10 ;
     sprintf(buffer," TEMP = %d%c",x,0xDF);
     SetCGRamAddr(0);
     putsXLCD(buffer);
    OpenXLCD(0xc0);
     putsXLCD("Temperature Sensor");
     SetCGRamAddr(0);
     putsXLCD(buffer);

     }
   }
 
Last edited by a moderator:
Not OpenXLCD(0xC0)..

Use WriteCmdXLCD(0xC0); If you re open the LCD it won't work properly...

C:
while(1)
     {
     ADCvalue = hienled();
     voltage = ADCvalue * 5000 / 1023 ;
     x = voltage / 10 ;
     sprintf(buffer," TEMP = %d%c",x,0xDF);
     SetCGRamAddr(0);
     putsXLCD(buffer);
     WriteCmdXLCD(0x0);
     putsXLCD("Temperature Sensor");
     WriteCmdXLCD(0xC0);
     putsXLCD(buffer);
     }
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top