Description: The basic technique is similar to the previous lesson, with the addition of a counter that counts from 0000 to 9999. The counter increments with a 1-second delay. This code demonstrates displaying numbers on four 7-segment displays (common cathode) in multiplex mode. All 7-segment displays are connected to PORTB (RB0 to RB7, with segment A connected to RB0, segment B to RB1, etc.) and refreshed via pins RA0 to RA3 on PORTA. The number is incremented every second. The project is defined as follows: MCU: PIC16F628A, Test Board: WB-106 Breadboard 2420 dots, Software: MikroC PRO for PIC 2010 (version v4.15). Configuration settings include INTOSC oscillator on RA6 and RA7, with the watchdog timer turned off, power-up timer disabled, master clear enabled, brown-out detection enabled, low voltage programming disabled, data EEPROM read protection disabled, and code protection turned off.
The circuit utilizes a PIC16F628A microcontroller to control a multiplexed display of four 7-segment LEDs, allowing for the visual representation of a counting mechanism that progresses from 0000 to 9999. The microcontroller's PORTB is employed to drive the segments of the displays, while PORTA is used to select which display is currently active.
The multiplexing technique involves activating one display at a time while rapidly cycling through them to create the illusion that all displays are lit simultaneously. This is achieved by controlling the PORTA pins with a shifting mechanism, where the active display is determined by the `shifter` variable. The `interrupt` function manages the timing and display switching, ensuring that the displays are refreshed at a high frequency to avoid flickering.
The main loop of the program initializes the counter and continuously updates the display based on the current value of the counter. The `mask` function translates the numerical values (0-9) into their corresponding segment states in binary format, which is then stored in the `portb_array`. The counter increments every second, controlled by a delay function, and resets to 0000 once it exceeds 9999.
This design showcases efficient use of microcontroller resources and demonstrates fundamental principles of digital electronics, including binary counting, multiplexing, and real-time control of display devices. The configuration settings ensure proper operation of the microcontroller under specified conditions, allowing for reliable performance in the intended application.The basic technique is the same like the last lesson except fact that we have added a counter which counts between 0000 and 9999. Our counter increments with 1 second delay. /* ` <7465> * ` Lesson nr. 12: ` Multiplexed 7Segment as counter mode ` Done by: ` Aureliu Raducu Macovei, 2010. ` ` This code demonstrates displaying number on fo ur 7-segment display (common ` cathode), in multiplex mode. All 7-segment displays are connected to PORTB ` (RB0. RB7, segment A to RB0, segment B to RB1, etc. ) with refresh via pins ` RA0. RA3 on PORTA. Number is incremented for 1 second. ` To define this project, a counter is added (counts from 0000 to 9999). ` Test configuration: ` MCU: PIC16F628A ` Test. Board: WB-106 Breadboard 2420 dots ` SW: MikroC PRO for PIC 2010 (version v4. 15) ` Configuration Word ` Oscillator: INTOSC:I/O on RA. 6, I/O on RA. 7 ` Watchdog Timer: OFF ` Power up Timer: Disabled ` Master Clear Enable: Enabled ` Browun Out Detect: Enabled ` Low Voltage Program: Disabled ` Data EE Read Protect: Disabled ` Code Protect: OFF ` <7465> * */ //*Header*/ unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x3F; case 1 : return 0x06; case 2 : return 0x5B; case 3 : return 0x4F; case 4 : return 0x66; case 5 : return 0x6D; case 6 : return 0x7D; case 7 : return 0x07; case 8 : return 0x7F; case 9 : return 0x6F; } } /*Endless mask*/ unsigned short shifter, portb_index; unsigned int digit, number; unsigned short portb_array[4]; void interrupt() { PORTA = 0; // Turn off all 7seg. displays; PORTB = portb_array[portb_index]; // Bring appropriate value to PORTB; PORTA = shifter; // Turn on appropriate 7seg.
display; //move shifter to next digit; shifter <<= 1; if(shifter > 8u) shifter = 1; //increment portb_index; portb_index + ; if (portb_index > 3u) portb_index = 0; //turn on 1st, turn off 2nd 7 seg. ; TMR0 = 0; //reset TIMER0 value; INTCON = 0x20; //clear T0IF, Bit T0IF=0, T0IE=1; } void main() { CMCON |= 7; // Set AN pins to Digital I/O; OPTION_REG = 0x80; // Set timer TMR0; digit = 0; portb_index = 0; shifter = 1; TMR0 = 0; INTCON = 0xA0; // Disable interrupt PEIE, INTE, RBIE, T0IE PORTA = 0; // Turn off both displays TRISA = 0; // All port A pins are configured as outputs PORTB = 0; // Turn off all display segments TRISB = 0; // All port D pins are configured as outputs number = 0; //initial value; do { digit = number % 10u; //extract ones digit; portb_array[0] = mask(digit); //and store it to PORTB array; digit = (number / 10u) % 10u; //extract tens digit; portb_array[1] = mask(digit); //and store it to PORTB array; digit = (number / 100u) % 10u; //extract hundreds digit; portb_array[2] = mask(digit); //and store it to PORTB array; digit = number / 1000u; //extract thousands digit; portb_array[3] = mask(digit); //and store it to PORTB array; Delay_ms(1000); // 1s delay; number + ; //increment number; if (number > 9999u) number = 0; } while(1); //Endless loop; } //End.
Twenty-five musical keys and 25 LEDs are provided to denote F to F" with half notes in between. Memory can store a played tune. There are ten preprogrammed tunes (each has an average of 55 notes) masked in the chip....
The FM497 is an integrated electronic ignition controller designed for breakerless ignition systems that utilize Hall effect sensors. This device operates an external NPN Darlington transistor to manage the coil current, thereby delivering the necessary stored energy while maintaining low...
The portable counter is designed with low-power logic to minimize battery drain while maintaining good performance. Since most of the milliwatt power drain is consumed by the digital readout, the circuit blanks the LED display when there is no input...
This circuit symmetrically divides an input by virtually any odd number. The circuit contains n + 1 clocks to achieve the desired divisor. By selecting the proper n, which is the decoded output of the 74LS161 counter, divisors from 3...
The control of the system is managed by a Microchip PIC18F46K20-I/PT microcontroller, which is programmed with firmware to oversee the activity of the GSM/GPRS module, monitor the logic conditions of two opto-isolated inputs, and send commands to two relays within...
It is entirely logical that low-cost miniature microcontrollers have fewer pins than their larger counterparts, sometimes too few. Consideration has been given to how to economize on pins by making them perform the work of several. It was noted that...
The difference between these two ICs. A microcontroller is a specialized type of microprocessor designed to be self-sufficient and cost-effective, while a microprocessor is typically intended for general-purpose use, such as in personal computers (PCs). The microcontroller integrates several useful...
Digital counters have various applications in electronic circuits. In digital electronics, counters are utilized in different situations. This article presents the concept of a ring counter circuit, which functions as a register counter. An animation and simulation video of the...
A 16V power supply can be synthesized using IN1692 rectifiers. A shift pulse input saturates the 2N2714, depriving the Darlington combination (2N2714 and 2N2868) of base drive. The negative pulse generated on the 15V line is differentiated to produce a...
We use cookies to enhance your experience, analyze traffic, and (if you allow) serve personalized ads.
By clicking Accept All, you agree to our use of cookies.
Learn more