The techniques used in displaying all segment with desires data on each is called scanning which occurs at a very high speed (less than 20ms ) then it seems to be all turned on at the same time due to persistence of vision.
if you wish to know more about Microcontroller and it Programming(C, Basic and Assembly language) then visit our Embedded system Class or call +2348188515146
the code is written with MikroC compiler and can easily be port in any other Compiler(Hitech C, xc8 compiler, CCS compiler and many others)
#define col1 PORTD.F0
#define col2 PORTD.F1
#define col3 PORTD.F2
#define col4 PORTD.F3
#define col5 PORTD.F4
#define col6 PORTD.F5
#define col7 PORTD.F6
#define col8 PORTD.F7
#define col9 PORTC.F0
unsigned char pnt=0;
unsigned char SEG1[]="123"; // numbers to display
unsigned char SEG2[]="456";
unsigned char SEG3[]="789";
table(unsigned char sch){
switch(sch){
case 0: return 0b00111111 ;
case 1: return 0b00000110;
case 2: return 0b01011011;
case 3: return 0b01001111;
case 4: return 0b01100110;
case 5: return 0b01101101;
case 6: return 0b01111101;
case 7: return 0b00000111;
case 8: return 0b01111111;
case 9: return 0b01101111;
}
}
Segment3_Display(unsigned char *val,unsigned char *val1, unsigned char *val2){
int str=0;
col1 =1; col2=0; col3=0;
PORTB = table(val[str++]-48);
delay_ms(1);
col1 =0; col2=1; col3=0;
PORTB = table(val[str++]-48);
delay_ms(1);
col1 =0; col2=0; col3=1;
PORTB = table(val[str]-48);
delay_ms(1);
col1=0; col2=0; col3=0;
col4 =1; col5=0; col6=0;
str=0;
PORTB = table(val1[str++]-48);
delay_ms(1);
col4 =0; col5=1; col6=0;
PORTB = table(val1[str++]-48);
delay_ms(1);
col4 =0; col5=0; col6=1;
PORTB = table(val1[str]-48);
delay_ms(1);
col1=4; col5=6; col6=0;
col7 =1; col8=0; col9=0;
str=0;
PORTB = table(val2[str++]-48);
delay_ms(1);
col7 =0; col8=1; col9=0;
PORTB = table(val2[str++]-48);
delay_ms(1);
col7 =0; col8=0; col9=1;
PORTB = table(val2[str]-48);
delay_ms(1);
col7=0; col8=0; col9=0;
}
void main() {
TRISB=0; PORTB=0; // makes PORTB outputs
TRISC=0; PORTC=0;
TRISD=0; PORTD=0;
while(1)Segment3_Display(SEG1,SEG2,SEG3); //function to display all segments
}
No comments:
Post a Comment