HISPEED SERIAL BACKPACK Need help/Recommendations


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Unhappy HISPEED SERIAL BACKPACK Need help/Recommendations

    I have a problem receiving serial data.... I must execute a HRSout "x" prior to my loop , if I don't issue it I receive no data????
    I looked at the HRSout asm code and nothing stands out . I'm surely missing something.

    HRSout is after MAIN1 tag...

    Code:
    ''*******************************************************************************
    '*  Name    : SerialBackPack.BAS                                                     *
    '*  Author  : Mike Wardlow                                                     *
    '*  Notice  : Copyright (c) 2019                                               *
    '*          : All Rights Reserved                                              *
    '*  Date    : 9/15/2019                                                        *
    '*  Version : 1.0                                                              *
    '*  Notes   :                                                                  *
    '==============================================================================*
    '  HardWare                  LCD HD44780                  Serial
    '    CMD                                                    CMD
    '-------------------------------------------------------------------------------
    '%0000 0000  ----  noop                                     0xB0 & 0x07 = 0x00    
    '%0000 0001  ----  clr dsp & set Cursor Position = 0        0xB1 & 0x07 = 0x01
    '%0000 0010  ----  Home      set Cursor Position = 0        0xB2 & 0x07 = 0x02
    '%0000 0011  ----  Home      Set Cursor Position = 0        0xB3 & 0x07 = 0x02                                                                                            
    '%0000 0100  ----  Cursor Move / Direction + dec + no shift 0xB4 & 0x07 = 0x04
    '%0000 0101  ----  Cursor Move / Direction + dec + shift    0xB5 & 0x07 = 0x05
    '%0000 0110  ----  Cursor Move / Direction + inc + no shift 0xB6 & 0x07 = 0x06
    '%0000 0111  ----  Cursor Move / Direction + inc + shift    0xB7 & 0x07 = 0x07
    '%---- ----  ----  ClearLine 20 x 1                         0xB8+1 & 0x7 = 1
    '%---- ----  ----  ClearLine 20 x 2                         0xB9+1 & 0x7 = 2
    '%---- ----  ----  ClearLine 20 x 3                         0xBA+1 & 0x7 = 3
    '%---- ----  ----  ClearLine 20 x 4                         0xBB+1 & 0x7 = 4
    '                                                           0xBC
    '                                                           0xBD
    '                                                           0xBE
    '                                                           0xBF
    '===============================================================================
    '%0000 1000  ----  Disp Ctl + Disp OFF + Cur OFF + No Blink 0xE8 & 0x0F = 0x08   
    '%0000 1001  ----  Disp Ctl + Disp OFF + Cur OFF + BLINK    0xE9 & 0x0F = 0x09    
    '%0000 1010  ----  Disp Ctl + Disp OFF + Cur ON  + No Blink 0xEA & 0x0F = 0x0A   
    '%0000 1011  ----  Disp Ctl + Disp OFF + Cur ON  + BLINK    0xEB & 0x0F = 0x0B    
    '%0000 1100  ----  Disp Ctl + Disp ON  + Cur OFF + No Blink 0xEC & 0x0F = 0x0C    
    '%0000 1101  ----  Disp Ctl + Disp ON  + Cur OFF + BLINK    0xED & 0x0F = 0x0D    
    '%0000 1110  ----  Disp Ctl + Disp ON  + Cur ON  + No Blink 0xEE & 0x0F = 0x0E    
    '%0000 1111  ----  Disp Ctl + Disp ON  + Cur ON  + BLINK    0xEF & 0x0F = 0x0F    
    '===============================================================================
    '%0010 00xx  ----  Interface + 4-bit + 1-line + 5x7-dots    0xF0 & 0x2C = 0x20
    '%0010 01xx  ----  Interface + 4-bit + 1-line + 5x10-dots   0xF4 & 0x2C = 0x24
    '%0010 10xx  ----  Interface + 4-bit + 2-line + 5x7-dots    0xF8 & 0x2C = 0x28
    '%0010 11xx  ----  Interface + 4-bit + 2-line + 5x10-dots   0xFC & 0x2C = 0x2C
    '===============================================================================
    '%0011 00xx  ----  Interface + 8-bit + 1-line + 5x7-dots    0xF1 & 0x3C = 0x30 
    '%0011 01xx  ----  Interface + 8-bit + 1-line + 5x10-dots   0xF5 & 0x3C = 0x34
    '%0011 10xx  ----  Interface + 8-bit + 2-line + 5x7-dots    0xF9 & 0x3C = 0x38
    '%0011 11xx  ----  Interface + 8-bit + 2-line + 5x10-dots   0xFD & 0x3C = 0x3C
    '===============================================================================
    '%0001 00xx  ----  Cursor / Display Shift+ Cur Move + Left  0xF2 & 0x1C = 0x10    
    '%0001 01xx  ----  Cursor / Display Shift+ Cur Move + Right 0xF6 & 0x1C = 0x14    
    '%0001 10xx  ----  Cursor / Display Shift+ Shift    + Left  0xFA & 0x1C = 0x18    
    '%0001 11xx  ----  Cursor / Display Shift+ Shift    + Right 0xFE & 0x1C = 0x1C     
    '===============================================================================
    '
    '%0100 0000  ----  CGRAM 0x40
    '%0111 1111  ----  CGRAM 0x7F
    '
    '%1000 0000  ----  Cursor Position addr  Ln1= 0-19     Ln3= 20-39 
    '%1111 1111  ----  Cursor Position addr  Ln2= 192-211  Ln4=212-231
    '  0 -  39   Cursor Positions used  0x80->0xA7   not used  0xA8->0xBF  24 addr's    
    '192 - 231   Cursor Positions used  0xC0->0xE7   not used  0xE8->0xFF  24 addr's 
    '  A7 -> BF  other cmds    E8 -> FF other cmds 
    '  B0?, B3?,   A8->AF,  B8->BF, F3,F7,FF                FB-Special
    '
    '===============================================================================
    Device = 16F1827                      ' PROTON BASIC compiler 3.5.5.5
    Declare Create_Coff = On              ' use with mplab sim to debug 
     
    Config1 fosc_intosc,mclre_on,pwrte_on,boren_off,wdte_off,fcmen_off,ieso_off ,clkouten_off  
     
    Config2 LVP_OFF, PLLEN_ON, wrt_off ,stvren_off
    
    
    Declare Xtal 32                       'Declare Xtal 32  not sure since using PLL
    Declare Float_Display_Type = Fast 
     
    $define b9600 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0x3 : SPBRGL=0x40
    $define b19200 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0x1 : SPBRGL=0xA0    
    $define b38400 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0x0 : SPBRGL=0xD0    
    $define b57600 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0x0 : SPBRGL=0x8A    
    $define b78600 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0x0 : SPBRGL=0x68    
    $define b115200 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0 : SPBRGL =0x44       
    $define b230400 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0 : SPBRGL =0x22        
    $define b460800 () TXSTA.4=0 : TXSTA.2=1 : BAUDCON.3=1 : SPBRGH=0 : SPBRGL =16   
    $define b921600 () TXSTA.4=0 : TXSTA.2=1 :_
                       BAUDCON.3=1 : SPBRGH=0 : SPBRGL = 8   ' continuation ??                                     
     
    $define Clock ()    Eclk=1 : Nop : Nop : Eclk=0                ' 500 ns
    $define CmdClock()  RS=0 : RW=0 : Eclk=1 : Nop : Nop : Eclk=0  ' cmd   RS=0  RW=0  
    $define BusyClock() RS=0 : RW=1 : Eclk=1 : Nop : Nop : Eclk=0  ' Busy  RS=1  RW=0  
    $define WriteClk()  RS=1 : RW=0 : Eclk=1 : Nop : Nop : Eclk=0  ' Write RS=0  RW=1  
    $define ReadClk()   RS=1 : RW=1 : Eclk=1 : Nop : Nop : Eclk=0  ' Read  RS=1  RW=1  
    
    
    $define BsyCtl()    RS=0 : RW=1 : Nop : Nop
    $define CmdCtl()    RS=0 : RW=0 : Nop : Nop
    $define WrCtl()    RS=1 : RW=0 : Nop : Nop
    $define RdCtl()    RS=1 : RW=1 : Nop : Nop
    $define DONE()     GoTo BEGIN
    
    
    Dim Xvar As String * 20 : Dim Yvar As String *5
    $define DisplayStr(strx) Xvar=strx : DispStr(Xvar)  ' works
    '$define DisplayStr(strx) : DispStr(strx)           ' no worky
    '$define DisplayStr(Xvar) : DispStr(Xvar)           ' no worky
    Dim Baudx As String * 10
    '----------------------------- EEPROM ------------------------------------------
    LCD_BACKLIGHT_SETTING     EData   1      '0 0-OFF 1-ON 
    LCD_BRIGHTNESS_SETTING    EData   30     '3 0-30 MAX 
    LCD_WIDTH_SETTING         EData   20     '1 DEFAULT
    LCD_LINE_SETTING          EData   4      '2 1,2,4 DEFAULT
    LCD_SPLASH_ENABLE         EData   1      '4 ENABLED 
    LCD_Baud_Hi               EData   0      ' spbrgh
    LCD_Baud_Lo               EData   0x8A   ' spbrgl
    '--------------------------- LCD EQUATES ---------------------------------------
    Symbol Eclk = LATA.7                ' Clock
    Symbol RS = LATA.6                  ' RS
    Symbol RW = LATA.4                  ' RW
    Symbol MC = PORTA.5                 ' Master Clear
    Symbol BLC = PORTB.3                ' backlight control 
    Symbol D7 = LATA.3                  '
    Symbol D6 = LATA.2                  '
    Symbol D5 = LATA.1                  '
    Symbol D4 = LATA.0                  '
    '========================= INTERRUPT EQUATES ===================================
    Symbol RCIF = PIR1.5                '    ????
    Symbol RCIE = PIE1.5                '    ????
    Symbol TXIE = PIE1.4
    Symbol TXIF = PIR1.4                ' =0 is busy 
    Symbol T0IF = INTCON.2              '    TMR0IF  ?????
    Symbol T0IE = INTCON.5              '    TMR0IE  ?????
    Symbol PEIE = INTCON.6              '
    Symbol GIE = INTCON.7               '
    '===============================================================================
    Dim CLR_DISP As   0x01              ' clear display
    Dim CUR_HOME As   0x02              ' clear screen and place curser at 0
    Dim CUR_RIGHT As  0x14              ' move curser 1 right
    Dim CUR_LEFT As   0x10              ' move curser left 1
    Dim SCROLL_RIGHT As   0x1c          ' scroll entire screen right 1
    Dim SCROLL_LEFT As   0x18           ' scroll entire screen left 1
    Dim DISP_ON As   0x0c               '
    Dim DISP_OFF As   0x08              '
    Dim UNDERLINE_ON As   0x0e          '
    Dim UNDERLINE_OFF As   0x0c         '???????
    Dim BLINKCUR_ON As   0x0d           '
    Dim BLINKCUR_OFF As   0x0c          '?????/
    Dim DUALCUR_ON As   0x0f            '
    Dim DUALCUR_OFF As   0x0c           '
    Dim SET_CURSOR As   0x80            '
    Dim ENTRY_INC As   0x0c             '
    Dim DD_RAM_ADDR As   0x80           '
    Dim DD_RAM_ADDR2 As   0xc0          '
    Dim CG_RAM_ADDR As   0x40           '
    Dim Beep As 0x07                    '
    '===============================================================================
    '   PROGRAM VARIABLES
    '-------------------------------------------------------------------------------
    Dim LCD_Byte As Byte                 '
    Dim CursorPos As Byte                '
    Dim splash_enable As Byte            '
    Dim Spos As Byte                     '
    Dim pos As Byte                      '
    Dim LineY As Byte                    '
    Dim xx As Byte                       '
    Dim BLcnt As Byte                    '
    Dim Bright_setting As Byte           '
    Dim BLsetting As Byte                '
    
    
    Dim LCD_WIDTH As Byte                '
    Dim LCD_line As Byte                 '
    Dim EL1 As Byte                      '
    Dim EL2 As Byte                      '
    Dim EL3 As Byte                      '
    Dim EL4 As Byte                      '
    Dim EL1x As Byte                     '
    Dim EL2x As Byte                     '
    Dim EL3x As Byte                     '
    Dim EL4x As Byte                     '
    Dim CP1 As Byte                      '
    Dim CP2 As Byte                      '
    Dim CP3 As Byte                      '
    Dim CP4 As Byte                      '
    Dim BfrInp As Byte                   '
    Dim BfrOut As Byte                   '
    Dim Buffer_size As Byte              '
    Dim CMD As Byte                      '
    Dim Rx_Array[80] As Byte             '
                                         '
    Dim NNN As Byte                      '
    Dim N01 As Byte                      '
    Dim XXX As Byte                      '
    Dim YYY As Byte                      '                
    Dim NHI As Byte                      '
    Dim NLO As Byte                      '  
    Dim HiNibx As Byte                   '
    Dim LoNibx As Byte                   '
    
    
    Dim TimeON As Byte                   ' on period
    Dim Toff As Byte                     ' off period
    Dim Period As Byte                       ' period = TimeON + Toff
    Dim DutyC As Byte
    Dim BeepCnt As Word
    Dim StatByte As Byte
    TimeON=20                                   '
    Period = 30                              ' initial  
    BLcnt = Period                                          
    '===============================================================================
    On_Hardware_Interrupt GoTo INT           '
     GoTo SETUP                              '
    '-------------------------------------------------------------------------------
    INT:                                     '
    Context Save                             ' --NEEDED WITH THIS CODE--
    If T0IF =1 Then GoTo T0IFX               'T0IFX
    If RCIF = 1 Then                         '
      Inc BfrInp                             '
      If BfrInp >= Buffer_size Then BfrInp=0 '
      Rx_Array[BfrInp]=RCREG                 '
      RCIF=0                                 ' 
    End If                                   '
    GoTo Ixx                                 '
    '-------------------------------------------------------------------------------
    T0IFX:                                   '
      If BeepCnt > 0 Then                    '  BEEP BEEP BEEP 
         Dec BeepCnt                         '  Beep Duration
         LATB = LATB ^ 0x01                  ' toggle
      EndIf                                  '
    '----------------------------------------'--------------------------------------                         
      Inc BLcnt                              ' BLcnt=Period    TimeON=20   Period=30  
      If BLcnt <= TimeON Then                ' BLCOUNT <= TIME ON
         BLC = 1                             ' BACK LIGHT ON
      Else                                   '
         BLC = 0                             ' BACK LIGHT OFF
      EndIf                                  '
      If BLcnt >= Period Then BLcnt=0        '   
      TMR0 = 64                              ' 48 flkr  64 better 1024us - now~768us
      T0IF = 0                               '
    Ixx:                                     '
      Context Restore                        ' --NEEDED WITH THIS CODE--
    '===============================================================================
    SETUP:
          LCD_WIDTH = 20
          LCD_line = 4
    '-------------------------------------------------------------------------------
          CP1= $80 
          CP2= $80 | $40
          CP3= $80 | LCD_WIDTH
          CP4= $80 | CP2 + LCD_WIDTH
          EL1= LCD_WIDTH
          EL2= $40 + LCD_WIDTH
          EL3= LCD_WIDTH + LCD_WIDTH
          EL4= EL2 + LCD_WIDTH      
          EL1x= $80+LCD_WIDTH
          EL2x= $80+$40 + LCD_WIDTH
          EL3x= $80+LCD_WIDTH + LCD_WIDTH
          EL4x= $80+EL2 + LCD_WIDTH  
          Buffer_size = 80            ''++++++++++++++++++++++++
    '===============================================================================
    MAIN: OSCCON = 0XF0      ' 8 MHZ x4 pllen 32mhz    1 1110 u00
          OSCTUNE = 0 '0X1D  ' 0X0F MAX FREQ
                             ' 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01
                             ' 0X00 CENTER FREQ
                             ' 0X1F MIN 1E 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11
                             ' 0X10 MIN FREQ
                             ' SLOW 8US/300US = 2.6% = 3.5 STEPS TRY 0X03
                             ' FAST 6US/300US = 2.0% = 2.6 STEPS TRY 0X12
                             ' ANSEL = 0X7F   ' FOSC/16[8MHZ CLOCK] chn 0,1,2,3
          ADCON0 = 0X0       ' 0X01                        '      C C C GO ON
          ADCON1 = 0X7F      ' 0X00                        '      7 ANALOG INPUTS
                             '  ADCON2 = 0X0 ' %10101101   '   RJ TAD16 FOSC/16                                   
          CCP1CON = 0        '      
    '===============================================================================
    '  STOP THE TIMERS     USING 8MHZ BASE FREQ  OSC/4 = 2MHZ  .5US/CYC
    '-------------------------------------------------------------------------------
    'OPTION_REG = 3          ' Fosc/4/ 32 Tmr0 OFLO = FSOC4 / 16 / 256 = 1952~ 512us
     OPTION_REG = 4          ' Fosc/4/ 32 Tmr0 OFLO = FSOC4 / 32 / 256 = 976 ~ 1.024ms
    ''  T0CON = %11000001    ' Fosc/4/ 16 Tmr0 OFLO = FSOC4 / 32 / 256 = 976 ~ 500us
    ''  T1CON = 0X10                 ' 1:2=1US RESOLUTION  & STOPPED 0X01=RUN                             ' B7=0=  2 8-BIT WRITES HI/LO
    ''  T2CON = 0X05                 ' 1:4=2US RESOLUTION  & STOPPED 0X04=RUN
     ' INTCON.T0IE = 1               '  ENABLE    TMR0     INTERRUPT   
    '=============================================================================== 
         BfrOut=0                    '
         BfrInp=0                    '
         TRISA = %00100000           ' ra5 cmclre
         TRISB = %00000010           ' rb0 =beep  rb1 RX rb2-Tx rb3-backlite          
         APFCON0=0                   '
         APFCON1=0                   '             
       ''' b57600 ()                 '    
        b115200 ()                   '
       '''  b38400 ()                '
     Select SPBRGL                   '
            Case 0x44                '
                Baudx = "115200"     '
             Case 0x8A               '
                Baudx = "57600"      '
             Case 0xD0               '
                Baudx = "38400"      '
             Case 0xA0               '
                Baudx = "19200"      '
             Case 0x40               '
                Baudx = "9600"       '
          End Select                 '
         BeepCnt = 0                 '
    '-------------------------------------------------------------------------------     
     PORTA = 0                         '
     PORTB = 8                         '
     LATB = 0xFF                       '
     '============================================================================== 
     INTCON=0                          ' 
     RCIF=0                            '
     T0IF = 0                          ' timer 0 overflo int enable
     RCIE=1                            ' enable rcv int 
     T0IE = 1                          ' timer 0 int
     TMR0=0
     PEIE=1                            ' ENABLE PERIPHERAL INTERRUPTS
     GIE=1                             ' ENABLE ALL INTERRUPTS
    '===============================================================================
    MAIN1:
    '-------------------------------------------------------------------------------
     BfrInp = 0                        '  Initialize Ring counts
     BfrOut = 0                        '
    HRSOut "x"                         ' needed - WEIRD PROBLEM 
     INIT_LCD()                        '
     Test1()                           '
      DelayMS 2000                     '
      SetCUR(0,1)                      '
      DisplayStr("PWR ON RESET I=8")   ' 
      SetCUR(0,2)                      '
      DisplayStr("SET BAUD ")   ' 20 spa
      DisplayStr(Baudx)
      SetCUR(0,3)                      '
      DisplayStr("SET INTF I=4_bit")   ' 
      SetCUR(0,4)                      '
      DisplayStr("LCDsercc-2A  768")   ' 
      SetCUR(0,1)                      '
    
    
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    BEGIN:                                   '
      Get_WaitNextByte()                     ' Serial Available ???
      'nibhex(Lcd_byte)
      'hrsout hinibx,lonibx
     
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
    '            CAREFULLY CHECK BYTES VERY CAREFULLY MODIFY CODE
    '              CODES BASED ON UNUSED CURSOR POSITION VALUES
    '===============================================================================   
    Select LCD_Byte                          ' 
      Case 0x07                              ' Beep T0 int toggles B.0 bit
        Beeper(1000)                         '
        DONE                                 '
      Case 0x10 To 0x7F                      ' ascii byte         
        SendDataByte(LCD_Byte)               ' send data ascii byte
        Inc CursorPos                        ' auto roll-over
        CursorPos = CursorPos & 0x7F         '
        DONE                                 '
    End Select                               '
    '===============================================================================            
    ' 01-Clr&Home  02-Home   04-Cur-nosft  05-Cur-sft  06-Cur+nosft  07-Cur+sft     
    '------------------------------------------------------------------------------- 
    Select LCD_Byte                          '
      Case 0xB0                              ' basic cmds 0
        DONE                                 '
      Case 0xB1 To 0xB2                      ' basic cmds 1,2 
        CMD = (LCD_Byte & 0x07)              '
        If CMD = 0x01 Then CursorPos = 0     '  1
        SendCmdByte(CMD)                     ' Send Cmd  1 or 2
        DONE                                 '
      Case 0xB3                              ' Set Backlite Time ON
        SetBackLightTime()                   '  454
        DONE                                 '
      Case 0xB4 To 0xB7                      ' basic
        CMD = (LCD_Byte & 0x07)              ' 4,5,6,7 cmds
        If CMD = 0x01 Then CursorPos = 0     '
        SendCmdByte(CMD)                     '   
        DONE                                 '
    '===============================================================================
    '   CLEAR LINE      B9 clr-1   BA clr-2  BB clr-3  BC clr 4             
    '-------------------------------------------------------------------------------
      Case 0xB8                              '
        BeepCnt = 1000         '  > 0 Beep is ON TMR0 toggles B.0 = sound
        DONE                                 '
    '-------------------------------------------------------------------------------    
      Case 0xB9 To 0xBC                      ' 20 x
        Spos = (LCD_Byte & 7)                ' ClearLine 1,2,3.4
        SetCUR(0,Spos)                       ' set cursor position 0  Line-x
        Spos = 0                             '
        Repeat                               '
          Inc Spos                           '
          SendDataByte("_")                  '
        Until Spos = LCD_WIDTH               '
        DONE                                 ' 
    '-------------------------------------------------------------------------------        
      Case 0xBD,0xBE                         '
        BeepCnt = 1000         '  > 0 Beep is ON TMR0 toggles B.0 = sound
        DONE                                 '
    '-------------------------------------------------------------------------------    
      Case 0xBF                              ' Restart
        GoTo SETUP                           '                  
    End Select                               '
    '===============================================================================
    '                   DISPLAY CONTROL     E8 -> EF ==> 8 -> F
    '------------------------------------------------------------------------------- 
    Select LCD_Byte                          '
      Case 0xE8 To 0xEF                      '  
        CMD = (LCD_Byte & 0x0F)              ' 8,9,a,b,c,d,e,f
        SendCmdByte(CMD)                     '
        DONE                                 '
    End Select                               '
    ' ==============================================================================
    '        4 - BIT INTERFACE                  F0 F4  F8  FC 
    '-------------------------------------------------------------------------------
    Select LCD_Byte         
      Case 0xF0,0xF4,0xF8,0xFC                     '
        CMD = (LCD_Byte & 0x2C)                  ' 
        SendCmdByte(CMD)                         '
        DONE        
    '===============================================================================
    '         8 - Bit INTERFACE                 F1  F5  F9  FD
    '-------------------------------------------------------------------------------        
      Case 0xF1,0xF5,0xF9,0xFD                     '
        CMD = (LCD_Byte & 0x3C)                  '
        SendCmdByte(CMD)                         '
        DONE 
    '===============================================================================
    '          CURSOR CONTROL                   F2 F6  FA  FE                    
    '-------------------------------------------------------------------------------                
      Case 0xF2,0xF6,0xFA,0xFE               ' Cursor Direction
        CMD = (LCD_Byte & 0x1C)              ' move / shift /Left/Right
        SendCmdByte(CMD)                     '
        DONE 
    '===============================================================================
    '           SPECIAL                         F3  F7  FB  FF     
    '-------------------------------------------------------------------------------       
      Case 0xF3                                    ' Special cmd 
        DONE           
      Case 0xF7                                    ' Special cmd 
        DONE             
       Case 0xFB                                   ' Special cmd CGRAM
        '' CGRAM()                                 '
        DONE            
       Case 0xFF                                   ' Special cmd 
        DONE               
    End Select            
    '=============================================================================== 
    '   CODES NOT PREVIOUSLY USED         Leftovers ie this code last
    '              Valid Cursor Positions  BE CAREFUL MODIFING
    '-------------------------------------------------------------------------------
    Select LCD_Byte
      Case CP1 To CP1 + LCD_WIDTH -1         '   0x80 to  0x93
        LineY = 1 
        Spos = LCD_Byte -CP1      
      Case CP2 To CP2 + LCD_WIDTH -1         ' 0xC0 to 0xD3
        LineY = 2 
        Spos = LCD_Byte -CP2      
      Case CP3 To CP3 + LCD_WIDTH -1         ' 0xC0 to 0xD3
        LineY = 3 
        Spos = LCD_Byte -CP3      
      Case CP4 To CP4 + LCD_WIDTH -1         ' 0xC0 to 0xD3
        LineY = 4 
        Spos = LCD_Byte -CP4       
    End Select 
    SetCUR(Spos, LineY)    
    DONE           '   goto Begin                                                       
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*     
    Proc Beeper(NNN As Word)   ' 0x07
        BeepCnt = NNN         '  > 0 Beep is ON TMR0 toggles B.0 = sound
    EndProc
    
    
    '===============================================================================
    '            SET BACK LIGHT  TIME ON
    '-------------------------------------------------------------------------------
    Proc SetBackLightTime()                         ' B3   179  
      Get_WaitNextByte()                            ' Wait & Get next Byte  
      If LCD_Byte < Period+1 Then TimeON = LCD_Byte
    EndProc
    '===============================================================================
    '             WAIT LCD FINISHED ie !BUSY
    '-------------------------------------------------------------------------------
    Proc BusyWait()                      '
       TRISA = 0xFF                      ' PORTA all inputs  
       RS=0 : RW=1                       ' BsyCtl
     For xx = 1 To 15                    ' insure busy exit 
       Eclk=1 : Eclk=0 : Eclk=1 : Eclk=0 ' must use 2 clk cycles on 4-bit
       If PORTA.3 = 0 Then GoTo BWX      '
     Next xx                             '
    BWX:                                 '
       TRISA = %00100000                 ' MCLR AS INPUT ? NOT NEEDED ? 
    EndProc                              '
    '===============================================================================
    Proc NibHex(NNN As Byte)             '  Create Hex nibbles from byte
      Dim Ln As Byte : Dim Hn As Byte    '
      Ln = NNN & 0x0F : Hn = NNN/16      '  store in 
      If Ln < 10 Then LoNibx = Ln + 48   '
      If Ln > 9 Then LoNibx = Ln + 55    '  HiNibx & LoNibx
      If Hn < 10 Then HiNibx = Hn + 48   '
      If Hn > 9 Then HiNibx = Hn + 55    ' 
    EndProc                              '
    '===============================================================================
    Proc SendDataByte(NNN As Byte)         '   Send Data Byte to LCD
       BusyWait()                          '
       WrCtl                               '
       NLO = NNN & $0F                     ' asm
       NHI = NNN/16                        ' swap nibs not work
       LATA = NHI: WriteClk                ' load HI nibble A3-A0  
       LATA = NLO: WriteClk                ' load LO nibble A3-A0
    EndProc                                '
    '===============================================================================
    Proc SendCmdByte(NNN As Byte)          '   Send Control Byte To LCD
       BusyWait()                          '
       CmdCtl()                            '
       NLO = NNN & $0F                     ' asm
       NHI = NNN/16                        ' swap nibs not work
       LATA = NHI: CmdClock                ' load nibble A3-A0 
       LATA = NLO: CmdClock                ' load nibble A3-A0
    EndProc                                '
    '===============================================================================
    Proc DispStr(abc As String * 20)           '
        Spos=0                                 '
        Repeat                                 '
          SendDataByte(abc[Spos])              '
          Inc Spos                             '
        Until Spos=Len(abc)                    '
    EndProc                                    '
    '=============================================================================== 
    Proc SetCUR(pos As Byte, Ln As Byte)       ' 
       If pos > LCD_WIDTH -1 Then GoTo SCPxit  '
       Select Ln                               '
         Case 1                                '
           Spos = pos + CP1                    ' CP1= $80
         Case 2                                '
           Spos = pos + CP2                    ' CP2= $80 | $40
         Case 3                                '
           Spos = pos + CP3                    ' CP3= $80 | LCD_WIDTH
         Case 4                                '
           Spos = pos + CP4                    ' CP4= $80 | CP2 + LCD_WIDTH
       EndSelect                               '
       SendCmdByte(Spos)                       '
    SCPxit:                                    '
    EndProc                                    '
    '===============================================================================
    Proc Get_WaitNextByte(), Byte              '
    Wx:                                        '  Get BYTE
       If BfrInp = BfrOut Then GoTo Wx         '  Wait for serial byte
       Inc BfrOut                              '
       If BfrOut = Buffer_size Then BfrOut = 0 '  
       LCD_Byte = Rx_Array[BfrOut]             '  Get the byte 
    EndProc                                    '
    '===============================================================================
    Proc INIT_LCD()
      LATB=0xff 
      DelayMS 200                     ' pwr on dly - defaults to 8 bit  
      LATA = 0x30 : CmdClock    ' set 8 bit 
      DelayMS 5
      LATA = 0x30 : CmdClock    ' set 8 bit 
      DelayMS 5
      LATA = 0x30 : CmdClock    ' set 8 bit 
      DelayMS 5
      LATA = 0x20 : CmdClock    ' set 4 bit 
      DelayMS 20
      LATA = 0x02 : CmdClock    ' 4 HI bit  set 4 bit 2 line
      LATA = 0x08 : CmdClock             ' 4 LO bit
      DelayMS 20
      LATA = 0x00 : CmdClock    ' 4 HI bit  disp on cursor off 
      LATA = 0x0C : CmdClock            ' 4 LO bit
      DelayMS 20
      LATA = 0x00 : CmdClock    ' 4 HI bit  disp right  increment
      LATA = 0x06 : CmdClock            ' 4 LO bit
      DelayMS 20
      LATA = 0x00 : CmdClock    ' 4 HI bit  Clr disp set cp 0
      LATA = 0x01 : CmdClock            ' 4 LO bit
    '-------------------------------------------------------------------------------  
      DelayMS 20
    '----------------------- Hard Print "A" ----------------------------------------  
    '  LATA = 0x04 : WriteClk    ' 4 HI bit  Clr disp set cp 0
    '  LATA = 0x01 : WriteClk             ' 4 LO bit  
    GoTo IX
    
    
    
    
    IX:
      CursorPos = 0
    EndProc
    '===============================================================================
    Proc special_commands(N01 As Byte)
      Select Case N01
        Case 1
          BLsetting = 1
          BLC = BLsetting
          EWrite LCD_BACKLIGHT_SETTING,[BLsetting]
        Case 2
          BLsetting = 0
          BLC = BLsetting
          EWrite LCD_BACKLIGHT_SETTING,[BLsetting]
        Case 3
          LCD_WIDTH = 20
          EWrite LCD_WIDTH,[1]
        Case 4
          LCD_WIDTH = 16
          EWrite LCD_WIDTH,[1]
        Case 5
          LCD_line = 4
          EWrite LCD_line,[2]
        Case 6
          LCD_line = 2
          EWrite LCD_line,[2]
        Case 7
          LCD_line = 1
          EWrite LCD_line,[2]
        Case 8
          INIT_LCD()
        Case 9
          If splash_enable=1 Then
             splash_enable=0
          Else
             splash_enable=1
             EWrite LCD_SPLASH_ENABLE,[splash_enable]
          End If
        Case Else
             If LCD_Byte >= 128 Then
               Bright_setting = LCD_Byte & $1F
               EWrite LCD_BRIGHTNESS_SETTING,[Bright_setting]
             End If
         End Select
    EndProc
    '===============================================================================
     Proc CGRAM()
       ' not supported now
     
     EndProc  
    '===============================================================================
     Proc Serial(NNN As Byte)     ' get Byte1
          
          Select NNN
            Case 0x00 To 0x7F
                SendDataByte(NNN)        ' send data ascii byte
            Case 0xB0 To 0xB7              ' basic
                CMD = (NNN & 0x07)       ' 0,1,2,3,4,5,6,7 cmds
                SendCmdByte(CMD)
            Case 0xE8 To 0xEF              ' Display Control 
                CMD = (NNN & 0x0F)       ' 8,9,a,b,c,d,e,f
                SendCmdByte(CMD)
            Case 0xF2,0xF6,0xFA,0xFE
                CMD = (NNN & 0x1C)
                SendCmdByte(CMD)
            Case 0xF0,0xF4,0xF8,0xFC
                CMD = (NNN & 0x2C)
                SendCmdByte(CMD)
            Case 0xF1,0xF5,0xF9,0xFD
                CMD = (NNN & 0x3C)
                SendCmdByte(CMD)
            Case 0xFB                       ' Special cmd CGRAM
            '' get next byte  
            Case Else
               SendCmdByte(ByteX)           '  set cursor position
          EndSelect
    EndProc
    '===============================================================================
    Proc Test1()               '
     SendDataByte("L")         '
     SendDataByte("I")         '
     SendDataByte("N")         '
     SendDataByte("E")         '
     SendDataByte(" ")         '
     SendDataByte("0")         '
     SendDataByte("-")         '
     DelayMS 1000              '
     SetCUR(0,1)               '
     DispStr("LINE 1 ")        '
     SetCUR(0,2)               '
     DispStr("LINE 2 ")        '
     SetCUR(0,3)               '
     DispStr("LINE 3 ")        '
     SetCUR(0,4)               '
     DispStr("LINE 4 ")        '  Ver ="LINE 4 SerialCC-1A"                          
    EndProc                    '
    '===============================================================================
    Proc Features()
    '------------------------------------------------
    BLsetting=ERead LCD_BACKLIGHT_SETTING
    If BLsetting > 1 Then BLsetting=1 
    EWrite LCD_BACKLIGHT_SETTING,[BLsetting]
    DelayMS 20
    '-------------------------------------------------
    Bright_setting=ERead LCD_BRIGHTNESS_SETTING
    If Bright_setting > 30 Then Bright_setting=30 
    EWrite LCD_BRIGHTNESS_SETTING,[Bright_setting]
    DelayMS 20
    '--------------------------------------------------
    LCD_WIDTH = ERead LCD_WIDTH_SETTING 
    If LCD_WIDTH > 80 Then LCD_WIDTH = 16      ' default
    EWrite LCD_WIDTH,[LCD_WIDTH_SETTING]
    DelayMS 20
    '--------------------------------------------------
    LCD_line = ERead LCD_LINE_SETTING
    If LCD_line > 8 Then LCD_line = 2                ' default
    EWrite LCD_line,[LCD_LINE_SETTING]
    DelayMS 20
    '----------------------------------------------------
    splash_enable = ERead LCD_SPLASH_ENABLE
    If splash_enable > 1 Then splash_enable = 1      ' default
    EWrite LCD_SPLASH_ENABLE,[splash_enable]
    DelayMS 20
    If splash_enable = 1 Then
      ''DispStr("  Sparkfun.com  ")   ' 20 char 
      DispStr(Name)   ' 20 char
      SendCmdByte((SET_CURSOR+$40))  
      ''DispStr(" Serial LCD V2  ")  
      DispStr(Ver)  
     '' DelayMS 1750
      ''SendCmdByte(CLR_DISP) 
    End If
    EndProc
    '=============================================================================== 
    '                         +5 strap       CHECK 3 PINSTATES FOR PIN 3
    '                            o
    '  PIC o--/\/\/\/----|-------o
    '                   cap      o
    '                   gnd   gnd strap
    '-------------------------------------------------------------------------------
    Proc PBxstate(), Word             ' PORT A/B  5/6     no strap    +5        0 
       Dim RESULT1 As Byte : Dim RESULT2 As Byte
           TRISB.4 = 0                ' SET AS OUTPUT         '        '        '
           LATB.4 = 0                 ' drive pin lo          '        '        '
           TRISB.4 = 1                ' SET PIN AS INPUT      '        '        '
           Result1 = 0                                        '        '        '
           If PORTB.4 = 0 Then        '     READS          LOW-1    HIGH-0    LOW-1 
              Result1 = 1                                     '        '        '
           EndIf                                              '        '        '          
              TRISB.4 = 0             ' SET AS OUTPUT         '        '        '
              LATB.4 = 1              ' SET PIN HI            '        '        '
              TRISB.4 = 1             ' SET AS INPUT          '        '        '
              Result2  = 5            '                       '        '        '
              If PORTB.4 = 1 Then     '     READS         HIGH-4    HIGH-4    LOW-5
                  Result2 = 4                           '
              EndIf                                     '     5        4        6
                 Result = Result1 + Result2             ' TRISTATE    HIGH     LOW
    EndProc
    '===============================================================================
    End

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,826
    Thumbs Up
    Received: 52
    Given: 96
    Total Downloaded
    1.37 GB

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    Thinking about this. You are using interrupts to RX the data and the pic is ignoring data sent to it then I would say something is not right in the initialization of the USART. I have not looked really hard but where have you set up the USART for the right baudrate?

    The RX code in the interrupt routine will not force proton to do it for you. Hrsout "x" will though.
    Tim

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    tried 3 different bauds all act the same 115200 57600 38400

    txsta = x26 before and after hrsout rcsta = x90 before and after hrsout

    I save txsta and rcsta before hrsout then display the b4 and after

    I put LED in INT routine -- I get no INT's[RCIF] unless hrsout "x" has been issued.
    I stumbled across the hrsout , when putting it into INT to capture byte - of course it worked - after a time I found that I could
    put the hrsout "x" almost anywhere before the main loop...

    I've been chasing this and a intermittant hang for about 2 weeks...I got burnt on not using context save/restore [very intermittant hang]
    The HRSOUT "x" has me flustered!!!!!!!!!

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    looks like if I toggle CREN as if {OERR exists} I don't need HRSOUT "x"

    more checking to be done tomorrow.........

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,826
    Thumbs Up
    Received: 52
    Given: 96
    Total Downloaded
    1.37 GB

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    I note that you have no error handling in the Int routine.

    No matter what you do, you have to check for buffer over run and clear it.

    First line in my usart interrupt is always

    If OERR = 1 Then GoTo USART_ERR ; Check for usart overrun


    USART_ERR: ; Handle a usart overrun error
    WREG = RCREG
    CREN = 0
    CREN = 1
    Tim

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    thx Tim

    I not showing any OERR per B4 and after RCSTA = 0x90 , but setting RCSTA =0 then 0x90 allows it to work
    I havn't checked erratta on the 16f1827 yet , but will try to find if this is mentioned
    I had planned to add the OERR checking later because I've used much of the eusart code on other chips with no issues.
    I will add the OERR code, although I don't think I will see the error, unless the chip fails

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,826
    Thumbs Up
    Received: 52
    Given: 96
    Total Downloaded
    1.37 GB

    0 Not allowed!

    Default Re: HISPEED SERIAL BACKPACK Need help/Recommendations

    For the sake of a couple of lines of code you prevent a once in 100000 occurrence which in practice will happen a lot more often. If you sell a product one failure will make you regret not adding it.
    Tim

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 11
    Last Post: 29th September 2019, 16:31
  2. Serial LCD backpack DIY
    By yvesmazzon in forum Projects discussion
    Replies: 10
    Last Post: 1st December 2016, 23:12
  3. Replies: 14
    Last Post: 24th February 2016, 09:52
  4. Serial_Lcd backpack
    By C_Moore in forum The Lounge
    Replies: 45
    Last Post: 17th July 2010, 14:36
  5. [SOLVED !] T6963 Graphic LCD serial backpack
    By J. Mark Wolf in forum Proton Plus Compiler v3
    Replies: 17
    Last Post: 27th February 2007, 03:21

Posting Permissions

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