Reputation: 19
I'm trying to understand this LCD example on Pic16F887; http://www.mikroe.com/chapters/view/17/chapter-4-examples/#c4v12
but the compiler keeps showing me errors:
lcdpic16.c:32: warning: function declared implicit int
lcdpic16.c:33: warning: function declared implicit int
lcdpic16.c:33: error: undefined identifier "_LCD_CURSOR_OFF"
lcdpic16.c:34: error: undefined identifier "_LCD_CLEAR"
lcdpic16.c:36: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
lcdpic16.c:37: warning: function declared implicit int
lcdpic16.c:38: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
lcdpic16.c:43: warning: function declared implicit int
lcdpic16.c:45: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
lcdpic16.c:48: warning: function declared implicit int
lcdpic16.c:54: warning: function declared implicit int
lcdpic16.c:55: warning: function declared implicit int
(908) exit status = 1
make: *** [build/default/production/lcdpic16.p1] Error 1
BUILD FAILED (exit value 2, total time: 22s)
Source Code (lcdp16.c)
/*Header******************************************************/
#include <pic16f887.h>
// LCD module connections
#define LCD_RS RB4
#define LCD_RS RB4
#define LCD_EN RB5
#define LCD_D4 RB0
#define LCD_D5 RB1
#define LCD_D6 RB2
#define LCD_D7 RB3
#define LCD_RS_Direction TRISB4
#define LCD_EN_Direction TRISB5
#define LCD_D4_Direction TRISB0
#define LCD_D5_Direction TRISB1
#define LCD_D6_Direction TRISB2
#define LCD_D7_Direction TRISB3
// End LCD module connections
unsigned char ch; //
unsigned int adc_rd; // Declare variables
char *text; //
long tlong; //
void main() {
INTCON = 0; // All interrupts disabled
ANSEL = 0x04; // Pin RA2 is configured as an analog input
TRISA = 0x04;
ANSELH = 0; // Rest of pins are configured as digital
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "mikroElektronika"; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
text = "LCD example"; // Define the second message
Lcd_Out(2,1,text); // Define the first message
ADCON1 = 0x82; // A/D voltage reference is VCC
TRISA = 0xFF; // All port A pins are configured as inputs
Delay_ms(2000);
text = "voltage:"; // Define the third message
while (1) {
adc_rd = ADC_Read(2); // A/D conversion. Pin RA2 is an input.
Lcd_Out(2,1,text); // Write result in the second line
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // Extract volts (thousands of millivolts)
// from result
Lcd_Chr(2,9,48+ch); // Write result in ASCII format
Lcd_Chr_CP('.');
ch = (tlong / 100) % 10; // Extract hundreds of millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
ch = (tlong / 10) % 10; // Extract tens of millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
ch = tlong % 10; // Extract digits for millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
Lcd_Chr_CP('V');
Delay_ms(1);
}
}
Can anyone explain to me what's happening? should I create a custom LCD library so the compiler can recognize methods like Lcd_Init()
or what?
(Windows 7 / XC8 / MPLAB X)
Upvotes: 1
Views: 11502
Reputation: 684
This website provides good library and examples for MPLABX IDE and XC8 compiler, but don't forget to add _XTAL_FREQ=20000000 micro in the project properties >> XC8 compiler , otherwise it won't compile!
If you use PIC16F877A it will fill 20% of the 256 Bytes EEPROM data memory! and 1% of the 14KB Program Memory.
Upvotes: 0
Reputation: 889
For MPLAB XC8 use the library in the following link : Interfacing LCD with PIC Microcontroller - MPLAB XC8
The example in that article using PIC 16F877A Microcontroller. You can convert it to PIC 16F877 just by changing it in MPLAB Project Settings..
Upvotes: 1
Reputation: 316
Easy! You are using MPLAB, but the library you are looking at is meant to be used on a completely different IDE called MikroC.
You will have to write you own functions or change your IDE. BTW, writing LCD functions isn't that hard, have a look at this example :
Interfacing PIC to HD44780 LCD
Upvotes: 2
Reputation:
Well , first things first. In theory everything you've done is correct. However you will need to design a lot of the functions that you are calling specifically: LCD_Init(),LCD_CMD(), LCD_OUT(). These are not native commands so you will have to write the code yourself.
If you want to get this up and running. The best way to do this is to find your LCD's documentation and figure out what bits/byte it needs to perform an operation. Since you already defined LCD_RS as RB4 , you have to make sure that the RS pin on your LCD is connected to RB4. And perform this check on all other pins. In the documentation of your LCD they will tell you what values the pins need to be set to perform a specific operation. ie LCD_EN might enable write to the screen so you can display characters. While D7-D4 might be your data bus were you send in 4-bits at a time from your byte. Since the Data cannot be sent instantaneously due the the LCD's response time you might have to insert delays.
The delays are rather simple you just need to set one of the free timers to measure time in microseconds and raise a flag and once the flag is raised you can send in the next command. You can also make then polling delays. This is done by resetting the timer value to zero and waiting until it reaches some value that you have predetermined, in the code it would be 2000.
Finally, you'll have to write the ADC_Read(),ADC_Init() [ this is not in your code but i think writing one is better than exposing the register operations in your code]. Also this might look intimidating but don't worry. It's one of those things that once you've programmed one LCD, you've programmed them all. Personally i think you should write your timer routines first and then move on to the LCD screen. Hope that helped.
Upvotes: 1