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.

problem in MikroC coad for LCD

Status
Not open for further replies.
Hi!

i am using mikoC PRO for PIC v5.6.1 and programming a 16x2 LCD display using PIC16F877A. wana display data on lcd but getting errors.

since i am in learning process so using engineers garage code.

Code:
#define RS PORTD.F4    //RD4
#define EN PORTD.F5    //RD5
#define Lcdport PORTC  //lcd data pins

void lcd_ini();
void dis_cmd(unsigned char);
void dis_data(unsigned char);
void lcdcmd(unsigned char);
void lcddata(unsigned char);

void main()
{
  TRISD.f4 = 0;
  TRISD.f5 = 0;
  TRISB.f2 = 0x00;
  TRISB.f3 = 0x00;
 // TRISC.f0 =0xff;
 // TRISC.f1 =0xff;
  TRISC=0x00; //portC output

 unsigned char data0[]="Shenztech PvtLtd";
 unsigned int i=0;
 lcd_ini();

  while(1)
  {
  
          for (i=0; i!='\0'; i++)
           {
              dis_data(data0[i]);
              Delay_ms(200);
           
           }
   }
   
}
//..............................;;;;;;;.........................................


void lcd_ini()
{
     dis_cmd(0x02);      // 4 bit mode select
      dis_cmd(0x28);     //2 line; 5x7 display; 4bit mode
       dis_cmd(0x0c);
        dis_cmd(0x06);
         dis_cmd(0x80);    //start from line 1 character 0
}


 //..............................;;;;;;;........................................
 
 void dis_cmd(unsigned char cmd_value)
{
     unsigned char cmd_value1;
     cmd_value1=(cmd_value & 0xf0);   // mask the lower nibble
     lcdcmd(cmd_value1); //send to lcd
      cmd_value1=((cmd_value1<<4) & 0xf0);
      lcdcmd(cmd_value1);
}

//................................;;;;;.........................................

void lcdcmd(unsigned char cmdout)
{
     Lcdport=cmdout;
     
     RS=0;
     EN=1;
     Delay_ms(10);
     EN=0;
}

 //.............................;;;;;;.........................................

void lcddata(unsigned char dataout)
{
     Lcdport=dataout;
     RS=1;
     EN=1;
     Delay_ms(10);
     EN=0;
}



i received the following errors:
View attachment 66163

array deceleration syntax is seem to be ok. but still there is error. any help will be much appritiated.

regards
 
Last edited:
where is the definition for the dis_data()...
Is it declared somewhere else...
 
Last edited:
Please read the MikroC PRO help file. It has a section on the LCD routines and MikroC has excellent LCD routines already built in and they work!

You don't need to make your own LCD routines!
 
where is the definition for the dis_data()...
Is it declared somewhere else...
oh sorry i forget to write its body. thank you
Please read the MikroC PRO help file. It has a section on the LCD routines and MikroC has excellent LCD routines already built in and they work!

You don't need to make your own LCD routines!
i think ....This Library is designed to work with the mikroElektronika's Serial Lcd Adapter Board pinout. i have to redesign my hardware for that. it will not work with my configured pins.
 
code is now ok but i am getting problem in my hardware design.
i've connected upper nibbles of lcd i.e; form pin 11 to 14 to upper nibble of port C of PIC16f877A while rd4 is connected to pin4 (rs) of lcd and rd5 to pin 6 (E) of LCD power pins of lcd are connected to power supply and unused data pins (lower nibble) and R/W pins are directly grounded.

View attachment 66186

but still lcd is not displaying anything; the first line of lcd is full of black squares.
 
unused data pins (lower nibble) dont gnd them left them open...

no it doesn't matter. i used this mikro C code:

Code:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections

void main(){
  TRISB = 0x00;                           // Configure PORTB pins as digital
  PORTB = 0x00;
  
  Lcd_Init();                             // Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR);                    // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);               // Cursor off


  while(1) {                              // Endless loop
       Lcd_Out(1,1,"Shenztech PvtLtd");   // Write text in first row
  }
}

it is built in liabrary codes of mikro C ... and my circuit is funtional now.
 
Yep, that's generally the best way to do it. :)

Congrats. :)

thank you very much Mr RB. But these kind of heavily library dependent software will make us very lazy and we will be ignorant about all the internal workings of the controller. creation of user defined functions for this software also seems to be impossible.
 
Thanks to all for their kind responses. now i fall in to another problem........
i want to monitor 4 inputs of my micro continuously just like interrupt; and perform appropriate action on specific key press. Please see the sanerio in the figure below:
View attachment 66343

here i have four inputs Enter, Reset, Up and Down. during normal operation of controller if i press enter it enters a specific routine that should monitor all the four inputs and perform the specific function specified to it. enter is to enter a specific routine, reset is to get out of the routine, up and down are for scroll the options and/or to increment/decrement the numbers displayed on lcd screen. kindly help me to write down the routine/program for that in MikroC.
thank you
 
is you want to do the software polling of that key press, then you can use the button function...
As the example of that has been given in the library like below :
Example reads RB0, to which the button is connected; on transition from 1 to 0 (release of button), PORTD is inverted:

bit oldstate; // Old state flag

void main() {

ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;

TRISB0_bit = 1; // set RB0 pin as input

TRISC = 0x00; // Configure PORTC as output
PORTC = 0xAA; // Initial PORTC value
oldstate = 0;

do {
if (Button(&PORTB, 0, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition
PORTC = ~PORTC; // Invert PORTC
oldstate = 0; // Update flag
}
} while(1); // Endless loop
}
 
Thank you dj. and how to tackle with "IRP bit must be set manually" problem. i am using pic16f877a and want to perform bank switching. i don't want to use pic18 now for this specific project.
 
Yes IRP bit needs to set for bank 2 and bank3 along with RP1 and RP0 to select particular from one of them....
I hope that is wat you were asking because i didnt understand these statement "IRP bit must be set manually"...
 
it means MikroC compiler do not switch the memory banks automatically like hi-tech compiler of MPLAB. so we have to switch the memory banks manually. it may have some specific microC instructions and may be methods that i don't know and want to know that how to swicth them manually.
 
MikroC compiler is not capable to set IRP bit.
IRP is bank select bit used for indirect addressing.
IRP=0 -> Bank 0,1
IRP=1 -> Bank 2,3

So you must do that manually. Also you can use 'absolute' directive and
move variable at memory banks 0 and 1(directive absolute specifies the starting address in RAM for variable.
If variable is multi-byte, higher bytes will be stored at the consecutive locations).

Best thing is that you can use 18F but as you said for these project you want to use PIC16F only.
That way, you will not have any problems with memory banks.
 
MikroC compiler is not capable to set IRP bit.
IRP is bank select bit used for indirect addressing.
IRP=0 -> Bank 0,1
IRP=1 -> Bank 2,3

So you must do that manually. Also you can use 'absolute' directive and
move variable at memory banks 0 and 1(directive absolute specifies the starting address in RAM for variable.
If variable is multi-byte, higher bytes will be stored at the consecutive locations).

Best thing is that you can use 18F but as you said for these project you want to use PIC16F only.
That way, you will not have any problems with memory banks.

thank you dj. how i use the above given instructions? i.e; at the start of program i use IRP=0 and in the mid of the program i have to use IRP=1????????
 
Status
Not open for further replies.

Latest threads

Back
Top