Serout2 on LCD Shows Junk Characters


Results 1 to 11 of 11

Threaded View

  1. #6


    Did you find this post helpful? Yes | No

    Default Re: Serout2 on LCD Shows Junk Characters

    If I'm using RA0, do I need to set those registers? Because without them the screen is completely blank:

    Code:
    '****************************************************************
    '*  Name    : Test_SPWM.pbp                                     *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 9/30/2006                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    
    ; LCD serout2 command won't work when using interrupts; need to use
    ; HSEROUT on chip's USART tx pin instead.
    
    
    
    ' ***************************************************************
    ' Pin Connections
    ' ***************************************************************
    
    ' RA0                        -> Serial LCD output
    ' RA1                        -> Middle arm of trim pot (AN1)
    ' RC0                        -> LED1
    ' RC1                        -> LED2
    ' RC2                        -> LED3
    
    DEFINE OSC          16      ; Set oscillator 16Mhz
    ;DEFINE OSC           4      ; Set oscillator 4Mhz
    DEFINE ADC_BITS      8      ; Set number of bits in result
    DEFINE ADC_SAMPLEUS  5      ; Set sampling time in uS
    DEFINE ADC_CLOCK     3      ; Set clock source (3=rc)
    
    DEFINE  HSER_TXSTA   20h    ; Set transmit status and control register
    DEFINE  HSER_BAUD    2400   ; Set baud rate
    
    ' ***************************************************************
    ' Device Fuses
    ' ***************************************************************
    #CONFIG
       __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
       __config _CONFIG2, _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    #DEFINE USE_LCD_FOR_DEBUG   ; comment out for non-debug use
    
    ' ***************************************************************
    ' Initialization
    ' ***************************************************************
    
    OSCCON   = %01111000        ' 16MHz internal osc
    ;OSCCON   = %01101000        ' 4MHz internal osc
    
    pause 100
    
    ; Use PortA.1 (AN1) for ADCIN (trim pot reading)
    ANSELA   = %00000010        ; Analog on PORTA.1 (AN1) only
    TRISA    = %00000010        ; Input on PORTA.1 (AN1) only
    ;ADCON1   = %01110000        ; Left-justified results in 8-bits; Fosc/8 (2uS @ 4Mhz)
    ADCON1.7 = 0                ; Left-justified results in 8-bits; Fosc/8 (2uS @ 4Mhz)
    ANSELC   = 0                ; Diginal only for all PortC pins
    TRISC    = %00000000        ; Make all PORTC pins output
    
    #DEFINE USE_LCD_FOR_DEBUG   ; comment out for non-debug use
    
    #IFDEF USE_LCD_FOR_DEBUG
        LCD_PIN    VAR PORTC.4  ' Alias PORTC.4 as "LCD_PIN"
        LCD_INST   CON 254      ' instruction
        LCD_CLR    CON 1        ' Clear screen
        LCD_L1     CON 128      ' LCD line 1
        LCD_L2     CON 192      ' LCD line 2
        LCD_BAUD   CON 16780    ' Baud rate/mode 2600bps for ILM-216 2x16 character display
    ;    LCD_BAUD   CON 16468    ' Baud rate/mode 9600bps for ILM-216 2x16 character display
        LCD_PACE   CON 1        ' Optional pace value
    #ENDIF
    
    ' ***************************************************************
    ' Includes
    ' ***************************************************************
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  200               ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
    
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
         SPWM_PIN  PORTC, 0, _DutyVar1  ; and the associated DutyCycle variables
         SPWM_PIN  PORTC, 1, _DutyVar2  ; Notice the underscore before variables
         SPWM_PIN  PORTC, 2, _DutyVar3
      endm
      SPWM_INIT  SPWM_LIST              ; Initialize the Pins
    ENDASM
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  SPWMhandler,  ASM,  yes
        endm
        INT_CREATE                      ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE  TMR1_INT              ; enable Timer 1 interrupts
    
    adval       VAR  WORD       ; stores ADCIN results  
    oldDutyVar1 VAR  WORD 
    ;_____________________________________________________________________________
    
    DutyVar1 = 0
    DutyVar2 = 25
    DutyVar3 = 255
    
    #IFDEF USE_LCD_FOR_DEBUG
        HSEROUT [LCD_INST, LCD_CLR]
        pause 5
        HSEROUT ["DutyVar1=", DEC DutyVar1, 13, 10] ' Send text followed by carriage return and linefeed
    #ENDIF
    
    Main:
       ADCIN 1, adval
       if adval <> oldDutyVar1 then
          oldDutyVar1 = adval
          DutyVar1 = adval
    
          #IFDEF USE_LCD_FOR_DEBUG
             HSEROUT [DEC DutyVar1, 13, 10] ' Send text followed by carriage return and linefeed
          #ENDIF
       EndIf
       Pause 100
    Goto Main
    Edit: Adding

    Code:
    APFCON0.2 = 1               ; Tx on RA0
    makes the screen not blank, but it's still gobbledy-gook.
    Last edited by RossWaddell; - 14th January 2013 at 02:59.

Similar Threads

  1. Interfacing with Arduino I2C LCD
    By norohs in forum Documentation
    Replies: 47
    Last Post: - 30th May 2017, 19:53
  2. LCD Low Power
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2012, 01:05
  3. Interfacing a Nokia 6233 LCD display
    By dancorneanu in forum General
    Replies: 0
    Last Post: - 13th November 2012, 15:30
  4. Only the first 8 characters.
    By timseven in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd September 2009, 02:43
  5. ascii characters to hex
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th January 2006, 05:06

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts