![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
bharatwalia
Joined: 04 May 2009 Posts: 35 Location: India
|
A #DEVICE |
Posted: Sun Jul 05, 2009 2:01 am |
|
|
Hi i am getting the following error during compilation :-
Error 128 "lcd.c" Line 45(1,17): A #DEVICE required before this line
// lcd.c
// These are randomly assigned pins, used to test
// that the driver can work with any arrangement
// of i/o pins.
/*
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_C0
#define LCD_DB7 PIN_E0
#define LCD_RS PIN_E2
#define LCD_RW PIN_B2
#define LCD_E PIN_D6
*/
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7
#define LCD_RS PIN_B0
#define LCD_RW PIN_B1
#define LCD_E PIN_B2
// If you want to use a 6-pin interface for your LCD, then
// connect the R/W pin on the LCD to ground and comment
// out the following line. A 6-pin interface to the LCD
// is used if only have a few free i/o pins available on
// your PIC, and you want to use the smallest possible
// number of pins for the LCD.
#define USE_LCD_RW 1
//========================================
// Use "2 lines" as the lcd type for the 16x1 LCD.
// The LCD is the same as an 8x2 LCD, but with the
// bottom line appended on the right side of the first line.
#define LCD_TYPE 2 // 0=5x7, 1=5x10, 2=2 lines
#define LCD_2ND_HALF_ADDRESS 0x40
#define LCD_WIDTH 16
#define LCD_HALF_WIDTH (LCD_WIDTH/2)
int8 const LCD_INIT_STRING[4] =
{
0x20 | (LCD_TYPE << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
int8 lcd_xcoord;
//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}
//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.
#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;
output_high(LCD_E);
delay_us(1);
retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
output_low(LCD_E);
delay_us(1);
return(retval);
}
#endif
//---------------------------------------
// Read a byte from the LCD and return it.
#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;
output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return((high << 4) | low);
}
#endif
//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(), 7)) ;
#else
delay_us(60);
#endif
if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);
#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif
output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
void lcd_init(void)
{
int8 i;
output_low(LCD_RS);
#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif
output_low(LCD_E);
// Some LCDs require 15 ms minimum delay after
// power-up. Others require 30 ms. I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}
lcd_xcoord = 1;
}
//----------------------------
// The x-coordinate can be 1 to 16.
// The y coordinate is ignored.
// This x,y interface is kept in order to be
// consistent with other CCS LCD drivers.
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
// Update the global x-coordinate variable with the
// current x coordinate.
lcd_xcoord = x;
// Convert the x-coordinate from CCS format (1-16) to
// the 0-15 format used by the LCD hardware.
address = x - 1;
// If the x-coordinate is within the 2nd half of the
// LCD line, the address must be adjusted because
// of the special architecture of the 8x2 LCD.
if(address >= LCD_HALF_WIDTH)
{
address += (LCD_2ND_HALF_ADDRESS - LCD_HALF_WIDTH);
}
lcd_send_byte(0, 0x80 | address);
}
//-----------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
lcd_xcoord = 1;
break;
case '\n':
lcd_gotoxy(1,1); // Goto start of line 1
break;
case '\b':
lcd_send_byte(0, 0x10);
lcd_xcoord--;
if(lcd_xcoord == LCD_HALF_WIDTH)
lcd_gotoxy(LCD_HALF_WIDTH, 1);
break;
default:
lcd_send_byte(1, c);
lcd_xcoord++;
if(lcd_xcoord == (LCD_HALF_WIDTH +1))
lcd_gotoxy(LCD_HALF_WIDTH +1, 1);
break;
}
}
//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;
lcd_gotoxy(x,y);
// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);
return(value);
}
#endif
#include <18f2550.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include "lcd.c"
// This macro converts the lower nibble of a byte to
// an ASCII hex character, so it can be displayed with
// lcd_putc().
#define tohex(x) (x & 0xF) < 10 ? x + '0' : x + '7'
//======================================
void main()
{
int8 i;
// This array is used in the test for lcd_gotoxy().
int8 x_array[16] =
{5,0xE,0xD,6,8,1,0xB,2,7,0xC,0,4,3,0x9,0xA,0xF};
int8 values_read[16];
// Always call lcd_init() once at the start of
// your program, before using the LCD.
lcd_init();
// First test the lcd_putc() function, and also the
// "clear screen" command '\f':
while(1)
{
printf(lcd_putc, "\f 16x1 LCD Test ");
delay_ms(3000);
printf(lcd_putc, "\fTest lcd_putc()");
delay_ms(3000);
printf(lcd_putc, "\f Hello World ");
delay_ms(1500);
printf(lcd_putc, "\fabcdefghijklmnop");
delay_ms(1500);
printf(lcd_putc, "\f0123456789ABCDEF");
delay_ms(1500);
printf(lcd_putc, "\f!@#$^&*(){}[]:;<");
delay_ms(2500);
// Test the backspace command.
// Do a destructive backspace by moving the cursor
// onto the previous character, overwriting it with
// a space, and then moving the cursor back onto the
// now erased location.
printf(lcd_putc, "\fTest Backspacing");
delay_ms(1000);
// Backspace over the line.
for(i = 0; i < 16; i++)
{
printf(lcd_putc, "\b \b");
delay_ms(400);
}
delay_ms(1500);
// Test that the lcd_gotoxy() function works OK.
// Go to each x-coordinate in a semi-random order,
// and write a character at each position. The x-coords
// are taken from an array declared at the start of main().
printf(lcd_putc, "\fTest lcd_gotoxy");
delay_ms(1500);
printf(lcd_putc, "\frandomly:");
delay_ms(1500);
printf(lcd_putc, "\f");
for(i = 0; i < 16; i++)
{
lcd_gotoxy(x_array[i] +1, 1);
printf(lcd_putc, "%c", tohex(x_array[i]));
delay_ms(500);
}
delay_ms(2000);
// Test the ability to read characters from the LCD.
// Read the character that was written in each position
// in the test above, and display it.
//
// Note:
// The following test can only be done if the driver
// can read from the LCD. If the RW pin is not used,
// the LCD is in write-only mode, and we can't do
// this test. In that case, it won't be compiled.
/*#ifdef USE_LCD_RW
for(i = 0; i < 16; i++)
values_read[i] = lcd_getc(i+1, 1);
printf(lcd_putc, "\fTest reading");
delay_ms(2000);
printf(lcd_putc, "\fRead these bytes");
delay_ms(2000);
lcd_putc('\f');
for(i = 0; i < 16; i++)
{
printf(lcd_putc, "%c", (values_read[i]));
delay_ms(400);
}
delay_ms(2000);
#endif
// Tell the user that the tests are finished.
printf(lcd_putc, "\f All Tests Done ");
delay_ms(3000);
*/}
} |
|
![](templates/subSilver/images/spacer.gif) |
andyfraser
Joined: 04 May 2004 Posts: 47 Location: UK
|
A #DEVICE |
Posted: Sun Jul 05, 2009 5:36 am |
|
|
The error message says is all !
Prior to including lcd.c in you must define which device you are targetting.
This is typically done by including the appropriate .h file for the processor in your main source file.
Andy |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jul 05, 2009 9:07 am |
|
|
The #device statement should be one of the first statements in your program and is present in the device include file.
You have included 18f2550.H, but is this the original file or did you edit it?
What is your compiler version number?
Two hints for your next post:
1) When posting code use the 'code' buttons. This preserves formatting of your code and makes for easier reading.
2) Post only short, but complete, programs of maximum 50 lines.
Applying these rules will get you more and faster responses. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sun Jul 05, 2009 9:11 am |
|
|
i didn't edited the file my compiler version is 4.3.0.225 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Jul 05, 2009 9:24 am |
|
|
That is not the version number. Look in the .lst file generated,it is in the top line. The version number, is just one digit, decimal, three digits. So (for example), 4.071.
Now, it is difficult (impossible....), to actually interpret what is in your files.
As has already been said, use the 'code' buttons, and post like this:
In myprog.c:
Code: |
#include <18f2550.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#include "lcd.c"
//======================================
void main(void) {
int8 i=0;
// Initialise LCD.
lcd_init();
while(true) {
printf(lcd_putc, "\fLCD Test %d",i++);
delay_ms(1000);
}
}
|
The 'point' is that people can see exactly what is in each file, and these are _as short as possible_.
We can then create copies of the files, and compile to see what is happening.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sun Jul 05, 2009 11:10 am |
|
|
Code: | // lcd.c
// These are randomly assigned pins, used to test
// that the driver can work with any arrangement
// of i/o pins.
/*
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_C0
#define LCD_DB7 PIN_E0
#define LCD_RS PIN_E2
#define LCD_RW PIN_B2
#define LCD_E PIN_D6
*/
#define LCD_DB4 PIN_B3
#define LCD_DB5 PIN_B4
#define LCD_DB6 PIN_B5
#define LCD_DB7 PIN_B6
#define LCD_RS PIN_B2
//#define LCD_RW PIN_B1
#define LCD_E PIN_B0
// If you want to use a 6-pin interface for your LCD, then
// connect the R/W pin on the LCD to ground and comment
// out the following line. A 6-pin interface to the LCD
// is used if only have a few free i/o pins available on
// your PIC, and you want to use the smallest possible
// number of pins for the LCD.
#define USE_LCD_RW 1
//========================================
// Use "2 lines" as the lcd type for the 16x1 LCD.
// The LCD is the same as an 8x2 LCD, but with the
// bottom line appended on the right side of the first line.
#define LCD_TYPE 2 // 0=5x7, 1=5x10, 2=2 lines
#define LCD_2ND_HALF_ADDRESS 0x40
#define LCD_WIDTH 16
#define LCD_HALF_WIDTH (LCD_WIDTH/2)
int8 const LCD_INIT_STRING[4] =
{
0x20 | (LCD_TYPE << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
int8 lcd_xcoord;
//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}
//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.
#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;
output_high(LCD_E);
delay_us(1);
retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
output_low(LCD_E);
delay_us(1);
return(retval);
}
#endif
//---------------------------------------
// Read a byte from the LCD and return it.
#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;
output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return((high << 4) | low);
}
#endif
//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(), 7)) ;
#else
delay_us(60);
#endif
if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);
#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif
output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
void lcd_init(void)
{
int8 i;
output_low(LCD_RS);
#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif
output_low(LCD_E);
// Some LCDs require 15 ms minimum delay after
// power-up. Others require 30 ms. I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}
lcd_xcoord = 1;
}
//----------------------------
// The x-coordinate can be 1 to 16.
// The y coordinate is ignored.
// This x,y interface is kept in order to be
// consistent with other CCS LCD drivers.
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
// Update the global x-coordinate variable with the
// current x coordinate.
lcd_xcoord = x;
// Convert the x-coordinate from CCS format (1-16) to
// the 0-15 format used by the LCD hardware.
address = x - 1;
// If the x-coordinate is within the 2nd half of the
// LCD line, the address must be adjusted because
// of the special architecture of the 8x2 LCD.
if(address >= LCD_HALF_WIDTH)
{
address += (LCD_2ND_HALF_ADDRESS - LCD_HALF_WIDTH);
}
lcd_send_byte(0, 0x80 | address);
}
//-----------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
lcd_xcoord = 1;
break;
case '\n':
lcd_gotoxy(1,1); // Goto start of line 1
break;
case '\b':
lcd_send_byte(0, 0x10);
lcd_xcoord--;
if(lcd_xcoord == LCD_HALF_WIDTH)
lcd_gotoxy(LCD_HALF_WIDTH, 1);
break;
default:
lcd_send_byte(1, c);
lcd_xcoord++;
if(lcd_xcoord == (LCD_HALF_WIDTH +1))
lcd_gotoxy(LCD_HALF_WIDTH +1, 1);
break;
}
}
//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;
lcd_gotoxy(x,y);
// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);
return(value);
}
#endif |
Code: | #include <18f2550.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include "lcd.c"
// This macro converts the lower nibble of a byte to
// an ASCII hex character, so it can be displayed with
// lcd_putc().
#define tohex(x) (x & 0xF) < 10 ? x + '0' : x + '7'
//======================================
void main()
{
int8 i;
// This array is used in the test for lcd_gotoxy().
int8 x_array[16] =
{5,0xE,0xD,6,8,1,0xB,2,7,0xC,0,4,3,0x9,0xA,0xF};
int8 values_read[16];
// Always call lcd_init() once at the start of
// your program, before using the LCD.
lcd_init();
// First test the lcd_putc() function, and also the
// "clear screen" command '\f':
while(1)
{
printf(lcd_putc, "\f 16x1 LCD Test ");
delay_ms(3000);
printf(lcd_putc, "\fTest lcd_putc()");
delay_ms(3000);
printf(lcd_putc, "\f Hello World ");
delay_ms(1500);
printf(lcd_putc, "\fabcdefghijklmnop");
delay_ms(1500);
printf(lcd_putc, "\f0123456789ABCDEF");
delay_ms(1500);
printf(lcd_putc, "\f!@#$^&*(){}[]:;<");
delay_ms(2500);
// Test the backspace command.
// Do a destructive backspace by moving the cursor
// onto the previous character, overwriting it with
// a space, and then moving the cursor back onto the
// now erased location.
printf(lcd_putc, "\fTest Backspacing");
delay_ms(1000);
// Backspace over the line.
for(i = 0; i < 16; i++)
{
printf(lcd_putc, "\b \b");
delay_ms(400);
}
delay_ms(1500);
// Test that the lcd_gotoxy() function works OK.
// Go to each x-coordinate in a semi-random order,
// and write a character at each position. The x-coords
// are taken from an array declared at the start of main().
printf(lcd_putc, "\fTest lcd_gotoxy");
delay_ms(1500);
printf(lcd_putc, "\frandomly:");
delay_ms(1500);
printf(lcd_putc, "\f");
for(i = 0; i < 16; i++)
{
lcd_gotoxy(x_array[i] +1, 1);
printf(lcd_putc, "%c", tohex(x_array[i]));
delay_ms(500);
}
delay_ms(2000);
// Test the ability to read characters from the LCD.
// Read the character that was written in each position
// in the test above, and display it.
//
// Note:
// The following test can only be done if the driver
// can read from the LCD. If the RW pin is not used,
// the LCD is in write-only mode, and we can't do
// this test. In that case, it won't be compiled.
/*#ifdef USE_LCD_RW
for(i = 0; i < 16; i++)
values_read[i] = lcd_getc(i+1, 1);
printf(lcd_putc, "\fTest reading");
delay_ms(2000);
printf(lcd_putc, "\fRead these bytes");
delay_ms(2000);
lcd_putc('\f');
for(i = 0; i < 16; i++)
{
printf(lcd_putc, "%c", (values_read[i]));
delay_ms(400);
}
delay_ms(2000);
#endif
// Tell the user that the tests are finished.
printf(lcd_putc, "\f All Tests Done ");
delay_ms(3000);
*/}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sun Jul 05, 2009 11:12 am |
|
|
compiler version is 4.084 |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sun Jul 05, 2009 12:07 pm |
|
|
As you posted it the code would not compile due to a missing LCD_RW definition in LCD.C
(I uncommented your #define LCD_RW PIN_B1 right before #define LCD_E PIN_B0 in your code).
After uncommenting that one line it compiles as you posted it with no problems in 4.081 ( the latest version I have).
Is it possible you have different version of LCD.C in the same directory that is confusing the compiler? _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Mon Jul 06, 2009 1:19 am |
|
|
Thanks,it worked ![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|