K8LH Serial Backpack

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, Jan 9, 2014.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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.
     
  2. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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
     
    tracecom likes this.
  3. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    Here's my prototype. I am still having a couple of issues with it, but in the main, it works well. Thanks.
     
    MMcLaren likes this.
  4. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    @ 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.

    Code ( (Unknown Language)):
    1. ' Name: Serial LCD Tester.pbp
    2. ' Compiler: PICBASIC PRO Compiler 3
    3. ' Assembler: MPASM
    4. ' Author: tracecom
    5. ' Target PIC: 12F683
    6. ' Hardware: CRH Breadboard
    7. ' Oscillator: 4MHz Internal
    8. ' Description: PICBASIC PRO program to display test data via K8LM serial
    9.     ' backpack on 4 x 20 serial LCD.
    10.  
    11. ' Device Configuration:
    12. #IF __PROCESSOR__ = "12F683"
    13. #config
    14. cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
    15. cfg1&= _WDT_ON              ; Watch Dog Timer enabled
    16. cfg1&= _PWRTE_OFF           ; Power-up Timer disabled
    17. cfg1&= _MCLRE_ON            ; Master Clear Reset enabled
    18. cfg1&= _CP_OFF              ; Program Code Protection is disabled
    19. cfg1&= _CPD_OFF             ; Data Code Protection is disabled
    20. cfg1&= _BOD_OFF             ; Brown-out Detect disabled
    21. cfg1&= _IESO_OFF            ; Internal Externa Switchover mode is disabled
    22. cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor is disabled
    23.  __CONFIG  cfg1             ; Set the configuration bits  
    24. #ENDCONFIG
    25. #else
    26.  #MSG "Wrong microcontroller selected!"
    27. #endif
    28.  
    29. ' Register Initializations:
    30. ADCON0.7 = 1 ' Right justify result
    31. ANSEL = %00111001 ' Set clock to FRC and set AN0, AN3 analog, AN1, AN2 digital
    32. CMCON0 = 7 ' Analog comparators off
    33. TRISIO = %0011001
    34.  
    35. ' Includes:
    36. Include "modedefs.bas"   ' Mode definitions for serout
    37.  
    38. ' Defines:
    39. Define ADC_BITS     10   ' Set number of bits in result
    40. Define ADC_CLOCK    3    ' Set clock source (3=rc)
    41. Define ADC_SAMPLEUS 50   ' Set sampling time in uS
    42.  
    43. ' Constants:
    44.  
    45. ' Variables:
    46.  
    47. ' Aliases and Modifiers:
    48. LCD Var GPIO.5 ' LCD data out pin
    49.  
    50. ' Program Code:
    51. Pause 500 ' Wait .5 seconds for LCD to initialize
    52.  
    53. mainloop:
    54.  
    55. ' Display results  
    56. serout LCD,T9600,[$FE,$01]
    57. serout LCD,T9600,[$FE,$80+5]
    58. Serout LCD,T9600,["K8LH Serial"]
    59. serout LCD,T9600,[$FE,$C0+7]
    60. serout LCD,T9600,["Backpack"]
    61. serout LCD,T9600,[$FE,$94+10]
    62. serout LCD,T9600,["by"]
    63. serout LCD,T9600,[$FE,$D4+4]
    64. serout LCD,T9600,["Mike McLaren"]
    65. Pause 100 ' Wait 100mS
    66.  
    67. 'Goto mainloop ' Do it forever
    68.    
    69. End
    70.  
    71.  
     
  5. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    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:

    Code ( (Unknown Language)):
    1. 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.
     
    tracecom likes this.
  6. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    It was worth a try, but didn't help.

    Thanks.
     
  7. elec_mech

    Senior Member

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

    Code ( (Unknown Language)):
    1. DEFINE LCD_DREG PORTA    ' Set LCD Data port
    2.  
    3. DEFINE LCD_DBIT 0    ' Set starting Data bit (0 or 4) if 4-bit bus
    4.  
    5. DEFINE LCD_RSREG PORTA    ' Set LCD Register Select port
    6.  
    7. DEFINE LCD_RSBIT 4    ' Set LCD Register Select bit
    8.  
    9. DEFINE LCD_EREG PORTB   ' Set LCD Enable port
    10.  
    11. DEFINE LCD_EBIT 3    ' Set LCD Enable bit
    12.  
    13. DEFINE LCD_BITS 4    ' Set LCD bus size (4 or 8 bits)
    14.  
    15. DEFINE LCD_LINES 2    ' Set number of lines on LCD
    16.  
    17. DEFINE LCD_COMMANDUS 1500    ' Set command delay time in us
    18.  
    19. 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:

    Code ( (Unknown Language)):
    1. DEFINE LCD_DREG GPIO    ' Set LCD Data port
    2.  
    3. DEFINE LCD_DBIT 0    ' Set starting Data bit (0 or 4) if 4-bit bus
    4.  
    5. DEFINE LCD_RSREG GPIO    ' Set LCD Register Select port
    6.  
    7. DEFINE LCD_RSBIT 0   ' Set LCD Register Select bit - Not sure if D4 and RS can share same pin
    8.  
    9. DEFINE LCD_EREG GPIO   ' Set LCD Enable port
    10.  
    11. DEFINE LCD_EBIT 5    ' Set LCD Enable bit
    12.  
    13. DEFINE LCD_BITS 4    ' Set LCD bus size (4 or 8 bits)
    14.  
    15. DEFINE LCD_LINES 4    ' Set number of lines on LCD
    16.  
    17. DEFINE LCD_COMMANDUS 1500    ' Set command delay time in us
    18.  
    19. DEFINE LCD_DATAUS 44    ' Set data delay time in us
    20.  
    21. ANSEL = %00110000
    22.  
    While it is working, would changing SEROUT to LCDOUT change anything?
     
  8. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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.
     
  9. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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?
     
  10. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    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.
     
  11. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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.
     
  12. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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?
     
  13. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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.
     
  14. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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?
     
  15. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    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.

    Code ( (Unknown Language)):
    1. ' Name: Serial LCD Tester.pbp
    2. ' Compiler: PICBASIC PRO Compiler 3
    3. ' Assembler: MPASM
    4. ' Author: tracecom
    5. ' Target PIC: 12F683
    6. ' Hardware: CRH Breadboard
    7. ' Oscillator: 4MHz Internal
    8. ' Description: PICBASIC PRO program to display test data via K8LM serial
    9.     ' backpack on 4 x 20 serial LCD.
    10.  
    11. ' Device Configuration:
    12. #IF __PROCESSOR__ = "12F683"
    13. #config
    14. cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
    15. cfg1&= _WDT_ON              ; Watch Dog Timer enabled
    16. cfg1&= _PWRTE_OFF           ; Power-up Timer disabled
    17. cfg1&= _MCLRE_ON            ; Master Clear Reset enabled
    18. cfg1&= _CP_OFF              ; Program Code Protection is disabled
    19. cfg1&= _CPD_OFF             ; Data Code Protection is disabled
    20. cfg1&= _BOD_OFF             ; Brown-out Detect disabled
    21. cfg1&= _IESO_OFF            ; Internal External Switchover mode is disabled
    22. cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor is disabled
    23.  __CONFIG  cfg1             ; Set the configuration bits  
    24. #ENDCONFIG
    25. #else
    26.  #MSG "Wrong microcontroller selected!"
    27. #endif
    28.  
    29. ' Register Initializations:
    30.  
    31. ' Includes:
    32. Include "modedefs.bas"   ' Mode definitions for serout
    33.  
    34. ' Defines:
    35.  
    36. ' Constants:
    37.  
    38. ' Variables:
    39.  
    40. ' Aliases and Modifiers:
    41. LCD Var GPIO.5 ' LCD data out pin
    42.  
    43. ' Program Code:
    44. Pause 500 ' Wait .5 seconds for LCD to initialize
    45.  
    46. mainloop:
    47.  
    48. ' Display results  
    49. serout LCD,T9600,[$FE,$01]
    50. serout LCD,T9600,[$FE,$87]
    51. Serout LCD,T9600,["K8LH Serial"]
    52. serout LCD,T9600,[$FE,$C0+7]
    53. serout LCD,T9600,["Backpack"]
    54. serout LCD,T9600,[$FE,$94+10]
    55. serout LCD,T9600,["by"]
    56. serout LCD,T9600,[$FE,$D4+4]
    57. serout LCD,T9600,["Mike McLaren"]
    58. Pause 100 ' Wait 100mS
    59.  
    60. 'Goto mainloop ' Do it forever
    61.    
    62. 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.
     
  16. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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...
     
  17. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    Not to my knowledge. I was pleasantly surprised when it worked without change. I used what you provided in post #16 of this thread. http://forum.allaboutcircuits.com/showthread.php?t=93164&highlight=backpack&page=2
     
  18. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    If I'm reading your code correctly, it appears you did.

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

    Is your backpack designed for 8N1 and driven true?
     
  19. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    I think that I just loaded the hex file without looking at the asm until more recently.
     
  20. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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: Jan 28, 2014
Loading...