PDA

View Full Version : Need idea hove to..?



phoenix_1
- 11th May 2008, 21:19
I need to displey specific data on LCD 4x20 chr.
Data will be received via RS232 on PIC 16F877 on HSER on PIC MCU.
Did someone have best idea what to I send from PC to PIC?
Example from me:
If I send somethig like 1DOG that maybe I can decode in pic like print on LCD in first line DOG.
But what about if I want to specific also on wich position of disply I will display that word DOG ?
Do someone want help with some simple example PLEASE.

That problem is part of my idea to bulid some type of terminal with 4x4 matrix keyboard where I will send No of key waht was push ( I was test mister_e keyboard rutine and it work super).And also I need in same time to display return from PC on LCD 4x20 chr when specific key is push.

Any suggest is welcome please.
Regards to all Mr.Robert - phoenix_1

DaveC3
- 11th May 2008, 23:57
Mr Robert

Here is some code I used for a 4X40 display (the reason for E1 and E2). It may give you an idea how to send data to the LCD from the PC. I assume you have a program that can be written to send and receive data via the serial port in your PC.



' PicBasic program to demonstrate operation of an LCD in 4-bit mode
' LCD DMC40457 W/backlight 16F876
' LCD should be connected as follows:
' PIN--LCD PIC 4016
' 4 DB4 PortB.4
' 3 DB5 PortB.5
' 2 DB6 PortB.6
' 1 DB7 PortB.7
' 11 RS PortB.0
' E PortB.1 pin 8 & 11
' 10 RW Ground
' 14 Vdd 5 volts
' 13 Vss Ground
' 12 Vo 10K potentiometer (or ground)
' DB0-3 No connect
' 9 E1 To enable logic ckt pin 9
' 15 E2 as above pin 10
'Backlight controled via a NPN transistor with 1K resistor from porta.2 to base.
' E1 & E2 controlled via a bilaterial switch 4016
' portc.4 pin 6
' portc.5 pin 12
'************************************************* ********************************

DEFINE LOADER_UESD 1 'Enable bootloader
DEFINE OSC 20 ' 20Mhz Xtl
DEFINE HSER_RCSTA 90h 'Set up USART
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600


DEFINE LCD_DREG PORTB 'Set up LCD Data Portb
DEFINE LCD_DBIT 4 ' bit 4 - 8 data bus
DEFINE LCD_RSREG PORTB 'RS portb.0
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB 'E portb.1
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4 '4 data bits
DEFINE LCD_LINES 2 '2 lines
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
ADCON1 = 7 'Make porta all digital
trisa = %00000000 'Make porta all outputs
output portc.4 ' E1 to 4016
output portc.5 ' E2 to 4016


RCIF VAR PIR1.5 ' Alias RCIF (USART Receive Interrupt Flag)
OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag)
CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable)

buffer_size CON 32 ' Sets the size of the ring buffer
buffer VAR BYTE[buffer_size] ' Array variable for holding received characters
index_in VAR BYTE ' Pointer - next empty location in buffer
index_out VAR BYTE ' Pointer - location of oldest character in buffer
bufchar VAR BYTE ' Stores the character retrieved from the buffer
bufchar1 VAR BYTE
i VAR BYTE ' loop counter
col VAR BYTE ' Stores location on LCD for text wrapping
errflag VAR BYTE ' Holds error flags
A VAR BYTE
E1 VAR portc.4 'E1 control to 4016
E2 VAR portc.5 'E2 control to 4016

index_in = 0 'Initalize varialbles
index_out = 0
i = 0
col = 1
low porta.2 'turn off backlight
errflag = 0 ' Reset the error flag
INTCON = %11000000 ' Enable interrupts
On INTERRUPT GoTo serialin ' Declare interrupt handler routine
PIE1 .5 = 1 ' Enable interrupt on USART
high E1 ' Enable E1
High E2 ' Enable E2




Pause 500 ' Wait for LCD to startup

START:
GOSUB OPENING 'Staart lcd display indication
Lcdout $fe, 1 'clear LCD
low E2 ' Disable E2 turn off second half of display
GOTO LOOP
LOOP:



display: ' dump the buffer to the LCD

IF errflag Then error ' Handle error if needed
If index_in = index_out Then Loop ' loop if nothing in buffer

GoSub getbuf ' Get a character from buffer
'IF bufchar = 253 THEN CONT 'if control character is detected go to control
LCDOut bufchar ' Send the character to LCD


GoTo display ' Check for more characters in buffer



' Subroutines

Disable ' Don't check for interrupts in this section

getbuf: ' move the next character in buffer to bufchar
index_out = (index_out + 1) ' Increment index_out pointer (0 to 63)
If index_out > (buffer_size - 1) Then index_out = 0 ' Reset pointer if outside of buffer
bufchar = buffer[index_out] ' Read buffer location
IF bufchar = 253 THEN CONT 'if control character is detected go to control
Return

error: ' Display error message if buffer has overrun
IF errflag.1 Then ' Determine the error
LCDOut $FE,$c0,"Buffer Overrun" ' Display buffer error on line-2
Else
LCDOut $FE,$c0,"USART Overrun" ' Display usart error on line-2
EndIf

LCDOut $fe,2 ' Send the LCD cursor back to line-1 home
For i = 2 To col ' Loop for each column beyond 1
LCDOut $fe,$14 ' Move the cursor right to the right column
Next i

errflag = 0 ' Reset the error flag
CREN = 0 ' Disable continuous receive to clear overrun flag
CREN = 1 ' Enable continuous receive

GoTo display ' Carry on


' Interrupt handler

serialin: ' Buffer the character received
If OERR Then usart_error ' Check for USART errors
index_in = (index_in + 1) ' Increment index_in pointer (0 to 63)
If index_in > (buffer_size - 1) Then index_in = 0 'Reset pointer if outside of buffer
If index_in = index_out Then buffer_error ' Check for buffer overrun
HSerin [buffer[index_in]] ' Read USART and store character to next empty location
If RCIF Then serialin ' Check for another character while we're here

Resume ' Return to program

buffer_error:
errflag.1 = 1 ' Set the error flag for software
' Move pointer back to avoid corrupting the buffer. MIN insures that it ends up within the buffer.
index_in = (index_in - 1) MIN (buffer_size - 1)
HSerin [buffer[index_in]] ' Overwrite the last character stored (resets the interrupt flag)
usart_error:
errflag.0 = 1 ' Set the error flag for hardware

Resume ' Return to program



cont:

index_out = (index_out + 1) ' Increment index_out pointer (0 to 63)
If index_out > (buffer_size - 1) Then index_out = 0 ' Reset pointer if outside of buffer
bufchar = buffer[index_out] ' Read buffer location
if bufchar = "A" then E1_ ' enable 1st half of display
if bufchar = "C" then E2_ 'enable 2nd half of display
if bufchar = "B" then BL_On 'backlight on
if bufchar = "F" then BL_Off 'backlight off

goto display


E1_:
high E1
Low E2
PAUSE 50
Lcdout $fe, 2
goto display

E2_
low E1
High E2
Pause 50
Lcdout $fe, 2
goto display

BL_On:
high porta.2
goto display

BL_Off:
low porta.2
goto display


OPENING:
FOR A = 1 TO 2
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "LCD" ' Display Hello

Pause 500 ' Wait .5 second
'enable debug

Lcdout $fe, 1 ' Clear LCD screen
Lcdout $FE, $C0
Lcdout "ACTIVE"

Pause 500 ' Wait .5 second
'enable debug

NEXT A

RETURN

end

phoenix_1
- 13th May 2008, 18:12
via hserout i can get pushed key 100% ok but can't drive 4x20lcd,how to define ???
data lines are on a0 to a43 port and command are on c0 and c1

skimask
- 13th May 2008, 18:21
but can't drive 4x20lcd,how to define ???
data lines are on a0 to a43 port and command are on c0 and c1

phoenix,
Read the PBP manual, specifically the section on how to define the pins to be used for driving an LCD and your project will rise from the ashes.

Another case of RTFM...

phoenix_1
- 13th May 2008, 20:03
phoenix,
Read the PBP manual, specifically the section on how to define the pins to be used for driving an LCD and your project will rise from the ashes.

Another case of RTFM...

I was probe on 2x16 chr and work fine with 4x20 don't want work .
I dont know what is problem becouse i was never use 4x20!
Any sugest
Sorry for my bad english!
Regards

skimask
- 13th May 2008, 20:23
I was probe on 2x16 chr and work fine with 4x20 don't want work .
I dont know what is problem becouse i was never use 4x20!
Any sugest
Sorry for my bad english!
Regards

Yes, a good suggestion is to re-read the PBP manual...as suggested in my last post. The define's you need are there.
Between that and the datasheet for the 16F877(a?), you should be able to figure out what is wrong.
We haven't seen any of the code you may (or may not) have written, no idea of your schematic (except for a vague idea of how you have connected your LCD, which leaves a bit to be desired), and not really much of an idea what you have tried so far.

For example, my truck's 'Check Engine' lamp is illuminated. What's wrong with it?
Not a lot of information is there?
And your English, while not perfect, is fine.

phoenix_1
- 14th May 2008, 05:37
Yes, a good suggestion is to re-read the PBP manual...as suggested in my last post. The define's you need are there.
Between that and the datasheet for the 16F877(a?), you should be able to figure out what is wrong.
We haven't seen any of the code you may (or may not) have written, no idea of your schematic (except for a vague idea of how you have connected your LCD, which leaves a bit to be desired), and not really much of an idea what you have tried so far.

For example, my truck's 'Check Engine' lamp is illuminated. What's wrong with it?
Not a lot of information is there?
And your English, while not perfect, is fine.

Here are defines:

define OSC 20
ADCON0.0 = 0
ADCON1 = 7
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4 ******************when is 2 and I use 2x16 it work 100%
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

As you see:

LCD Wire PIC
RS --------------portc.0 -----> 4K7 pullup to +5V
E----------------portc.1
D4---------------porta.0
D5---------------porta.1
D6---------------porta.2
D7---------------porta.3

And that work 100% fine with 2x16 when I redefine No:. of lines of LCD.

skimask
- 14th May 2008, 12:50
Try increasing the 'startup pause', give the LCD more time to start itself before you start sending data. Double check your contrast wiring/voltage.

phoenix_1
- 14th May 2008, 15:44
Try increasing the 'startup pause', give the LCD more time to start itself before you start sending data. Double check your contrast wiring/voltage.

Hi skimask I was probe 1000 ms pause on startup and was probe on same pcb 2x16 chr it work and last solution is to lcd is fabric dead or bad ?!

pinout is same on 2x16 and that 4x20 and when 2x16 work and that not must be something with 4x20 wrong or maybe is problem in pbp2.50 maybe some bug ????

Really it is big problem for me...
Many thanks to all who was and will probe to help me !

Regards

p.s " The diference is only in define of no:. of lines betwin 2x16 and 4x20. and with same hardware 2x16 work and 4x20 have after reset time back all chr on screen !"

mackrackit
- 14th May 2008, 16:05
Do you have pin #3 on the display going to a pot as a voltage divider for contrast?

phoenix_1
- 14th May 2008, 16:30
Do you have pin #3 on the display going to a pot as a voltage divider for contrast?

You have 100% good question !!!!
When I was use 2x16chr display it have bad contrast and I was see TEST on it,but 4x20 have extra contrast and with same value all poligons are black at these oment I was reduce fix resistors on network on pin 3 and problem go out I can look normaly and 4x20 work fine.

The best thing is have mentors out of personal laboratory !
Other can find what you cant in your project ;-)).

The best regards to all

skimask
- 14th May 2008, 16:51
So, can we infer that all is well now and is working ok?
(a few things are getting lost in the English translation :) )

phoenix_1
- 14th May 2008, 17:16
So, can we infer that all is well now and is working ok?
(a few things are getting lost in the English translation :) )

Yes my dear friend work 100% ok.
Many hank's o all you !!!
I little think about some small problems but in core all work good.

Here is little more about what I probe to do.

In project I have one RS232 conection via hser in 877 to pc via max 232,one 4x20 chr lcd (that problematic hehehe) and 4x4 matrix keyboard.
Device must work on next way:
1.it must send no:. of key what is push by persone who use it.
2.in middle time it must display what return application from pc via rs232 on lcd.
3.application return some instructions like words like "DOG" or "CAT"or...and position where it will be displayed on lcd by line and row - position in line 1,2,3 or 4.
It is something like terminal for PC.

For now I success send key no:. with mister_e rutine for matrix keyboard
But I stil look hove to configure that famose from PC to PIC...

Maybe somethin like 1,5,DOG or ???
And hove to I decode that ?

I was use 877 with Nokia 6210 and there I was use skip xxx chr and get message and decode it like bite but here I dont know hove to start.


Regards to all ( any suggest is welcome).

Sorry for bad english again !!!

Robert

mackrackit
- 14th May 2008, 18:41
This might get you started.

Read all data from the PC into an array in the PIC.


[WAIT("?"),STR NUMS\8]
The above will wait for "?" (could be whatever you want) and the next part will put the rest of the data in an array that has 8 places.

The array will start at 0, so if you wrote it out it would look like this:
NUMS[0]
NUMS[1]
NUMS[2]
NUMS[3]
NUMS[4]
NUMS[5]
NUMS[6]
NUMS[7]

Now you can make each part a variable that is a bit easier to work with:
X1 = NUMS[0]
X2 = NUMS[1]
X3 = NUMS[2]
X4 = NUMS[3]
X5 = NUMS[4]
X6 = NUMS[5]
X7 = NUMS[6]
X8 = NUMS[7]

Now lets say X1 is equal to 1 and you want to start display at line 1 position 2.

LCDOUT $FE, $80 + X1
$80 is line 1 position 1. (refer to the manual for more)

Now to display some of the other data:


LCDOUT $FE,$80 + X1,X2,X3,X4

X2 = D
X3 = O
X4 = G

Something like that maybe.