You can play with the place of the dot, and minus sign. Pretty easy to figure out how the code works. So no need to get into explanation much.
#CONFIG __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF __config _CONFIG2, _WRT_OFF & _STVREN_OFF & _BORV_LO & _LPBOR_ON & _LVP_OFF #ENDCONFIG clear define OSC 4 OSCCON = $68 TRISA = 0; TRISB = 0; TRISC = 0; ANSELA = 0; ANSELB = 0; ANSELC = 0; ADCON0 = 0; ADCON1 = 0; ADCON2 = 0; LATA = 0; PORTA = 0; LATB = 0; PORTB = 0; LATC = 0; PORTC = 0; FVRCON = 0; T2CON = 0; CM1CON0 = 0; CM1CON1 = 0; DEFAULT_BIT_DELAY con 100 TM1637_I2C_COMM1 con $40 TM1637_I2C_COMM2 con $C0 TM1637_I2C_COMM3 con $80 LEDPIN var PORTC.3 TM1637_CLK var PORTA.0 TM1637_DIO var PORTA.1 TM1637_CLK_DIR var TRISA.0 TM1637_DIO_DIR var TRISA.1 Number var word m_brightness var byte brightness con 7 dispon con 1 WriteByte var byte 'When these two values change, you need to take care of the dot and minus sign behaviour. pos con 0 ' Shifts position of the number on display length con 4 ' how many digits to show on display ' just variables. k var byte i var byte tempbits var byte tempbits = 0 dot_yesno var tempbits.0 ' want to show dot? dot_digitno var byte ' on which digit to show the dot? minus_yesno var tempbits.1 ' want to show minus sign? minus_digitno var byte ' on which digit to show the minus sign? dig2_onoff var tempbits.2 ' depending on the minus sign is either yes or no, dig3_onoff var tempbits.3 '... turn the left most digits off. minusSegments con $40 ' did you want a minus sign on display? digitToSegment var byte(16) ' Seven segment LED bits corresponding to the number digit. digitToSegment[0] = $3F '// 0 digitToSegment[1] = $06 '// 1 digitToSegment[2] = $5B '// 2 digitToSegment[3] = $4F '// 3 digitToSegment[4] = $66 '// 4 digitToSegment[5] = $6D '// 5 digitToSegment[6] = $7D '// 6 digitToSegment[7] = $07 '// 7 digitToSegment[8] = $7F '// 8 digitToSegment[9] = $6F '// 9 digitToSegment[10] = $77 '// A ' can also display some letters. digitToSegment[11] = $7C '// b digitToSegment[12] = $39 '// C digitToSegment[13] = $5E '// d digitToSegment[14] = $79 '// E digitToSegment[15] = $71 '// F Begin: gosub startTM gosub stopTM gosub TM1637Display gosub setBrightness ' brightness con 7, 7 is max. minus_yesno = 0 minus_digitno = 3 ' show minus sign on digit 3. dot_yesno = 0 ' show no dot for now. dot_digitno = 2 number = 456; gosub setSegments ' call this once. Start: PAUSE 10 goto start setSegments: 'Write COMM1 gosub startTM WriteByte = TM1637_I2C_COMM1 gosub writeBytes gosub stoptm 'Write COMM2 + first digit address gosub starttm WriteByte = TM1637_I2C_COMM2 + (pos & $03) gosub writeBytes dig2_onoff = 1 dig2_onoff = 1 ' Write the data bytes for k = length-1 to 0 step -1 WriteByte = digitToSegment[number dig k] if dot_yesno = 1 && k = dot_digitno then WriteByte.7 = 1 if minus_yesno then if k = minus_digitno then WriteByte = minusSegments if k > minus_digitno then WriteByte = 0 ' turn of digits after minus sign. endif gosub writeBytes next k gosub stoptm 'Write COMM3 + brightness gosub starttm WriteByte = TM1637_I2C_COMM3 + (m_brightness & $0f) gosub writeBytes gosub stoptm return startTM: TM1637_DIO_DIR = 0; PAUSEUS DEFAULT_BIT_DELAY return stopTM: TM1637_DIO_DIR = 0 PAUSEUS DEFAULT_BIT_DELAY TM1637_CLK_DIR = 1 PAUSEUS DEFAULT_BIT_DELAY TM1637_DIO_DIR = 1 PAUSEUS DEFAULT_BIT_DELAY return writeBytes: ' 8 Data Bits for i = 0 to 7 'CLK low TM1637_CLK_DIR = 0; PAUSEUS DEFAULT_BIT_DELAY ' Set or Clear databit TM1637_DIO_DIR = WriteByte.0[i]; PAUSEUS DEFAULT_BIT_DELAY 'CLK high TM1637_CLK_DIR = 1; PAUSEUS DEFAULT_BIT_DELAY next i ' CLK to zero TM1637_CLK_DIR = 0 TM1637_DIO_DIR = 1 PAUSEUS DEFAULT_BIT_DELAY TM1637_CLK_DIR = 1 PAUSEUS DEFAULT_BIT_DELAY if TM1637_DIO == 0 then TM1637_DIO_DIR = 0 PAUSEUS DEFAULT_BIT_DELAY TM1637_CLK_DIR = 0; PAUSEUS DEFAULT_BIT_DELAY return TM1637Display: ' Set the pin direction and default value. ' Both pins are set as inputs, allowing the pull-up resistors to pull them up TM1637_CLK_DIR = 1; TM1637_DIO_DIR = 1; TM1637_CLK_DIR = 0; TM1637_DIO_DIR = 0; TM1637_CLK = 0; TM1637_DIO = 0; return setBrightness: if dispon then m_brightness = (brightness & 7 ) | 8 else m_brightness = (brightness & 7) endif return end
Re: Reusing PGC & PGD pins
Yes you can reuse them but you need to be careful as to what circuitry you hang off the pins.
tumbleweed Today, 13:29Most ICSP programmers have 4.7K pull-down resistors on the PGC/PGD pins and assume the pins will idle...