K8LH Serial Backpack

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Mike,

I decided to start a new thread on this rather than tack it on to the old one.

Because of the significant effort in breadboarding your design, and because it has already been vetted, I am going straight to a perfboard prototype. To that end, I have drawn my own schematic to follow as I wire the prototype.

Would you take a look and tell me if you see any errors? Thanks.
 

Attachments

MMcLaren

Joined Feb 14, 2010
861
Hi Trace':

That drawing looks correct. Good luck and please show us pictures when you're done... I built one onto the right hand portion of an 8/14/20 pin PIC protoboard and it works great (the contrast pot is located on the back of the LCD)...

Cheerful regards, Mike
 

Attachments

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
@ MMcLaren

I am using the following code in a 12F683 to output serial data to your serial backpack design that I built. I have noticed that when I use an odd number of spaces to advance the cursor on lines three and four of the LCD, the display does not respond correctly, but if I use an even number of spaces, the display does respond correctly.

I will post two photos; the first will be with the code as included in this post and the second will be with serout LCD,T9600,[$FE,$94+10] changed to serout LCD,T9600,[$FE,$94+9]

Do you think there could be something in your code that causes that? Or is there something I need to change in my code?

Thanks.

Rich (BB code):
' Name: Serial LCD Tester.pbp
' Compiler: PICBASIC PRO Compiler 3
' Assembler: MPASM
' Author: tracecom
' Target PIC: 12F683
' Hardware: CRH Breadboard
' Oscillator: 4MHz Internal
' Description: PICBASIC PRO program to display test data via K8LM serial
    ' backpack on 4 x 20 serial LCD.

' Device Configuration:
#IF __PROCESSOR__ = "12F683"
#config
cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
cfg1&= _WDT_ON              ; Watch Dog Timer enabled
cfg1&= _PWRTE_OFF           ; Power-up Timer disabled
cfg1&= _MCLRE_ON            ; Master Clear Reset enabled
cfg1&= _CP_OFF              ; Program Code Protection is disabled
cfg1&= _CPD_OFF             ; Data Code Protection is disabled
cfg1&= _BOD_OFF             ; Brown-out Detect disabled
cfg1&= _IESO_OFF            ; Internal Externa Switchover mode is disabled
cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor is disabled
 __CONFIG  cfg1             ; Set the configuration bits   
#ENDCONFIG
#else
 #MSG "Wrong microcontroller selected!"
#endif

' Register Initializations:
ADCON0.7 = 1 ' Right justify result
ANSEL = %00111001 ' Set clock to FRC and set AN0, AN3 analog, AN1, AN2 digital
CMCON0 = 7 ' Analog comparators off
TRISIO = %0011001

' Includes:
Include "modedefs.bas"   ' Mode definitions for serout

' Defines:
Define ADC_BITS     10   ' Set number of bits in result
Define ADC_CLOCK    3    ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50   ' Set sampling time in uS

' Constants:

' Variables:

' Aliases and Modifiers:
LCD Var GPIO.5 ' LCD data out pin

' Program Code:
Pause 500 ' Wait .5 seconds for LCD to initialize

mainloop:

' Display results   
serout LCD,T9600,[$FE,$01]
serout LCD,T9600,[$FE,$80+5]
Serout LCD,T9600,["K8LH Serial"]
serout LCD,T9600,[$FE,$C0+7]
serout LCD,T9600,["Backpack"]
serout LCD,T9600,[$FE,$94+10]
serout LCD,T9600,["by"]
serout LCD,T9600,[$FE,$D4+4]
serout LCD,T9600,["Mike McLaren"]
Pause 100 ' Wait 100mS

'Goto mainloop ' Do it forever
   
End
 

Attachments

elec_mech

Joined Nov 12, 2008
1,500
Tracecom,

Cool project. I looked at your code - everything looks good to me, but I do see in the manual that PBP is by default set to a 2-line display whereas you are using a 4-line display. Try adding the following line of code to your DEFINE's section:

Rich (BB code):
DEFINE LCD_LINES 4         ' Set number of lines on LCD
I suspect because the compiler *thinks* you are using a 2-line display, it somehow interprets serout LCD,T9600,[$FE,$94+9] as a lowercase m.
 

elec_mech

Joined Nov 12, 2008
1,500
Hmmm. Take a look at all the DEFINE's for the LCD command in the manual:

Rich (BB code):
DEFINE LCD_DREG PORTA    ' Set LCD Data port

DEFINE LCD_DBIT 0    ' Set starting Data bit (0 or 4) if 4-bit bus

DEFINE LCD_RSREG PORTA    ' Set LCD Register Select port

DEFINE LCD_RSBIT 4    ' Set LCD Register Select bit

DEFINE LCD_EREG PORTB   ' Set LCD Enable port

DEFINE LCD_EBIT 3    ' Set LCD Enable bit

DEFINE LCD_BITS 4    ' Set LCD bus size (4 or 8 bits)

DEFINE LCD_LINES 2    ' Set number of lines on LCD

DEFINE LCD_COMMANDUS 1500    ' Set command delay time in us

DEFINE LCD_DATAUS 44    ' Set data delay time in us
I wonder if you need to specify something like GPIO in place of the PORTA instances? Also, since there is no port B, maybe define EREG as GPIO as well? Then EBIT should be 5.

Not sure if you need a pin for the register select bit or if you can use GPIO.0 as you have connected.

Also not sure if you need to use GPIO.0 - 3 exclusively for D4-D7, respectfully. This is how it is shown in the example in the manual.

The manual also states the analog pins should all be set to digital inputs. You have some set as digital and some as analog.

Perhaps:

Rich (BB code):
DEFINE LCD_DREG GPIO    ' Set LCD Data port

DEFINE LCD_DBIT 0    ' Set starting Data bit (0 or 4) if 4-bit bus

DEFINE LCD_RSREG GPIO    ' Set LCD Register Select port

DEFINE LCD_RSBIT 0   ' Set LCD Register Select bit - Not sure if D4 and RS can share same pin

DEFINE LCD_EREG GPIO   ' Set LCD Enable port

DEFINE LCD_EBIT 5    ' Set LCD Enable bit

DEFINE LCD_BITS 4    ' Set LCD bus size (4 or 8 bits)

DEFINE LCD_LINES 4    ' Set number of lines on LCD

DEFINE LCD_COMMANDUS 1500    ' Set command delay time in us

DEFINE LCD_DATAUS 44    ' Set data delay time in us

ANSEL = %00110000
While it is working, would changing SEROUT to LCDOUT change anything?
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
While it is working, would changing SEROUT to LCDOUT change anything?
I don't know. I think that LCDOUT is just for controlling an LCD in the parallel mode, hence all the defines that have to do with an entire port as opposed to a single I/O. I think that SEROUT has to be used with a single port and serial data transmission. But I am very much in the experimental mode.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I did some testing.

I can insert any digit 1 through 19 in the serout command for rows 1 and 2, and it works fine.

But on rows 3 and 4, digits 1, 3, 5, 7, 9, and 11 result in the substitution of an ASCII character instead of moving the cursor the correct number of spaces to the right. In addition, the error includes moving the entire text string to the first open space in the previous row.

Attached is a chart showing which ASCII characters are substituted for each digit 1, 3, 5, 7, 9, and 11 for both the 3rd and 4th rows. As you can see, all the errors have a 1 as the LSB in the lower 4 bits.

There's a clue there, but I haven't figured out what it means.

Maybe Mike's code was never meant to work with a 20 x 4 display?
 

Attachments

elec_mech

Joined Nov 12, 2008
1,500
I don't know. I think that LCDOUT is just for controlling an LCD in the parallel mode, hence all the defines that have to do with an entire port as opposed to a single I/O. I think that SEROUT has to be used with a single port and serial data transmission. But I am very much in the experimental mode.
I'm a little confused, but this thread appears to come from another one that I haven't seen so that may be the reason. Is your code for the 12F683 in the schematic which is connected to the LCD or is it for another PIC that is sending data to the 12F683?

If the latter, I'd have to see what the code is on the 12F683 connected directly to the LCD and the whole schematic showing how both PICs are connected. If the code on the 12F683 was written by MMcLaren, I'll leave it to him.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I'm a little confused, but this thread appears to come from another one that I haven't seen so that may be the reason. Is your code for the 12F683 in the schematic which is connected to the LCD or is it for another PIC that is sending data to the 12F683?

If the latter, I'd have to see what the code is on the 12F683 connected directly to the LCD and the whole schematic showing how both PICs are connected. If the code on the 12F683 was written by MMcLaren, I'll leave it to him.
Sorry, I should have explained. Mike wrote some assembly code to function in a serial backpack that converts serial data from a PIC to a parallel format for the HD44780-compliant LCD. That project is described here, starting about post 12. http://forum.allaboutcircuits.com/showthread.php?t=93164&highlight=backpack&page=2

I built the hardware Mike designed and mounted it on the rear of an LCD. Then, I programmed (in PBP) another 12F683 with a test program that outputs serial data to the backpack, which converts it to parallel and displays it.
 

MMcLaren

Joined Feb 14, 2010
861
@ MMcLaren

I am using the following code in a 12F683 to output serial data to your serial backpack design that I built. I have noticed that when I use an odd number of spaces to advance the cursor on lines three and four of the LCD, the display does not respond correctly, but if I use an even number of spaces, the display does respond correctly.
Hi Trace',

Sorry for late reply. I don't see any obvious problem in my backpack firmware. Sorry.

Are you using a 12F683 on 4-MHz INTOSC with PBP bit-banged serial driver? If so, what baud rate? It might help PBP if you use the 8-MHz INTOSC setting.

Is there a chance you could try the same program on another device with a hardware serial port module?
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Mike,

Thanks for your response.

Here is what I hypothesize is happening in the firmware.

Whenever the control code is sent for moving the cursor to the beginning of row 3, + 1, 3, 5, 7, 9, or 11 spaces, the command is being interpreted as 30h less than is being sent. For example, the code to move the cursor to the fourth space on row three is 97h, but when that is sent, the firmware interprets it as 67h. Thus, it prints a "g" (ascii 67h) at the end of row 2.

Likewise, whenever the control code is sent for moving the cursor to the beginning of row 4 + 1, 3, 5, 7, 9, or 11 spaces, the command is being interpreted as 60h less than is being sent. For example, the code to move the cursor to the sixth space on row four is D9h, but when that is sent, the firmware interprets it as 79h. Thus, it prints a "y" (ascii 79h) at the end of row 3.

Unfortunately, I lack the skills to make the changes in the firmware to test my hypothesis.
 

MMcLaren

Joined Feb 14, 2010
861
Hi Trace',

Still need some background info, please. (1) 12F683 clock is? (2) Are you using PBP bit-banged serial driver? (3) Baud rate is? (4) Did you modify the ezLCD backpack firmware?
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Hi Trace',

Still need some background info, please. (1) 12F683 clock is? (2) Are you using PBP bit-banged serial driver? (3) Baud rate is? (4) Did you modify the ezLCD backpack firmware?
The clock is running at 4mHz; I tried 8mHz with no change.

I am not sure what bit-banged serial driver is. I am designating GPIO.5 as the LCD out pin. Then, I send a $FE signal followed by whatever command is needed. My code follows.

Rich (BB code):
' Name: Serial LCD Tester.pbp
' Compiler: PICBASIC PRO Compiler 3
' Assembler: MPASM
' Author: tracecom
' Target PIC: 12F683
' Hardware: CRH Breadboard
' Oscillator: 4MHz Internal
' Description: PICBASIC PRO program to display test data via K8LM serial
    ' backpack on 4 x 20 serial LCD.

' Device Configuration:
#IF __PROCESSOR__ = "12F683"
#config
cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
cfg1&= _WDT_ON              ; Watch Dog Timer enabled
cfg1&= _PWRTE_OFF           ; Power-up Timer disabled
cfg1&= _MCLRE_ON            ; Master Clear Reset enabled
cfg1&= _CP_OFF              ; Program Code Protection is disabled
cfg1&= _CPD_OFF             ; Data Code Protection is disabled
cfg1&= _BOD_OFF             ; Brown-out Detect disabled
cfg1&= _IESO_OFF            ; Internal External Switchover mode is disabled
cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor is disabled
 __CONFIG  cfg1             ; Set the configuration bits   
#ENDCONFIG
#else
 #MSG "Wrong microcontroller selected!"
#endif

' Register Initializations:

' Includes:
Include "modedefs.bas"   ' Mode definitions for serout

' Defines:

' Constants:

' Variables:

' Aliases and Modifiers:
LCD Var GPIO.5 ' LCD data out pin

' Program Code:
Pause 500 ' Wait .5 seconds for LCD to initialize

mainloop:

' Display results   
serout LCD,T9600,[$FE,$01]
serout LCD,T9600,[$FE,$87]
Serout LCD,T9600,["K8LH Serial"]
serout LCD,T9600,[$FE,$C0+7]
serout LCD,T9600,["Backpack"]
serout LCD,T9600,[$FE,$94+10]
serout LCD,T9600,["by"]
serout LCD,T9600,[$FE,$D4+4]
serout LCD,T9600,["Mike McLaren"]
Pause 100 ' Wait 100mS

'Goto mainloop ' Do it forever
   
End
9600 baud

No modifications of any kind to the firmware.

Thanks again for your response.

ETA: Don't worry with this unless it's something you want to do.
 

MMcLaren

Joined Feb 14, 2010
861
Hi Trace',

Did I give you custom backpack firmware for 9600 baud? I ask because the default backpack baud rate is 57600 which means it shouldn't be working at all with your PBP program...
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944

elec_mech

Joined Nov 12, 2008
1,500
Did I give you custom backpack firmware for 9600 baud?
If I'm reading your code correctly, it appears you did.

Rich (BB code):
clock   equ     8               ; 8 MHz clock
usecs   equ     clock/4         ; cycles/usec multiplier
msecs   equ     clock/4*1000    ; cycles/msec multiplier
bRate   equ     9600            ; baudrate 19200, 57600 or 115200
bTime   equ     (usecs*10000000/bRate+5)/10
                                ; bTime = 104, 35 or 17 cycles
Assuming this to be the case, the PBP manual states SEROUT:

Sends one or more items to Pin in standard asynchronous format using 8 data bits, no parity and one stop (8N1).
Is your backpack designed for 8N1 and driven true?
 

MMcLaren

Joined Feb 14, 2010
861
It looks like that code is setup for 9600 baud. I don't remember running the backpack at 9600 baud before so I should probably check it out in the simulator and make sure my delay subsystem supports that baud rate. I may have done that already but I don't remember. Give me a few to check it out and I will get back to you...

If this is a problem that I caused, I apologize...
 
Last edited:
Top