The use of 51 single-chip constitute a counter, the upper limit of the count, to do more, it is not difficult, thousands of tens of thousands can be.
The following circuit, a bit smaller, is a two-way two-digit counter.
Used to record ping pong matches, still can be used for basketball games, scores of more than 99, this circuit is not enough.
In the circuit diagram, a common-yang digital tube is used; six keys are also set and their uses are marked.
Writing drivers in C is relatively simple. All code is as follows:
#include"reg51.h"
Unsigned char n1, n2;
//--------------------------------------------------
Void delay(unsigned int i) //1ms delay program
{
Unsigned char j;
While(i--) for(j = 0; j "115; j++);
}
//--------------------------------------------------
Void disp(void)
{
Unsigned char code SEG[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99, //0-4
0x92, 0x82, 0xf8, 0x80, 0x90};//5-9
P0 = SEG[n1 / 10]; P1 = 1; delay(2); P1 = 0;
P0 = SEG[n1 % 10]; P1 = 2; delay(2); P1 = 0;
P0 = SEG[n2 / 10]; P1 = 4; delay(2); P1 = 0;
P0 = SEG[n2 % 10]; P1 = 8; delay(2); P1 = 0;
}
//--------------------------------------------------
Void main(void)
{
Unsigned char k, t;
N1 = n2 = 0;
While(1) {
Disp();
If (~(P2 | 0xc0)) {
Disp();
If (~(P2 | 0xc0)) {
k = ~(P2 | 0xc0);
While (~(P2 | 0xc0)) disp();
If (k == 1) {n1++; if (n1 == 100) n1 = 0;}
Else if (k == 2) {n1--; if (n1 == -1) n1 = 99;}
Else if (k == 4) {n2++; if (n2 == 100) n2 = 0;}
Else if (k == 8) {n2--; if (n1 == -1) n2 = 99;}
Else if (k == 16) {n1 = n2 = 0;}
Else if (k == 32) {t = n1; n1 = n2; n2 = t;}
} } }
}
//--------------------------------------------------
Is not it simple?
Programming in assembly language is much longer.
The assembly language program with the same function as the above C language, all the code is as follows:
ORG 0000H
JMP MAIN
ORG 0030H
;-------------------------
MAIN:
CALL DISP
MOV A, P2
CJNE A, #0FFH, KEY
CLR 00H
JMP MAIN
;-------------------------
KEY:
JNB 00H, A_ADD1
JMP MAIN
;----------------------
A_ADD1:
SETB 00H
JB P2.0, A_SUB1
MOV A, R0
ADD A, #01H
DA A
MOV R0, A
JMP MAIN
;----------------------
A_SUB1:
JB P2.1, B_ADD1
MOV A, R0
ADD A, #99H
DA A
MOV R0, A
JMP MAIN
;----------------------
B_ADD1:
JB P2.2, B_SUB1
MOV A, R1
ADD A, #01H
DA A
MOV R1, A
JMP MAIN
;----------------------
B_SUB1:
JB P2.3, CLR_0
MOV A, R1
ADD A, #99H
DA A
MOV R1, A
JMP MAIN
;----------------------
CLR_0:
JB P2.4, EXCH
MOV R0, #00H
MOV R1, #00H
JMP MAIN
;----------------------
EXCH:
JB P2.5, END_K
MOV A, R0
XCH A, R1
MOV R0, A
JMP MAIN
END_K:
CLR 00H
JMP MAIN
;-------------------------
DISP:
MOV DPTR, #BG
MOV A, R0
SWAP A
ANL A, #0FH
MOVC A, @A + DPTR
MOV P0, A
SETB P1.0
CALL DELAY
CLR P1.0
;----------------------
MOV A, R0
ANL A, #0FH
MOVC A, @A + DPTR
MOV P0, A
SETB P1.1
CALL DELAY
CLR P1.1
;----------------------
MOV A, R1
SWAP A
ANL A, #0FH
MOVC A, @A + DPTR
MOV P0, A
SETB P1.2
CALL DELAY
CLR P1.2
;----------------------
MOV A, R1
ANL A, #0FH
MOVC A, @A + DPTR
MOV P0, A
SETB P1.3
CALL DELAY
CLR P1.3
RET
;-------------------------
DELAY:
DJNZ R7, $
DJNZ R7, $
DJNZ R7, $
DJNZ R7, $
RET
;-------------------------
BG:
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H
DB 92H, 82H, 0F8H, 80H, 90H
;-------------------------
END
The assembly language program looks a lot longer than the C language program, but the compiled machine code generated is less than the C program.
More stable performance
Disposable ecig have a completely enclosed design, reducing the need for charging and replacing cartridges. The no-charge design also reduces the occurrence of faults. It is understood that with rechargeable e-cigarettes, each cartridge needs to be charged at least once and the battery efficiency is extremely low, while the design of disposable ecig can solve this problem very well.
Disposable E-Cig,Disposable Vape Pen Oem,Best Disposable Vapes,One-Time Use Vape
Shenzhen MASON VAP Technology Co., Ltd. , https://www.disposablevapepenfactory.com