Wednesday, 1 March 2017

Interfacing Seven Segment display with 8051MCU.

#include<htc.h>
#define led P1
#define led2 P3

void data(int a);
void delay(int b);
void data_2(int b);

void main()
{

int m=0;
int g=0;
while(1){
data(m);
data_2(g);
delay(10);
m++;
if(m>9){
g++;
m=0;
if(g>5){
g=0;
m=0;
}

}

}
}
void data(int a){
switch(a){
case 0:
led=0x40;
break;
case 1:
led=0x79;
break;
case 2:
led=36;
break;
case 3:
led=48;
break;
case 4:
led=0x19;
break;
case 5:
led=0x12;
break;
case 6:
led=0x02;
break;
case 7:
led=0x78;
break;
case 8:
led=0x00;
break;
case 9:
led =0x10;
break;
}

}

void data_2(int a){
switch(a){
case 0:
led2=0x40;
break;
case 1:
led2=0x79;
break;
case 2:
led2=36;
break;
case 3:
led2=48;
break;
case 4:
led2=0x19;
break;
case 5:
led2=0x12;
break;
case 6:
led2=0x02;
break;
case 7:
led2=0x78;
break;
case 8:
led2=0x00;
break;
case 9:
led2 =0x10;
break;




}

}
void delay(int a){
int i=0;
int j=0;
for(i; i<a; ++i){
for(j; j<a/2; ++j){

}

}

}


  • Circuit Diagram:



















No comments:

Post a Comment