CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with 16f877a code writing for lcd interface

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
uma



Joined: 17 Apr 2014
Posts: 29
Location: chennai

View user's profile Send private message

Problem with 16f877a code writing for lcd interface
PostPosted: Thu Apr 17, 2014 11:30 pm     Reply with quote

Error msg: cannot change device type this far into the code. (line2)
Code:

#include <pgm1.h>

#include <16F877A.h> 
//#fuses XT,NOWDT
#use delay(clock=20000000)

#include <lcd.c>

#define lcd_RD4     PIN_RD0
#define lcd_RD5     PIN_RD1
#define lcd_RD6     PIN_RD2
#define lcd_RD7     PIN_RD3

#define lcd_E       PIN_RB1
#define lcd_RS      PIN_RB2

void main()
{
set_tris_d(0x00);
set_tris_b(0x00);
output_d(0x00);
output_b(0x00);
delay_ms(1500);

lcd_init();
delay_ms(500);
//lcd_cursor_on(1,TRUE);
//for(;;)
while(TRUE)
   {
    lcd_gotoxy(1,1);   
    Printf(lcd_putc,"/f welcome to ETPL");
    delay_ms(500);
    lcd_gotoxy(1,2);
    Printf(lcd_putc,"/n LCD interface");
    delay_ms(500);
   }
}

_________________
uma
Application Engineer,
ETPL
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 1:48 am     Reply with quote

The error message is telling you what to do.

Try putting
Code:
#include <16F877A.h> 
as the first line, rather than second.

Mike
uma



Joined: 17 Apr 2014
Posts: 29
Location: chennai

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 3:13 am     Reply with quote

I tried that too as you said, and i have made little changes also,even then it is showing errr.
Code:

#include <16F877.h>
#include <pgm1.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#define lcd_DATA4             PIN_D0
#define lcd_DATA5             PIN_D1
#define lcd_DATA6             PIN_D2
#define lcd_DATA7             PIN_D3

#define lcd_ENABLE_PIN        PIN_B1
#define lcd_RS_PIN            PIN_B2
#include <lcd.c>

void main()
{
set_tris_d(0x00);
set_tris_b(0x00);
output_d(0x00);
output_b(0x00);
delay_ms(1500);

   lcd_init();
   delay_ms(500);
   
   while(TRUE)
   
    printf(lcd_putc,"/f welcome to ETPL");
    delay_ms(500);
    lcd_gotoxy(1,2);
    Printf(lcd_putc,"/n LCD interface");
    delay_ms(500);
   
   }

how to attach the error screen shot with this?
_________________
uma
Application Engineer,
ETPL
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 4:33 am     Reply with quote

You can copy and paste to show error messages.

What is the error you are now getting?

Your code is not complete and compilable.

I don't have your pgm1.h file

Therefore, I can't readily test your code on my system.

At this stage you are making me second guess what you have done.

If you want help, you need to make it easy for us.

Mike
uma



Joined: 17 Apr 2014
Posts: 29
Location: chennai

View user's profile Send private message

i have simplified the code and now no result in simulation.
PostPosted: Fri Apr 18, 2014 5:11 am     Reply with quote

Code:
#include<16f877a.h>

#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP


#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7

#include <lcd.c> 

void main()
{
   set_tris_d(0x00);
   set_tris_c(0x00);
   lcd_init();
    Delay_ms(100);
   while(1)
   {
      lcd_gotoxy(1,1);
      Delay_ms(1000);
      lcd_putc("\f Hello ETPL...\n");
   }
}


Here is the link of screen shot of simulation:
http://www.2shared.com/photo/aQY7aQyF/proteus_disp.html
http://www.2shared.com/photo/tOFGqXrt/warning_msg.html
_________________
uma
Application Engineer,
ETPL
uma



Joined: 17 Apr 2014
Posts: 29
Location: chennai

View user's profile Send private message

solved,mstke is connection.
PostPosted: Fri Apr 18, 2014 5:53 am     Reply with quote

connected the D4,D5,D6,D7 PIN of MCU to D0,D1,D2,D3 is the problem.

Again i connected it to D4,D5,D6,D7 pin of LCD and grounded the upper nibble.
_________________
uma
Application Engineer,
ETPL
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 18, 2014 5:54 am     Reply with quote

a clear message about what the problem is , can be found here :

http://www.ccsinfo.com/forum/viewtopic.php?t=47549
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 8:40 am     Reply with quote

I refuse to deal with Proteus/ISIS issues.
Come back when you are using real hardware.

This line deals with the pin connections
Code:
#include <lcd.c>

You therefore don't need these
Code:
#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7

You don't need these lines. The CCS compiler deals with I/O's
Code:
   set_tris_d(0x00);
   set_tris_c(0x00);


The list goes on ..........................

Your link to the screen shot was a waste of my time and effort.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9127
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 10:36 am     Reply with quote

to begin with... if you wired up the project according to your schematic..it'll never work !!!

1) no xtal or caps on PIC clk pins.

2) no power to PIC

3) not supposed to ground LCD data pins...

3 strikes and I'm out.

Happy to help but come back with real hardware.....

jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 1:33 pm     Reply with quote

Connect your LCD according to this schematic:
http://2.bp.blogspot.com/-8xC4RgF8scM/TxlLYKaSFaI/AAAAAAAAACk/7FODBf0jvRo/s1600/Schematic.png

Compile and run this test program below, and it should work.
This program uses the CCS lcd.c driver, and it defaults to using PortD for
the lcd. The schematic in the link above uses PortD, exactly as required
by the CCS lcd.c driver.
Code:

#include <16F877A.h>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#include <lcd.c>

//==========================================
void main()
{

delay_ms(500);
lcd_init();

printf(lcd_putc, "\fHello World");

while(1);
}
uma



Joined: 17 Apr 2014
Posts: 29
Location: chennai

View user's profile Send private message

RE: problem of lcd interface
PostPosted: Sat Apr 19, 2014 12:22 am     Reply with quote

Thanks for everyone who replied, sorry if anyone of you feel that i have wasted your time.

I am struggling because i am new to this field,so i am working from basic.
_________________
uma
Application Engineer,
ETPL
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group