It is currently 19 Sep 2017 13:26

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: 29 Aug 2017 00:07 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
:cry: :cry: :roll: :roll: Hi friends. I'm trying to initialize the LCD using PORT (a) from RA1 to RA5 plus PORT RE0 (e) using the Mikroc library, but the LCD in this configuration does not boot, in other PORTs like (B), (C), (D) It works normal. My development board is with this hardware configuration, it came with a program recorded on the PIC16F877A that analog input AN0. When you run this program, the LCD will initialize and write on the screen. Do you have any tips to solve this problem? I'm using the PIC16F877A. The code is:

sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA2_bit;
sbit LCD_D4 at RA3_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA5_bit;
sbit LCD_D7 at RE0_bit;

sbit LCD_RS_Direction at TRISA1_bit;
sbit LCD_EN_Direction at TRISA2_bit;
sbit LCD_D4_Direction at TRISA3_bit;
sbit LCD_D5_Direction at TRISA4_bit;
sbit LCD_D6_Direction at TRISA5_bit;
sbit LCD_D7_Direction at TRISE0_bit;

lcd_Init ();
Lcd_Chr_CP ('F');
Lcd_Chr_CP (' ');
Lcd_Chr_CP ('H');
Lcd_Chr_CP ('O');
Lcd_Chr_CP ('L');
Lcd_Chr_CP ('A');
Lcd_Out_CP ("Work");
Lcd_Out (2,1, "You can");
delay_ms (300);
Lcd_Cmd (_LCD_CLEAR);
Lcd_Cmd (_LCD_CURSOR_OFF);
delay_ms (300);
Lcd_Cmd (_LCD_BLINK_CURSOR_ON);
Lcd_Out_CP ("Estudante");
delay_ms(200);
}

I was able to initialize the LCD with this program, but when sending write nothing appears on the screen, it only initializes with the blinking course. But it still does not write on the LCD.

void main()
{

ADCON0 = 0b00000000;
ADCON1= 0b00001110;
TRISA = 0b00000001;
TRISE = 0x00;
PORTA = 0b00000000; // 1º send
PORTE = 0b00000000; // 1º send
//delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00011000; // 2º send
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00011000; // 3º send
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00011000; // 4º send
delay_ms (200);
RA5_bit = 1; // start send
delay_ms(200);
RA5_bit = 0;
//delay_ms(200);
PORTA = 0b00001000; // 5º send
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00001000; // 6º send
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00000010; // 7º envio
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00000000; // 8º send
delay_ms (200);
RA5_bit = 1; // start send
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
PORTA = 0b00011110; // 9º send
delay_ms (200);
RA5_bit = 1; // start Sent
//delay_ms(200);
RA5_bit = 0;
delay_ms(200);
}


Attachments:
File comment: without signal To D4, D5, D6, D7 pins Simulation Proteus
LCDnaoInicializado.JPG
LCDnaoInicializado.JPG [ 131.97 KiB | Viewed 1119 times ]
File comment: Simulation Proteus
LCD_PortsA-E.JPG
LCD_PortsA-E.JPG [ 120.93 KiB | Viewed 1119 times ]
Top
 Profile  
 
PostPosted: 29 Aug 2017 20:56 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 481
Hello,

For this to work on the PORT A, you need a pull up resistor on your RA4 pin. That is because RA4 is open-drain and it can only sink the current, it's unable to set itself high.
One pull up of about 4K7 will solve your issue.

Best regards


Top
 Profile  
 
PostPosted: 29 Aug 2017 22:17 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
Hello darko.ilijevski, thanks for your help.

I had already put the 4k7 resistor on the RA4 pin and it did not work either. My development board has a 10K resistor on the RA4 pin and as I mentioned in the topic, when loading the program that was recorded on the PIC16F877A of the board the LCD works normally, however when placing another program created in the MikroC or even in the CCS, the LCD does not Prints the messages on the screen. It has already been tested with 4k7 and 10k resistors and simulated without working on Proteus or on the development board circuit design is attached.


Attachments:
LCDnaoInicializado2.JPG
LCDnaoInicializado2.JPG [ 115.41 KiB | Viewed 1110 times ]
Top
 Profile  
 
PostPosted: 29 Aug 2017 22:48 
Offline

Joined: 27 Jun 2010 12:07
Posts: 848
Location: England
Your schematic does not tie up with your port definitions:

sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA2_bit;
sbit LCD_D4 at RA3_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA5_bit;
sbit LCD_D7 at RE0_bit;


EDIT: sorry, ignore me. I seem to have gone blind or daft :(


Last edited by hexreader on 30 Aug 2017 14:29, edited 1 time in total.

Top
 Profile  
 
PostPosted: 30 Aug 2017 05:29 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
Hello Joined, thanks for your help. But you don't understood my problem..

My didactic board, has the configuration of hardware already mounted

sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA2_bit;
sbit LCD_D4 at RA3_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA5_bit;
sbit LCD_D7 at RE0_bit;

according to the simulated in Proteus. The LCD works normally with the program that was recorded in PIC16F877A, but it does not boot with any other programs I do and I load the PIC. That is, it works only with the settings of the .hex program originally recorded in the PIC.
See that the LCD initializes and displays data on the screen with the program originally recorded by the card manufacturer.

But don't initialize with my simple program:

sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA2_bit;
sbit LCD_D4 at RA3_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA5_bit;
sbit LCD_D7 at RE0_bit;

sbit LCD_RS_Direction at TRISA1_bit;
sbit LCD_EN_Direction at TRISA2_bit;
sbit LCD_D4_Direction at TRISA3_bit;
sbit LCD_D5_Direction at TRISA4_bit;
sbit LCD_D6_Direction at TRISA5_bit;
sbit LCD_D7_Direction at TRISE0_bit;

lcd_Init ();
Lcd_Chr_CP ('F');
Lcd_Chr_CP (' ');
Lcd_Chr_CP ('H');
Lcd_Chr_CP ('O');
Lcd_Chr_CP ('L');
Lcd_Chr_CP ('A');
Lcd_Out_CP ("Work");
Lcd_Out (2,1, "You can");
delay_ms (300);
Lcd_Cmd (_LCD_CLEAR);
Lcd_Cmd (_LCD_CURSOR_OFF);
delay_ms (300);
Lcd_Cmd (_LCD_BLINK_CURSOR_ON);
Lcd_Out_CP ("Estudante");
delay_ms(200);
}


Attachments:
PUCposGrad.7z [7.67 KiB]
Downloaded 31 times
LCD_PortsA-E_Pot.JPG
LCD_PortsA-E_Pot.JPG [ 125.03 KiB | Viewed 1108 times ]
Top
 Profile  
 
PostPosted: 30 Aug 2017 14:18 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9319
Hi,

Have you tried toggling the Lcd pins (PORTA and PORTE.0) to see if they are properly set as digital ?

Regards,
Filip.


Top
 Profile  
 
PostPosted: 30 Aug 2017 17:38 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 481
Hi,

Try what Filip suggested to verify your pins have good connections, indeed. Also I think that your program does not call the function you have made. You have a main() function where you haven't used the function which would initialize the LCD. Also do not touch TRISA and TRISE, those are taken care of in the library (except the bit for the RA0 which I have set additionally without touching the rest of them)

Try with this code (copy - paste in your compiler)
sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA2_bit;
sbit LCD_D4 at RA3_bit;
sbit LCD_D5 at RA4_bit;
sbit LCD_D6 at RA5_bit;
sbit LCD_D7 at RE0_bit;

sbit LCD_RS_Direction at TRISA1_bit;
sbit LCD_EN_Direction at TRISA2_bit;
sbit LCD_D4_Direction at TRISA3_bit;
sbit LCD_D5_Direction at TRISA4_bit;
sbit LCD_D6_Direction at TRISA5_bit;
sbit LCD_D7_Direction at TRISE0_bit;

void InitMyLCD()
{
  lcd_Init ();
  delay_ms (300);
  Lcd_Cmd (_LCD_CLEAR);
  Lcd_Cmd (_LCD_CURSOR_OFF);
  delay_ms (300);
  Lcd_Chr_CP ('F');
  Lcd_Chr_CP (' ');
  Lcd_Chr_CP ('H');
  Lcd_Chr_CP ('O');
  Lcd_Chr_CP ('L');
  Lcd_Chr_CP ('A');
  Lcd_Out_CP ("Work");
  Lcd_Out (2,1, "You can");

  Lcd_Cmd (_LCD_BLINK_CURSOR_ON);
  Lcd_Out_CP ("Estudante");
  delay_ms(200);
}

void main()
{
  ADCON1= 0b00001110;
  TRISA0_bit = 0;
  InitMyLCD();
 
  PORTA = 0b00000000; // 1º send
  PORTE = 0b00000000; // 1º send
  //delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00011000; // 2º send
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00011000; // 3º send
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00011000; // 4º send
  delay_ms (200);
  RA5_bit = 1; // start send
  delay_ms(200);
  RA5_bit = 0;
  //delay_ms(200);
  PORTA = 0b00001000; // 5º send
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00001000; // 6º send
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00000010; // 7º envio
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00000000; // 8º send
  delay_ms (200);
  RA5_bit = 1; // start send
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
  PORTA = 0b00011110; // 9º send
  delay_ms (200);
  RA5_bit = 1; // start Sent
  //delay_ms(200);
  RA5_bit = 0;
  delay_ms(200);
}


Regards


Top
 Profile  
 
PostPosted: 30 Aug 2017 18:41 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
Hello Filip. Yes, I already did this test.


Top
 Profile  
 
PostPosted: 30 Aug 2017 19:31 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
hI darko.ilijevski<<< Thank you for your help. Now the LCD has initialized and written. I already recorded my first program on my didactic plate and it worked. I am very happy for the help of all of you. Thank you!

sbit LCD_RS at RE0_bit;
sbit LCD_EN at RA5_bit;
sbit LCD_D4 at RA4_bit;
sbit LCD_D5 at RA3_bit;
sbit LCD_D6 at RA2_bit;
sbit LCD_D7 at RA1_bit;

sbit LCD_RS_Direction at TRISE0_bit;
sbit LCD_EN_Direction at TRISA5_bit;
sbit LCD_D4_Direction at TRISA4_bit;
sbit LCD_D5_Direction at TRISA3_bit;
sbit LCD_D6_Direction at TRISA2_bit;
sbit LCD_D7_Direction at TRISA1_bit;

sbit LCD_RS at RE0_bit;
sbit LCD_EN at RA5_bit;
sbit LCD_D4 at RA4_bit;
sbit LCD_D5 at RA3_bit;
sbit LCD_D6 at RA2_bit;
sbit LCD_D7 at RA1_bit;

sbit LCD_RS_Direction at TRISE0_bit;
sbit LCD_EN_Direction at TRISA5_bit;
sbit LCD_D4_Direction at TRISA4_bit;
sbit LCD_D5_Direction at TRISA3_bit;
sbit LCD_D6_Direction at TRISA2_bit;
sbit LCD_D7_Direction at TRISA1_bit;

void InitMyLCD()
{
lcd_Init ();
delay_ms (300);
Lcd_Cmd (_LCD_CLEAR);
Lcd_Cmd (_LCD_CURSOR_OFF);
delay_ms (300);
Lcd_Chr_CP ('H');
Lcd_Chr_CP ('I');
Lcd_Chr_CP ('>');
Lcd_Chr_CP ('H');
Lcd_Chr_CP ('O');
Lcd_Chr_CP ('L');
Lcd_Chr_CP ('A');
Lcd_Chr_CP ('>');
Lcd_Out_CP ("Work ");
Lcd_Out (2,1, "You can");

Lcd_Cmd (_LCD_BLINK_CURSOR_ON);
Lcd_Out_CP ("Estudante");
delay_ms(200);
}

void main()
{
ADCON1= 0b00001110;
TRISA0_bit = 0;
InitMyLCD();
}


Top
 Profile  
 
PostPosted: 30 Aug 2017 19:43 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 481
Great, I am glad we could help you.

Best regards.


Top
 Profile  
 
PostPosted: 31 Aug 2017 17:45 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
darko.ilijevski, thank you very much.

I have another question. What would be the same code in the CCS compiler? CCS by default sets PORT_D in library #include <lcd.c>, it is easy to switch to PORT_B inserted in the #define directive use_portb_lcd true.
I made this code that in the attempt to use the PORTs_A, E. used in MikroC programming, but does not initialize the LCD. Where is the error?

#include <16F877a.h>
#device ADC = 10 // 8-bit converter
#fuses hs, nowdt, nolvp
#use delay (clock = 20M)
#define use_porta_lcd true
#define use_porte_lcd true
#include <lcd.c>
#use fast_io (a)
#use fast_io (e)
#byte ADCON1 = 0x9F // register address ADCON1

Void main (void)
{
    SETUP_ADC_PORTS (AN0);
    Set_tris_a (0b00000001); // the first pin Analogic
    Set_tris_e (0x11111110);
    ADCON1 = 0b00001110;
    Init_lcd ();
    Printf (lcd_txt, "PIC and LCD");
    Dealy_ms (3000);

}

Would it be necessary to change something in the library #include <lcd.c> or would it be easier to setup an initialization program for the LCD?


Top
 Profile  
 
PostPosted: 04 Sep 2017 20:13 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 481
Hi,

I am sorry but I have no idea how their LCD libraries work, it's MicroChip's product. My guess is that you shouldn't touch the PORTs A and E as a whole, try only ORing the bits you need to set for the AD convertor. Try that way, see if it helps...

TRISA |= 0x01;


Best regards


Top
 Profile  
 
PostPosted: 05 Sep 2017 16:30 
Offline

Joined: 28 Aug 2017 23:20
Posts: 8
Thank you darko.ilijevski.


Top
 Profile  
 
PostPosted: 06 Sep 2017 11:29 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 481
Hi,
You are welcome

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: