Seven segment with Hi-Ttech C

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
Dear All

Can I have a sample seven segment program with Hi-Tech C for two digits for the purpose of understand

Thanks in advance
 

Dear denujith,
Thanks for reply

Please help me to understand how make multiplex using Hi-Tech C
It is better if you can post a program that simple two digit up counter I mean without other program codes

we can use two arrays

long segment [10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
long digit[2] = {0b0000001,0b0100010};

what will be the next steps
Thanks in advance
 

Please check whether is this what you want. Anyway, I didn't understand what you meant by
we can use two arrays

You can easily alter this code to accommodate only two digits.

View attachment main.zip
 
Last edited:
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear denujith,
Thank you so-much for reply
Actually I need to understand how write a program using Hi-Tech C for seven segments ( with multiplexing )

first I need to write a program for two digits

it is counting 0 to 99 and reset and start again from 0

displayNumber(1234);
can you please explain why 1234 insert to above function


Please help
Thanks in advance
 
Last edited:

hello i dont know about pic too much but you can consider this logic if u aware of C
Code:
unsigned short mask(unsigned short num);
unsigned short digit_no, digit10, digit1, digit, i;

void interrupt() {
    if (digit_no==0) {
        PORTA = 0;                 // Turn off both displays
        PORTD = digit1;            // Set mask for displaying ones on PORTD
        PORTA = 1;                 // Turn on display for ones (LSD)
        digit_no = 1;
    } else {
        PORTA = 0;                 // Turn off both displays
        PORTD = digit10;           // Set mask for displaying tens on PORTD
        PORTA = 2;                 // Turn on display for tens (MSD)
        digit_no = 0;
    }
    TMR0 = 0;                      // Reset counter TMRO
    INTCON = 0x20;                 // Bit T0IF=0, T0IE=1
}

void main() {
    OPTION_REG = 0x80;             // Set timer TMR0
    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
    PORTD = 0;                     // Turn off all display segments
    TRISD = 0;                     // All port D pins are configured as outputs
    
    do {
        for (i = 0; i<=99; i++) {  // Count from 0 to 99
            digit = i % 10u;
            digit1 = mask(digit);  // Prepare mask for displaying ones
            digit = (char)(i / 10u) % 10u;
            digit10 = mask(digit); // Prepare mask for displaying tens
            Delay_ms(1000);
        }
    } while (1);                   // Endless loop
}
mask.c file:

/*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;
}
}

use of timer interrupt is good way for multiplex seven segments
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Hi
Try with this code to understand what you want. it is counting from 0 to 999 and reset to 0

Code:
#include <htc.h>
#define _XTAL_FREQ 4000000 // 4 MHz clock 


__CONFIG(0X3F39);

long segment [10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
char digit[6] = {0b0010000,0b0100000,0b0001000,0b0000100,0b0000010,0b0000001};  //,0x4,0x08,0x10};

char i;
char j;
char k;
char l;
void main(){
TRISC = 0;
TRISD = 0;

while(1){
	PORTC = 0;
	PORTD = segment[i];
	PORTC = 0b0000000;
	__delay_ms(15);

	PORTC = 0;
	PORTD = segment[j];
	PORTC = digit[0];
	__delay_ms(4);

	PORTC = 0;
	PORTD = segment[k];
	PORTC = digit[1];
	__delay_ms(4);

	PORTC = 0;
	PORTD = segment[l];
	PORTC = digit[2];
	__delay_ms(4);

	
	i++;
if (i==10)
	{
	i=0;
	j++;
	}
	if (j==10)
		{
		j=0;
		k++;
		}
		if(k==10)
			{
			k=0;
			l++;
			}
			if (l==10)
				{
				l=0;
				}
			

}
}
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…