PDA

View Full Version : Newbie? Problem with LCD



lew247
- 7th December 2009, 12:43
Hi All,
I put myself down as a newbie even though I played with Pic's over a year ago.
The problem I have stems from I had a severe brain injury and had to undergo surgery, and since then I have had problems remembering things.

I've had to start leaning about Pic's and PBP from scratch really.

To help myself I bought an easypic 6 but decided to stick with PBP instead of Mikrobasic (had a quick look and it seemed really hard compared to PBP)

I cant figure out what I'm doing wrong,
I'm trying to get the simle "hello world" lcd test working but it just wont

My code is as follows

'************************************************* ***************
'* Name : Test.BAS *
'* Author : Lewis *
'* Notice : *
'* : All Rights Reserved *
'* Date : 07/12/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic16F887,HS_OSC
'LCD DEFINATION
DEFINE OSC 8
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0)
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit, Port B.4
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 5 ' Set LCD Enable bit, PORTB.5
DEFINE LCD_BITS 4 ' Set LCD bus size 4 bits
DEFINE LCD_LINES 2 ' Set number of lines on LCD to 4 Lines
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

'************************************************* ******************************
pause 500 ' Wait for LCD to startup

loop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second

Goto loop ' Do it forever

I set it like that after studying the easypic manual and lcd that came with it
http://i256.photobucket.com/albums/hh175/karenhornby/Capture-4.jpg
I use MicroCode Studio

The programmer is the picflash program that came with the easypic board, the xtal is 8Mhz

When I write the program in Microcode Studio I get a wierd effect when choosing a 16F887 PIC
the ICD Compile row of buttons goes greyed out, yet they dont when choosing a 16F877
Does this matter?


I get the following error when I compile I have no idea what it is.
Warning [207]C:P\pbp\tests\lcdtes~1.asm 108 : found label after colum 1. (DEVICE)
Error [122] c:\pbp\tests\cdtes~1.asm 108 : Illegal opcode (pic16f877)

IF I take the @ DEVICE pic16F877,HS_OSC out and put it as the first line of the program it does the same thing

If I take it out altogether it compiles ok but just won't do anything with the LCD.

I don't want anyone to write any code for me, I want and need to learn, however I'd really like someone to help please and explain what I'm doing wrong please.

I also tried changing the osc to xt but it makes no difference.

Has anyone any ideas? and sorry for asking for help for what must be to most of you a very simple problem, but I've spent 3 days trying to figure out what is wrong, as well as trying various combinations of code.

Oh Picflash v7.13
Microcode Studio ver 3.0.0.5
PBP ver I THINK it's 2.50C but not sure how to check.
Windows 7 X64

lew247
- 7th December 2009, 15:29
after much more reading I came up with the following, but it still doesn't do anything.
I tested the board and pic by using the blinking led program and it works, and then modified that to alternativly turn on then off each led on port B (cycle through them) and that works, so the board works fine

I just cant figure out how to get the lcd working.


define device pic16F887,HS_osc
Define OSC 8
adcon1 = 7
trisb=%00000000

'************************************************* ***************
'* Name : Test.BAS *
'* Author : Lewis *
'* Notice : *
'* : All Rights Reserved *
'* Date : 07/12/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

'LCD DEFINATION
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0)
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit, Port B.4
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 5 ' Set LCD Enable bit, PORTB.5
DEFINE LCD_BITS 4 ' Set LCD bus size 4 bits
DEFINE LCD_LINES 2 ' Set number of lines on LCD to 4 Lines
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

'************************************************* ******************************
pause 500 ' Wait for LCD to startup

loop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second

Goto loop ' Do it forever

Anyone?

Acetronics2
- 7th December 2009, 15:44
Ok, lew

Seems you use MPASM as an assembler ...

so don't use PM commands !



@ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF


should Work somewhat better ...

Alain

rmteo
- 7th December 2009, 16:12
You think this MikroBASIC code is more difficult than what you came up with?


program Lcd_demo

main:

Lcd_Init(PORTB) ' Initialize LCD connected to PORTB
Delay_ms(500)

While true

Lcd_Cmd(LCD_CLEAR) ' Send command to LCD "clear display"
Lcd_Out(1,1,"Hello") ' Print txt to LCD, 1st row, 1st column
Delay_ms(500)

Lcd_Cmd(LCD_CLEAR) ' Send command to LCD "clear display"
Lcd_Out(2,1,"World") ' Print txt to LCD, 2nd row, 1st column
Delay_ms(500)

Wend

end.

sayzer
- 7th December 2009, 16:21
lew247,

Your problem is at PORTB config;

For 16F887, there are some registers controlling PORTB.
You have non of them configured.

If you use the LCD with PORTD, you need no setting for the port. I am sure it will work.
But I am not sure if you can switch to PORTD with your existing pcb.

------------

Acetronics2
- 7th December 2009, 16:43
You think this MikroBASIC code...



Hi, Rmteo

PBP also has the While - Wend loops ... LOL

Seriously ... Having tested both ... on " real " programs.

No comparison possible ... MkBasic FAR Behind ...


BTW ... If you'd want a C Pro license ... I GIVE you mine.

Not Joking at all !

Alain

lew247
- 7th December 2009, 17:12
Ok, lew

Seems you use MPASM as an assembler ...

so don't use PM commands !



@ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF


should Work somewhat better ...

Alain


Sorry I forgot totally about that, PM would not work at all,because I have an X64 system

For some reason @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF will not work

If I add it at the beginning I get Error [118] c:\pbp\tests\cdtes~1.asm 108 : Overwriting previous address contents (2007)

If I put this at the beginning of the program it compiles with no errors but won't work.

Define Device 16f887
Define OSC 8
adcon1 = 7
PORTB = %00000000
TRISB = %00000000
IOCB = 0
CM1CON0 = 0
CM2CON0 = 0
CCP1CON = 0
CM2CON1 = 0
INTCON = 0


I checked the datasheet of the 16f887 (using this because it came supplied with it) and I THINK I've configured all registers on PortB


It would be good if I could change LCD pins as suggested but unfortunately not possible on this board.
And I need to learn what is wrong so next time I won't (hopefully) need to ask for help.

Acetronics2
- 7th December 2009, 17:43
If I add it at the beginning I get Error [118] c:\pbp\tests\cdtes~1.asm 108 : Overwriting previous address contents (2007)


Yes ...

With MPLAB you also must comment the PBP default config in the relevant .inc file ...

see details here:

http://www.picbasic.co.uk/forum/showthread.php?t=543

...

Alain

rmteo
- 7th December 2009, 17:54
Hi, Rmteo

PBP also has the While - Wend loops ... LOL

Seriously ... Having tested both ... on " real " programs.

No comparison possible ... MkBasic FAR Behind ...


BTW ... If you'd want a C Pro license ... I GIVE you mine.

Not Joking at all !

Alain

Although I am not a C user, I'll take it. :)

lew247
- 7th December 2009, 18:03
Got it working at last :)
Thanks for all the help everyone.

I think the problem I had was I was trying to overwrite the inc files without realising.

I now have @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
as the config

However the programmer always tried to program in low voltage mode, I have to manually set it to off.

I'd like to sort that out, but I can live with it if needed.

Edit: Works with 16F877A but not 16F887 for some weird reason!

found it!

This works for the 16f887

@ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
Define device 16F887
Define OSC 8
ANSEL=0 ' A/D disabled for ANS0 to ANS7
ANSELH=0 ' A/D disabled for ANS8 to ANS13
CM1CON0 = 0 ' Disable comparators
CM2CON0 = 0 ' These default to disabled at POR, but just in case
CM2CON1 = 0
adcon1 = 7
IOCB = 0
INTCON = 0
ansel = 0
anselh = 0
PORTB = %00000000
TRISB = %00000000

However still got the programming issued I've got to set the low power programming to off manually and the oscillator to HS

Acetronics2
- 7th December 2009, 19:48
May be you should have a look to the upper part of the MPLAB Configuration bits window ...

an option to choose ...


Alain