PDA

View Full Version : P16F1827 and LCD Problems



Bobw55
- 19th January 2011, 01:49
I am new to all of this:
I have triple checked my wiring to the PIC<16F1827> and LCD as follows:

PIC LCD
RB0 = D4
RB1 = D5
RB2 = D6
RB3 = D7
RB4 = RS
RB5 = E
The R/W is tied to ground. VCC = +5 volts.
I have tried just about every sample program I could find on this forum and they will either not compile (Pic Basic Pro) or I could not figure out the correct ports to change around to match my configuration. I am using a PICKIT3 to program with and it does see and properly identify my chip.
Would be wonderful if someone could point me at some proper sample code to just initialize the LCD.... let alone make it say hello.
I have not done any PIC programming, and haven't done much basic programming since the days of my Atari 800. Most of the compile errors I was receiving were stating that "Program" was expected. Newbie error I guess.
Some one please re-aim my compass

mackrackit
- 19th January 2011, 02:07
Can you post the code you have along with your config settings?

Bobw55
- 19th January 2011, 20:48
Here is the latest code I have been trying to build.
And this is the error message I receive :
3 304 Syntax error: Expected "program" but "module" found TEST.mbas

'*Header****************************************** ************/

module TEST
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// 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);

Bob

rmteo
- 19th January 2011, 21:01
Try asking here mikroC PRO for PIC General (http://www.mikroe.com/forum/viewforum.php?f=88)

mark_s
- 19th January 2011, 21:04
Here is the latest code I have been trying to build.
And this is the error message I receive :
3 304 Syntax error: Expected "program" but "module" found TEST.mbas

'*Header****************************************** ************/

module TEST
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// 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);

Bob


http://forums.basicmicro.net/feedback-f482/mbasic-pro-dead-t9279.html

gadelhas
- 19th January 2011, 21:04
Hi;
That program is writen in MicroC. It will not work in PBP.

Regards

Bobw55
- 19th January 2011, 21:09
I knew it had to be something supidly simple. I have been looking at and trying to understand some of the coding, they all start to look the same to me. Have to see if I can compile it with MPLAB.


THANKS

gadelhas
- 19th January 2011, 21:13
No, you will not be able to compile that program with MPLAB, only with MicroC.

Bobw55
- 19th January 2011, 21:25
Yuppers... just found that out the hard way. About ready to put 1KV thru this PIC and say the hell with it..... NOT

gadelhas
- 19th January 2011, 21:32
Don't do that give it to me!!!:D

Bobw55
- 19th January 2011, 23:33
I'll figure something out.
I should have known the simple would be hard

Bobw55
- 21st January 2011, 00:47
Tried another sample file with MPLAB and actually managed to get it to build and load. But "NO" LCD initialization, still a top row boxes.
Will have to Google the 16f1827 some more and see if someone has Ideas.

mackrackit
- 21st January 2011, 00:53
Do you have pin 3 of the LCD (contrast) connected to a POT?

Bobw55
- 21st January 2011, 01:05
YES I do.... Should have mentioned that earlier on.
Actually used a little interface board from here :http://www.mikroe.com/eng/products/view/145/lcd-adapter-board/ pre-wired for 4 bit mode

mackrackit
- 21st January 2011, 01:11
That POT is for the backlight according to the data sheet.

Bobw55
- 21st January 2011, 01:14
The pot is for the contrast, I have 3 pots on a separate board to control the RGB back light.
The display DOES use the standard LCD controller, I made sure I at least got that part right.

Bobw55
- 22nd January 2011, 00:52
I think some of the problems I am having is not being sure of what coding the file example I am trying to copy is in (Basic, C, Assembly).
To just initialize the LCD I am assuming I have to Code the port/Pins the LCD is on, and then send the initialization string "LCD_Init" .

Archangel
- 22nd January 2011, 04:14
I am new to all of this:
I have triple checked my wiring to the PIC<16F1827> and LCD as follows:

PIC LCD
RB0 = D4
RB1 = D5
RB2 = D6
RB3 = D7
RB4 = RS
RB5 = E
The R/W is tied to ground. VCC = +5 volts.
I have tried just about every sample program I could find on this forum and they will either not compile (Pic Basic Pro) or I could not figure out the correct ports to change around to match my configuration. I am using a PICKIT3 to program with and it does see and properly identify my chip.
Would be wonderful if someone could point me at some proper sample code to just initialize the LCD.... let alone make it say hello.
I have not done any PIC programming, and haven't done much basic programming since the days of my Atari 800. Most of the compile errors I was receiving were stating that "Program" was expected. Newbie error I guess.
Some one please re-aim my compass
Hello Bob,
To be clear, you DO / Do Not have the Pic Basic Pro compiler from MeLabs?

Bobw55
- 22nd January 2011, 14:55
I only have the demo version which does NOT support the 16F1827.
I have:
MPLAB 8.63 PICKIT3
MikroBasic
MikroC-Pro
MikroPro-Suite

I found the Assembly template file for the 16F1827 and will start using that to build with.
From my reading last night I figured out that I have to define or tell the program the pinout of the LCD to the PIC. Set the LCD for 4bit High nibble, then I can send the initialization string to it. (I think)
My first goal is just to get it to Initialize.
Second Print some text.
Third read and display the value of a switch.
I will do this, even if it takes a sledge hammer

Bobw55
- 29th January 2011, 22:18
Managed to get some code written and displayed.

THANK YOU ALL FOR THE POINTERS

Bob

cncmachineguy
- 29th January 2011, 23:38
:D

Awesome Bob!!

gadelhas
- 29th January 2011, 23:56
Well Done Bob!

mister_e
- 30th January 2011, 14:52
Now how about sharing it for humanity purpose :p

Acetronics2
- 30th January 2011, 17:06
Hello BobW

About "your" MikroC Pro program ...

1) are you sure it has been written ( by you ??? :rolleyes: ) for a '1827
2) did you create a project ??? ( the " module " error comes from here )

once " trimmed " it gives :



0 1 mikroCPIC1618.exe -MSF -DBG -pP16F1827 -DL -O11111114 -fo8 -N"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Examples\tEST.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16_Enh\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Examples\" "tEST.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_ADC.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl"
0 1139 Available RAM: 368 [bytes], Available ROM: 4096 [bytes]
0 126 All files Preprocessed in 50 ms
0 122 Compilation Started tEST.c
63 123 Compiled Successfully tEST.c
0 127 All files Compiled in 80 ms
0 1144 Used RAM (bytes): 63 (17%) Free RAM (bytes): 305 (83%) Used RAM (bytes): 63 (17%) Free RAM (bytes): 305 (83%)
0 1144 Used ROM (program words): 1198 (29%) Free ROM (program words): 2898 (71%) Used ROM (program words): 1198 (29%) Free ROM (program words): 2898 (71%)
0 125 Project Linked Successfully tEST.mcppi
0 128 Linked in 210 ms
0 129 Project 'tEST.mcppi' completed: 451 ms
0 103 Finished successfully: 30 janv. 2011, 18:02:00 tEST.mcppi



1198 ROM .... should compile fine with the demo version, no ???

[HUMOUR ON]

How much with PBP ???? :D

nooooooo .... not on the head !!!


Alain

ScaleRobotics
- 30th January 2011, 17:39
How much with PBP ???? :D


With PBP, give or take a few:
Program Memory Words Used: 285
Program Memory Words Free: 3811

Give or take a little. So, about 7%, compared to MicroC's 29% used.

Now, this is not a fair comparison, because I don't know what MicroC's test program you are using, or what it does. PBP numbers are for just printing two variables to an LCD display.

Acetronics2
- 30th January 2011, 18:10
Now, this is not a fair comparison, because I don't know what MicroC's program is doing


Hoooooo ...

See #4

Program just reads voltage on ADC channel 2 , prints a text on line one of the LCD and prints the ADC voltage in V.VVV format on the second line ... of course with the Unit !

Comparison is not unfair at all as the shortest MkC Pro available way to display numbers is used here ...
you had also noted the LONG type use for "calculations" ... unavoidable with MkC.

I already made a comparison on this Forum and result was similar ...
PBP and Proton were quite the same for the result. ;)

Alain

Bobw55
- 31st January 2011, 03:34
I am not sure which program you are referring to?
The one That gave me the display was written by me on a PIC16F88 using C.
I gave up on the 16F1827 do to lack of programming knowledge and lack of sample programs for that chip. Now that I have a somewhat grasp on the basics, I have been able to read and display the ADC value of a pot, (will use that later to read 3 switches on one pin).
It is all the PIC dependent declarations at the very beginning of the program that trip me up.

Bob

You have to crawl before you walk, and I am starting to crawl pretty well.

Acetronics2
- 31st January 2011, 09:05
I am not sure which program you are referring to?

Without any further notice we all were on posts #1 and #3 ...


The one That gave me the display was written by me on a PIC16F88 using C.

Of course result was not exactly that expected with #3 program ...


I gave up on the 16F1827 do to lack of programming knowledge and lack of sample programs for that chip. Now that I have a somewhat grasp on the basics, I have been able to read and display the ADC value of a pot, (will use that later to read 3 switches on one pin).
It is all the PIC dependent declarations at the very beginning of the program that trip me up.


So, comes the killing question ...

Did you notice we're aboard a PICBASIC PRO ( MeLabs brew ) forum, and we are supposed to "speak" Basic ??? :D

me too ...;)

Alain

Bobw55
- 31st January 2011, 13:47
Yes I do know this is a BASIC forum.
My post was only to thank those who were trying to help me get started.

Bob