Menu

Example Code for Simple Debugging With LCD Display

2015-04-26
2015-04-29
  • William Roth

    William Roth - 2015-04-26

    This is a an example that shows a way to do simple debugging by viewing the contents of various registers on an LCD Display. Many times when developing a program I need to check the contents of a register or two but I am not too keen on running a debugger.

    So I wrote the Print_reg sub to do this. Required are a $5 4x20 LCD Display with a $1 I2C Expander. Only two pins needed to the PIC. Optionally a 16x 2 display could be used, but the code will need modification.

    Here is the complete code. Feel free to change or modify as you wish.

     '''An Example Program for Great Cow Basic.
    
     ''' Using a 4x20 LCD Display for Simple Debugging
    
     '''@author         William R
     '''@date           24.04.2015
     '''******************************************************
    
    #chip 16F1829, 16
    
    #define I2C_MODE Master
    #define I2C_DATA PORTA.2
    #define I2C_CLOCK PORTC.0
    #define I2C_DISABLE_INTERRUPTS ON
    
    #define LCD_IO 10
    #define LCD_SPEED FAST
    #define LCD_Backlight_On_State  1
    #define LCD_Backlight_Off_State 0
    CLS
    
    ' Splash Screen
    Locate 0,0: Print "Great Cow Basic .94"
    Locate 1,0: Print ChipNameStr
    wait 2 s
    CLS 'Clear the display
    
    'Manually Setup  Timer2
    T2CON = b'01111011    ;Prescaler 1:64, Postscaler 1:16
    TMR2 = 0  'Make sure timer2 value = 0
    'The timer is now initialized but not started.
    
           'Verify T2CCON register
    
    ''' ************   DEBUGGING ******************
    'PRINT_REG (LCD Line, RegisterName)
    ' If Line is ommited will print on line 0
    Print_Reg (0,T2CON)   'Print the contents of up to 4 Registers
    Print_Reg (1,PR2)     'Each register takes 1 line
    Print_Reg (2,OSCCAL)
    Print_Reg (3,PIE1)
    ''' *******************************************
    
    Stop   'Stop the program here
    
    'Start timer 2
    SET T2CON.2 ON
    wait 100 us
    
    SUB ISR1 'Flash LED to test inpterrupt
       Set PortA.5 ON
       WAIT 2 ms
       Set PortA.5 Off
    END SUB
    
    SUB Print_reg (optional In LN = 0, IN Register)
    
       'CLS   'Optional
       if LN > 3 then LN = 0
    
       Locate LN,0
       Print "RG": PRINT LN: Print "  "
       Print register.7: Print " "
       Print register.6: Print " "
       Print register.5: Print " "
       Print register.4: Print " "
       Print register.3: Print " "
       Print register.2: Print " "
       Print register.1: Print " "
       Print register.0
    
    END SUB
    
    sub stop  'stops code
    do
    loop
    end sub
    
     

    Last edit: William Roth 2015-04-26
  • Jim giordano

    Jim giordano - 2015-04-29

    Looks good, thanks :)

     

    Last edit: Jim giordano 2015-05-03

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.