aaaa12345
Fig. 1 wiring diagram of single chip microcomputer 80C51
control system design
Block diagram
Fig. 2 program block diagram
Program list
The program is written into 80C51 chip as follows
#include
/*---------------------Define variables----------------------------------*/
ããsbit p1_ 0=P1^0;
ããsbit p1_ 1=P1^1;
ããsbit p1_ 2=P1^2;
ããsbit p1_ 3=P1^3;
ããsbit p1_ 4=P1^4;
ããsbit p1_ 7=P1^7;
/ / common anode nixie tube displays segment codes of 0 9
ããunsigned char code table[]=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;
ããunsigned int count=0; // Define counter
ããunsigned int weight=0; // Weighing variable
ããvoid delay(unsigned int TIme); // delayed
ããvoid display(unsigned int n); // Nixie tube display
/ * ----------------- main program------------------------------------*/
ããvoid main(void)
/ * - input synchronous display-*/
ããwhile(1)
ããint i=0;
ããunsigned int a;
If ((P1 & 0x1f) = = 0x1f); / / no action without pressing the key
Else if (p1_0 = = 0) count = count 100; while (p1_0 = = 0); / / while (P1! = 0xff) is waiting for the key to be released
ããelse if(p1_1==0) count=count10; while(p1_1==0);
ããelse if(p1_2==0) count=count1; while(p1_2==0);
Else if (p1_3 = = 0) count = 0; while (p1_3 = = 0); / / calculate zero clearing
Else if (p1_4 = = 0) break; / / confirm to start weighing
ããp1_7=0;
If (count > 255) count = 0; / / the counter range is 0 255g, and will be cleared automatically
ããa=count;
Display (a); / / call the display function
ãã
/ * - judge whether the weighing is sufficient and display-*/
ããwhile(1)
Weight = P3; / / obtain the weighing data from port P3
ããif(weight
Else p1_7 = 0; / / P1.7 set the low position to stop the motor
ããdisplay(weight*5);
If (p1_3 = = 0) while (p1_3 = = 0); break; / / clear the calculation and end the weighing
ãã
ãã
/ * ----------------- delay subroutine -------------------------------------------- * / void delay (unsigned int time)
ããunsigned int j=0;
ããfor(;TIme>0;TIme--)
ããfor(j=0;j