I've been trying for hours to make a 4-digit display work with the TM1637 controller. On Arduino Nano it works well. When trying to port the Arduino library to the PIC, MPLAB-X XC8, the signal generated by the PIC is different from the Arduino.
- MPLAB X IDE v6.00
- XC8 2.36
So after trying to do bitbang on the XC8, and not getting satisfactory results, I decided to compare it with the operation of the program made in MikroBasic.
With MikroBasic the PIC seems to make the signal correctly, as occurs with Arduino.
But in MPLAB-X there is a lack of power at the PIC pin, it seems that the internal resistance of the pin is lower when the program is done in MPLAB-X.
On the oscilloscope it is easy to notice that the PIC cannot immediately lower the pin when using MPLAB-X:
MPLAB-X:
MikroBasic:
I tried everything I know:
- Different ports (PORT, PORTB), Different port pins, Different PIC models (PIC16F876A, PIC16F1938)
- PORTAbits.RA3 = 0;
- PORTA &= 0b11110111;
- Disabled the modules related to the pins, comparator, ADC, voltage reference, etc.
- With the XC8's delay, with the FOR(), WHILE() loop, nothing worked.
MPLAB-X main:
void main(void) { PORTA = 0; PORTB = 0; PORTC = 0; TRISA = 0b00000011; TRISB = 0; //ADCON0 = 0b11000000; //bit 0 ADON: A/D On bit = off ADCON1 = 0b11000110; //all pins as digital CCP1CON = 0; //module off CCP2CON = 0; CMCON = 7; //comparator off //CVRCON = 0; //TM1637_Init(); //TM1637_setBrightness(0x0F, true); const uint8_t const1 = 70; while (1) { //TM1637_setSegments(TM1637_test, 1, 0); PORTB = 0; // PORTAbits.RA2 = 0; // DIO_low(); // pinMode(m_pinDIO, OUTPUT) //__delay_us(100); // bitDelay(); delay1 = const1; while(delay1--){ asm("NOP"); } //writeByte(TM1637_I2C_COMM1); //stop(); PORTB = 0; // PORTAbits.RA2 = 0; // DIO_low(); // pinMode(m_pinDIO, OUTPUT); //__delay_us(100); // bitDelay(); delay1 = const1; while(delay1--){ asm("NOP"); } PORTB |= 0b00010000; // PORTAbits.RA3 = 1; // CLK_high(); // pinMode(m_pinClk, INPUT); // __delay_us(100); // bitDelay(); delay1 = const1; while(delay1--){ asm("NOP"); } PORTB = 255; // PORTAbits.RA2 = 1; // DIO_high(); // pinMode(m_pinDIO, INPUT); // __delay_us(100); // bitDelay(); delay1 = const1; while(delay1--){ asm("NOP"); } __delay_ms(2000); } return; } MikroBasic main:
main: ' Main program PORTA = 0 PORTB = 0 PORTC = 0 TRISB = 0 CMCON = 7 ADCON0 = %11000000 ADCON1 = %11000110 CCP1CON = 0 CCP2CON = 0 while(1) PORTB.B5 = 0 Delay_us(300) PORTB.B5 = 1 Delay_ms(2000) wend end. P.S.:
- Edit 1:
-
- I didn't mention that I'm using Linux, I haven't tested it on Windows yet.

