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.

Please help with school project of PIC16f864 + 2x16 LCD

Status
Not open for further replies.

tonyela

New Member
View attachment 67045Hello all,
I try to have the message display on the 2x16 lcd, but show nothing. In proteus it does show perfectly what I want it to show, but when I implemented with the real chip, it does not show anything. I did play with the contract... but it only show blank square dot.
Thank you for your help.

here is the code and schematic:
// LCD module connections
sbit LCD_RS at RC5_bit;
sbit LCD_EN at RC4_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;

sbit LCD_RS_Direction at TRISC5_bit;
sbit LCD_EN_Direction at TRISC4_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections



void main()
{



TRISA = 0xFF; // PORTA is input except RA4
ANSEL = 0x03; // Configure AN0, AN1, pin as analog
// (Without this also could cause controller received data whlst busy msg)
PORTC = 0; // Set all pins on PORTC to low
TRISC = 0; // All of PORTC are outputs
lcd_cmd(0x20); // 4-bit mode - 2 line - 5x7 font.
delay_ms(1000);
lcd_init();
delay_ms(1000);
//lcd_cmd(0x28); // 4-bit mode - 2 line - 5x7 font.


LCD_cmd(_LCD_TURN_ON);
delay_ms(100);
LCD_cmd(_LCD_CLEAR); // Clear LCD
delay_ms(100);
LCD_cmd(_LCD_CURSOR_OFF);
delay_ms(100);


do
{

Lcd_Out(1,1,"Welcome to LCD");
lcd_out(2,1,"and PIC16f684");
delay_ms(1000);
} while(1);
}
 
Hello Ian, Thank you for your respond, I remove the lcd_cmd line and it still not work. I also connect the led from RA5 to gnd... I can see it blinking... but nothing show on the screen... just the square box on the line 1.
 
One more thing to check, In hardware, the LCD Pot is 100Ω?, the recommended is 5000Ω.
 
Last edited:
TRISA = 0xFF; // PORTA is input except RA4

this command will set all PORTA pins as input, since 0xFF in hex = 1111 1111 in Bin.

I suggest you try simple example given in MikroC help to initialize your LCD and then try your code, change the pins according to your setup:

Code:
char *text = "mikroElektronika";

void main() {
  TRISB = 0;                // PORTB is output
  Lcd_Init(&PORTB);         // Initialize LCD connected to PORTB
  Lcd_Cmd(Lcd_CLEAR);       // Clear display
  Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off
  Lcd_Out(1, 1, text);      // Print text to LCD, 2nd row, 1st column
}//~!
 
Last edited:
Hey! what do you know... the command CMCON0 = 0x7 did fixed my problem. Although it also dumping some garbage on the LCD. but it is a good sign.. Thank you very very much guys, both of you were very helpful. you guys are great. Thank you again.
 
Long time since I have played with PICs, but shouldn't PORTC have some form of I/O register to tell the CPU which way you want control e.g. a DDR data direction register.
On most processors, PORTC=0 is meaningless as most come out of reset set as inputs.
 
Sorry ..... That sounded rude.... I really didn't mean to be..

No offence taken.

I personally avoid this kind of syntax as to me (in my case about 3 years) or to a reviewer can become meaniless despite being valid syntax.

On an 8051 core...
REFSL=1; is valid but what does it mean? You have to trawl the header files or data sheet to find where REFSL is referenced by a Special Function Register.

I would prefer using the exact SFR followed by a brief explaining comment
REF0CN |=0x08; // use VDD as a reference voltage.

I am not particularly interested in what the bit name is, just where to find it and if in the register there are any corresponding bits affected.

Which I suppose unlike many you did.
 
Last edited:
I agree WTPpepper. MikroC (that the OP is using) has a nice feature of allowing base2 constants, so
TRISC = 0;

can be displayed better as
TRISC = 0b00000000;

which allows good commenting like;
TRISC = 0b10000011; // RC7 is USART RX, RC2-6 are LEDs, RC0,1 buttons
 
Status
Not open for further replies.

Latest threads

Back
Top