Menu

TM1637 does not work with #option explicit , removing the #option line works ok

2021-04-07
2021-04-07
  • Mohammed Shalash

    I have MCP3422 ADC with PIC16LF18855 and TM1637 4X7 Segment module
    when I compile and run the code all ok on terminal but blank TM module until I have commented out the #option explicit line then all working ok.
    here is my code:
    '-------------------------------------------
    #chip 16f18855
    '#option explicit
    #config RSTOSC_HFINT32, MCLR_ON

    #include <lowlevel\hwi2c.h>
    #include <TM1637a.h>
    #define TM1637_CLK RA1
    #define TM1637_DIO RA2
    'Set the PPS of the PWM and the RS232 ports.
    'Set the PPS for this solution.
    

    #startup InitPPS, 85

    Sub InitPPS
    UNLOCKPPS
    'Module: EUSART
    RC6PPS = 0x0010 'TX > RC6
    RXPPS = 0x0017 'RC7 > RX

      SSP1CLKPPS = 0x14     'RC3->MSSP1:SCL1;
      SSP1DATPPS = 0x13     'RC4->MSSP1:SDA1;
      RC3PPS = 0x15         'RC3->MSSP1:SCL1;
      RC4PPS = 0x14         'RC4->MSSP1:SDA1;
    
      LOCKPPS
    

    End sub

    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define sync SYNC_TX1STA

    ; ----- Define Hardware settings for hwi2c
    ' Define I2C settings - CHANGE PORTS if required for your specific device.
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.3
    #define hi2c_CLOCK PORTC.4
    'Initialise I2C Master
    'I2C pins need to be input for SSP2 module
    Dir hi2c_DATA in
    Dir hi2c_CLOCK in

    hi2cMode Master
    

    ; ----- Main body of program commences here.
    ' Now assumes Serial Terminal is operational
    dim DeviceID as byte
    Dim DISPLAYNEWLINE as Byte
    Dim hByte as Byte
    Dim lByte as Byte
    Dim regVal as Byte

    Dim result as Long
    Dim rmder as Byte
    Write4Dig (17, 16, 17, 16, 0) 'clear display
    wait 20 ms
    TMchar_Bright = 11
    TMdec(9999)
    wait 50 ms
    DO

     'Instantiate MCP3422 for new ADC conversion
    
    DO
      HI2CReStart
      HI2CSend ( 0xD0 )
    loop While HI2CAckPollState
        HI2CSend ( 0xAB )' channel 2, gain =8 , one shot conversion
      HI2CStop
    ' wait for conversion completion
     WAIT 150 ms
    
    ' Read 3 bytes from MCP3422 first 2 bytes ard the Analog value and the 3rd is the register value
    DO
      HI2CReStart
      HI2CSend ( 0xD1 )
    LOOP While HI2CAckPollState
        HI2CReceive hByte,ACK ' Analog conversion higher byte
    
        HI2CReceive lByte, ACK ' Analog conversion lower byte
        HI2CReceive regVal, NAK ' MCP3422 register value to check the setting
    
    HI2CStop
    
     HSerPrint "Conversion result X8 : "
    
     HSerPrint Hex(hByte)
     HSerPrint Hex(lByte)
     HSerPrint " Register: "
     HSerPrint Hex(regVal)
     HSerPrintCRLF
     HSerPrintCRLF
     HSerPrintCRLF
    
    
    result=0
    result = result+ [long]hByte
    result = 256 * result + lByte
    
      result = 7812 * result+result/2
      result = result /100000
      HSerPrint "mOhm: "
      HSerPrint (result)
      TMdec(result,0)
      HSerPrintCRLF
      IF  result > 2048 THEN
        result=9999
      END IF
      IF  result > 2048 THEN
        TMdec(9999)
        'WriteChar (0 , "O")
        'WriteChar (1 , "U")
        'WriteChar (2 , "F")
        'WriteChar (3 , "L")
        HSerPrintCRLF
        HSerPrint "mOhm: Out of Range !"
    
        HSerPrintCRLF
      ELSE
        HSerPrintCRLF
        HSerPrint "mOhm: "
        HSerPrint (result)
        HSerPrintCRLF
        TMdec(result,0)
      END IF
    
    HSerPrintCRLF
    HSerPrintCRLF
    HSerPrintCRLF
    

    wait 2 s
    Loop

    '------------------------------------------

    Any help appreciated
    Thanks

     
  • Mohammed Shalash

    Yes it is a typo but after correcting it still need to comment out #option explicit to get it working.
    Thanks

     
  • Anobium

    Anobium - 2021-04-07

    Did you update the software?

     
  • Mohammed Shalash

    Yes I did same error
    Thanks

     
  • Anobium

    Anobium - 2021-04-07

    I do not know that library but TM_Bright = 11 may work for you.

     
  • Mohammed Shalash

    I moved the #option Explicit line after the include <tm1637a.h> and solve the issue
    Thanks for your support and Yes TM_Bright = nn (nn 8to 15) is the right brughtness setting
    All the best</tm1637a.h>

     

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.