praful111
Newbie level 1
i need to be embedded C program which transmit the data on PC using RS232 continuously which is displayed on 7 segment LED. & this number is changes continuously & send to PC using RS232 via TxD & RxD signal.
Just i write the program in c Plz check it for that:
Just i write the program in c Plz check it for that:
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 // Program to demonstrate the principle of digital clock. this digital clock displays two minute digits and two second digits #include<reg51.h> sbit dig_ctrl_4=P1^0; //Declaring control pins of 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 a time delay of approx. 1 second. 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() //Function to display the number using seven segmnet multiplexing. For more details refer seven segment multiplexing. { TL0=0x36; //Reloading Timer0 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 ini() // Initialize Timer 1 for serial communication { TMOD=0x20; //Timer1, mode 2, baud rate 9600 bps TH1=0XFD; SCON=0x50; TR1=1; } void main() { TMOD=0x20; //Intialize Timer 0 TL0=0x36; TH0=0xF6; IE=0x82; // Enable Timer 0 interrupt TR0=1; //Start Timer 0 while(1) //Start clock { 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++) { display(); delay(); ini(); REN = 0; // now disable reception SBUF = P2; // start transmission while(TI==0){} // wait until data transmitted TI=0; // clear transmission flag } } } } } }
Last edited by a moderator: