Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 #include<reg51.h> sbit dig_ctrl_4=P1^0; // Control pins for the seven segments sbit dig_ctrl_3=P1^1; sbit dig_ctrl_2=P1^2; sbit dig_ctrl_1=P1^3; unsigned char dig_disp=0; int min2; int min1; int sec2; int sec1; char digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; void delay() // Function to provide time delay using Timer 1. { int i; for(i=0;i<20;i++) { TL1=0xFD; TH1=0x4B; TR1=1; while(TF1==0); TR1=0; TF1=0; } } void display() interrupt 1 // Function to display the four digit number using multiplexing on seven segment. It uses Timer 0 interrupt to display the four digits one by one after a time delay of 2.5 milli second { TL0=0x36; TH0=0xf6; P2=0xFF; dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0; dig_disp++; dig_disp=dig_disp%4; switch(dig_disp) { case 0: P2=digi_val[sec1]; dig_ctrl_1 = 1; break; case 1: P2= digi_val[sec2]; dig_ctrl_2 = 1; break; case 2: P2= digi_val[min1]; dig_ctrl_3 = 1; break; case 3: P2= digi_val[min2]; dig_ctrl_4 = 1; break; } } void main() { TMOD=0x11; // Intialize Timer 0 TL0=0x 36; TH0=0xF6; IE=0x82; TR0=1; //Start timer0 while(1) // Forward counting { min2=min1=sec2=sec1=0; for(min2=0;min2<10;min2++) { for(min1=0;min1<10;min1++) { for(sec2=0;sec2<10;sec2++) { for(sec1=0;sec1<10;sec1++) { delay(); } } } } } }
Hi,
but in my board, thery connected seven segment through buffer to miccorcontroller.Now which one i have to change coding part to get the out,i pasted the code below.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 #include<reg51.h> sbit dig_ctrl_4=P0^7; // Control pins for the seven segments sbit dig_ctrl_3=P0^6; sbit dig_ctrl_2=P0^5; sbit dig_ctrl_1=P0^4; unsigned char dig_disp=0; int min2; int min1; int sec2; int sec1; char digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; void delay() // Function to provide time delay using Timer 1. { int i; for(i=0;i<20;i++) { TL1=0xFD; TH1=0x4B; TR1=1; while(TF1==0); TR1=0; TF1=0; } } void display() interrupt 1 // Function to display the four digit number using multiplexing on seven segment. It uses Timer 0 interrupt to display the four digits one by one after a time delay of 2.5 milli second { TL0=0x36; TH0=0xf6; P0=0xFF; dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0; dig_disp++; dig_disp=dig_disp%4; switch(dig_disp) { case 0: P0=digi_val[sec1]; dig_ctrl_1 = 1; break; case 1: P0= digi_val[sec2]; dig_ctrl_2 = 1; break; case 2: P0= digi_val[min1]; dig_ctrl_3 = 1; break; case 3: P2= digi_val[min2]; dig_ctrl_4 = 1; break; } } void main() { TMOD=0x11; // Intialize Timer 0 TL0=0x36; TH0=0xF6; IE=0x82; TR0=1; //Start timer0 while(1) // Forward counting { min2=min1=sec2=sec1=0; for(min2=0;min2<10;min2++) { for(min1=0;min1<10;min1++) { for(sec2=0;sec2<10;sec2++) { for(sec1=0;sec1<10;sec1++) { delay(); } } } } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #include<8051.h> __sbit __at(0x90) dig_ctrl_4; //=P1^0; // Control pins for the seven segments __sbit __at(0x91) dig_ctrl_3; //=P1^1; __sbit __at(0x92) dig_ctrl_2; //=P1^2; __sbit __at(0x93) dig_ctrl_1; //=P1^0; unsigned char DecimalToBCD (unsigned char decimalByte); void fnd_display(unsigned char val,int pos); unsigned int n=0; int digits[4]; void main() { int i,j; unsigned char digit; i=0; P1=0; P2=0; dig_ctrl_1=1; dig_ctrl_2=1; dig_ctrl_3=1; dig_ctrl_4=1; n=1234; while(n){ digits[i]=n%10; i++; n=n/10; } while(1){ for(i=0;i<=3;i++){ Delayms(5); //put delay of 5 mS. Adjust for clear visibility. Write your own routine digit=digits[i]; fnd_display(DecimalToBCD(digit),i); //try to send digit without conversion and see what happens } } } ////////////////////////////////// void fnd_display(unsigned char val,int pos){ switch(pos){ case 0: dig_ctrl_1=0; break; case 1: dig_ctrl_2=0; break; case 2: dig_ctrl_3=0; break; case 3: dig_ctrl_4=0; break; } P2=val; return ; } ////////////////////////////////// unsigned char DecimalToBCD (unsigned char decimalByte) { return (((decimalByte / 10) << 4) | (decimalByte % 10)); } /////////////////
Thanks u sir,but the following code is not working,while pressing reset button just zero showing on four seven segment digits,after that its disappeared.and i added just delay function.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 #include<reg51.h> sbit dig_ctrl_4=P0^7; // Control pins for the seven segments sbit dig_ctrl_3=P0^6; sbit dig_ctrl_2=P0^5; sbit dig_ctrl_1=P0^4; unsigned char DecimalToBCD (unsigned char decimalByte); void fnd_display(unsigned char val,int pos); unsigned int n=0; int digits[4]; void Delayms(int j) { int i; for(i=0;i<=j;i++); } void main() { int i; unsigned char digit; i=0; P0=0; dig_ctrl_1=1; dig_ctrl_2=1; dig_ctrl_3=1; dig_ctrl_4=1; n=1234; while(n){ digits[i]=n%10; i++; n=n/10; } while(1){ for(i=0;i<=3;i++){ Delayms(5000); //put delay of 5 mS. Adjust for clear visibility. Write your own routine digit=digits[i]; fnd_display(DecimalToBCD(digit),i); //try to send digit without conversion and see what happens } } } ////////////////////////////////// void fnd_display(unsigned char val,int pos){ switch(pos){ case 0: dig_ctrl_1=0; break; case 1: dig_ctrl_2=0; break; case 2: dig_ctrl_3=0; break; case 3: dig_ctrl_4=0; break; } P0=val; return ; } ////////////////////////////////// unsigned char DecimalToBCD (unsigned char decimalByte) { return (((decimalByte / 10) << 4) | (decimalByte % 10)); }
/////////////////
in my board they used single port Po for control pins (4) of 7 segment and decoder four inputs ,with out chaging the connectiion i have to write the coding part.According to my connection plz tel me da coding.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 #include<reg51.h> #define p0 P0 #define p3 P3 unsigned int sec1,sec2; int sec1_1,sec1_2,sec2_1,sec2_2; unsigned int digi_val[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}; sbit dig_ctrl_1=P0^7; // Declare the control pins of seven segments sbit dig_ctrl_2=P0^6; sbit dig_ctrl_3=P0^5; sbit dig_ctrl_4=P0^4; sbit start_pin = P3^2; // Start pin to start the watch. sbit stop_pin = P3^3; // Stop pin to stop the watch. sbit reset_pin = P3^4; // Reset pin to reset the watch. int s,t; void mplex_delay(unsigned int j) // Function to provide a time delay of approximatelty one second using Timer 1 { int i; for (i=0;i<=j;i++); //for(j=0;j<=500;j++); } void digi_out(unsigned int current_num) { p0=digi_val[current_num]; mplex_delay(0); } void display(unsigned int dig1,unsigned int dig2) // Function to display the digits on seven segmnet. For more details refer seven segment multiplexing. { sec1_2=dig1%10; sec1_1=dig1/10; sec2_2=dig2%10; sec2_1=dig2/10; TMOD=0x01; //Enable Timer 0 TL0=0xFF; TH0=0xDB; TR0=1; // Triger Timer 0 while(TF0==0) { dig_ctrl_1 = 1; dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0; digi_out(sec1_1); dig_ctrl_2 = 1; dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0; digi_out(sec1_2); dig_ctrl_3 = 1; dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0; digi_out(sec2_1); dig_ctrl_4 = 1; dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0; digi_out(sec2_2); } TR0=0; TF0=0; } void main() { while(1) { start: // Segment to start the stop watch dig_ctrl_1 = 0; dig_ctrl_2 = 0; dig_ctrl_3 = 0; dig_ctrl_4 = 0; P0 = 0xFF; s = t = 0; while(start_pin == 0)// Check if start pin is pressed { display(0,0); } stopwatch: // Segment to stop the watch for (sec1=s;sec1<=99;sec1++) { if (stop_pin == 1&& start_pin==0 ) //Check if stop pin is pressed break; for (sec2=t;sec2<=99; sec2++) { if (stop_pin == 1 && start_pin==0) //Check if stop pin is pressed break; display(sec1,sec2); } } s = sec1; t = sec2; while ( stop_pin == 1 && start_pin == 1 ) //Check if start pin or reset pins are not pressed { display(sec1,sec2); } if (start_pin == 1 ) //Check if start pin is pressed { goto stopwatch; } else { if (stop_pin == 1 ) //Check if reset pin is pressed { s = t = 0; goto start; } } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #include<reg51.h> #define p0 P0 #define p3 P3 sbit p1=P3^2; sbit p2=P3^3; sbit p3=P3^4; void wait(int j) { long int i; for(i=0;i<j;i++); } void reset() { for(p0=0x00;p0<=0xf9;p0++) { wait(10000); } } void main() { if(p2==1) { p0=0xff; for(p0=0xf0;p0<0xf9;p0++) { wait(10000); if(p1==1) break; if(p3==1) reset(); } } }
In my program one pushbutton for counting(0-9) ,another for stop,and another for where we stopped from there to it has to count,but in my program thrid b uuton is not working,where is the mistake plz tel me sir.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #include<reg51.h> #define p0 P0 #define p3 P3 sbit p1=P3^2; sbit p2=P3^3; sbit p3=P3^4; void wait(int j) { long int i; for(i=0;i<j;i++); } void reset() { for(p0=0x00;p0<=0xf9;p0++) { wait(10000); } } void main() { if(p2==1) { p0=0xff; for(p0=0xf0;p0<0xf9;p0++) { wait(10000); if(p1==1) break; if(p3==1) reset(); } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?