|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
BYTE and BOOLEAN variables |
Posted: Mon Sep 29, 2008 12:32 pm |
|
|
I'm just playing with the driver lcd.c that comes with PCWH and am struggling with a compiler error that refers to line 64 in lcd.c:
*** Error 91 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(6,7): Expression must be a constant or simple variable
*** Error 48 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(12,27): Expecting a (
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(28,29): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(29,30): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(31,32): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(33,34): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(34,35): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(35,36): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(37,40): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(40,41): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(42,43): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(43,44): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(45,46): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(46,47): Expecting a declaration
*** Error 43 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 66(47,48): Expecting a declaration
*** Error 12 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 82(29,30): Undefined identifier set_tris_d
*** Error 12 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 94(30,31): Undefined identifier set_tris_d
*** Error 12 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 124(28,29): Undefined identifier set_tris_d
*** Error 12 "C:\PROGRA~1\PICC\drivers\lcd.c" Line 135(24,39): Undefined identifier LCD_INIT_STRING
19 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Mon Sep 29 19:12:59 2008
The first problem line (64) is:
BYTE const LCD_INIT_STRING[4] = {0x20 | lcd_type << 2, 0xc, 1, 6};
What is BYTE supposed to be, a 'CCS' variable? I'm quite new to this so apologies if I'm being a retard.
Thanks
Andy |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 12:50 pm |
|
|
Post a very short test program that demonstrates the problem.
It should have the #include for the PIC's .H file, #fuses statement,
#use delay() statement, and the #include for the lcd.c file. It should
have a main(). |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Sep 29, 2008 12:56 pm |
|
|
The respective exampled as EX_LCDKB.C compiles without error. You can also see that BYTE is type alias for int8, defined in any 18Fxxx.h device file. These kind of error showers are often caused by a single simple syntax error. |
|
|
peaps
Joined: 15 Sep 2008 Posts: 11 Location: Hemel Hempstead, Hertfordshire, UK
|
|
Posted: Mon Sep 29, 2008 1:03 pm |
|
|
Thanks for the quick replies..
The code I am using (attempting to get lcd.c to work) is:
Code: | #include <16f819.h>
#use delay(clock=1000000)
#include <lcd.c>
#fuses INTRC_IO, NOWDT, NOPUT, NOMCLR, NOBROWNOUT, NOCPD
#bit LED = 5.1
void main(void) {
// set_tris_a(0b00000000);
setup_oscillator(OSC_1MHZ);
setup_ccp1(CCP_OFF);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
LED = 1;
delay_ms(1000);
LED = 0;
lcd_init();
while(1==1) {
delay_ms(500);
LED = 1;
lcd_putc("\f12345678");
delay_ms(500);
lcd_putc("\f********\n--------");
delay_ms(250);
}
} |
And lcd.c is pretty vanilla:
Code: |
struct lcd_pin_map { // This structure is overlayed
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
BOOLEAN unused; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;
#if defined use_portb_lcd
#locate lcd = getenv("sfr:PORTB") // This puts the entire structure over the port
#define set_tris_lcd(x) set_tris_b(x)
#else
#locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port
#define set_tris_lcd(x) set_tris_d(x)
#endif
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line
BYTE const LCD_INIT_STRING[4] = {0x20 | lcd_type << 2, 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.
// The following are used for setting
// the I/O port direction register.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in
BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
|
|
|
peaps
Joined: 15 Sep 2008 Posts: 11 Location: Hemel Hempstead, Hertfordshire, UK
|
|
Posted: Mon Sep 29, 2008 1:15 pm |
|
|
Hmm. I have just added the line:
Code: | #define use_portb_lcd TRUE |
And now it compiles. Is it falling over on the line that says:
Code: | #locate lcd = getenv("sfr:PORTD") |
because PORTD doesn't exist on a 16F819?
If so, why did it tell me the error was on line 64? |
|
|
|
|
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
|