Learning tasks:
(1) Basic understanding of LCD1602
(2) Using LCD1602 to realize minute and second timing based on 51 single chip microcomputer;
(3) Using buttons to control the adjustment of minutes and seconds (two buttons control the increase of minutes and seconds respectively);
(4) Able to realize the function of hourly timing (buzzer sounds);
(5) Understand the download module and download principle;
(6) Basically understand and use DXP to draw PCB board;
Summary of knowledge points:
1. LCD1602:
The character type liquid crystal display module is a dot matrix LCD specially used to display letters, numbers, symbols, etc. The LCD1602 used this time is 16*2 type.
1. Basic operation sequence
1.1 Read status: Input: RS=L, Rw=H, E=H Output: D0~D7=status word;
1.2 Write instruction: Input: RS=L, Rw=L, D0~D7=instruction code, E=high pulse, Output: None;
1.3 Read data: Input: RS=H, Rw=H, E=H Output: D0~D7=data;
1.4 Write data: Input: RS=L, Rw=H, D0~D7=data, E=high pulse, Output: None;
2. Status word description
STA7...STA0
D7...D0
STA0~6 are the values of the current data address pointer; STA7 is the read and write operation enable, 1 is disabled, 0 is enabled;
the first line takes the address 80, the second line is 80+40;
3. Initialization settings
Display mode setting
00111000 (0x38)
Display switch and cursor setting
instruction code
00001DCB D=1 display on, D=0 off
C=1 display cursor, C=0 off
B=1 cursor flashing, B=0 off
000001NS N=1 When reading or writing an address, the character pointer increases by one, and the cursor increases by one
N=0 minus minus
S=1 write a character, the entire screen display moves left (N=1) or right (N=0) to get the cursor does not move but the screen moves
S=0 does not move
4. Indicator code
80H+address code (0-27H 40-67H) (only display the first 16 digits of each line)
01H Display clear screen: 1. Data pointer cleared 2. All displays cleared
02H Display enter: Data pointer cleared
5. Initialization process (reset process)
1. Delay 15ms
2. Write command 38H (do not detect busy signal)
3. Delay 5ms
4. Write command 38H (do not detect busy signal)
5. Delay 5ms
6. Write command 38H (do not detect busy signal)
7. Write command 38H: Display mode setting
8. Write command 08H: Display off
9. Write command 01H: Display clear
10. Write command 06H: Display cursor movement setting
11. Write command 0cH: Display on and cursor setting
2. Timer
1、TMOD
Used to set the working mode of the timer and counter. The lower four bits are used for T0 and the upper four bits are used for T1.
7 6 5 4 3 2 1 0
Byte address GATE C/T M1 M0 GATE C/T M1 M0 TMOD
GATE is the gate bit, which is used to control whether the start of the timer is affected by the external interrupt source signal. When TR0 or TR1 in TCON is set to 1 by software, the timer/counter can be started; when GATE=1, TR0 or TR1 must be set to 1 by software, and the external interrupt pin INT0/1 must also be high level to enable the timer/counter to work. That is, the start condition of the timer at this time adds the condition that the INT0/1 pin is high level;
C/T: Timing/Counting Mode Selection Bit C/T=0 is timing mode; C/T=1 is counting mode;
M1M0: Working Mode Setting Bit
There are four working modes for timer/counter:
M1M0 Working mode Description
00 1 13-bit timer/counter
01 2 16-bit timer/counter
10 3 8-bit auto-reload timer/counter
11 4 T0 is divided into two independent 8-bit timer/counters; T1 stops counting in this mode
Mode 3: Only applicable to timer/counter T0. When timer T1 is in mode 3, it is equivalent to TR1=0 and stops counting.
Mode 3 divides T0 into two independent 8-bit counters TL0 and TH0.
2. Initialization program
Assign a value to TMOD, determine the working mode of T0 and T1, calculate the initial value, and write it into the interrupt mode of
TH0, TL0 or TH1, TL1 , then assign a value to EA, open the timer interrupt to set TR0 or TR1, start the timing, counter timing or counting
learning process:
Get a basic understanding of LCD1602 and TMOD timer through videos or online materials and perform initialization operations;
analyse problem:
First, make LCD1602 able to basically display the position of minutes and seconds;
secondly, make the timer increase every second, that is, set the timer to change every second. Because the timer is 2^16us, in order to accurately adjust one position in 1s, 50ms is realized when the timer is run once, and then the seconds are increased when the timer is repeated 20 times;
when realizing the increase of minutes and seconds, it is best to stop the timer at the same time when pressing the key, that is, TR0=0, and then display the cursor and the cursor flashing, that is, 0x0f, and then increase the seconds each time you press it. The principle of adjusting the time division is the same as above. When the adjustment is completed, the cursor disappears and stops flashing (0x0c), and the timing continues to start (TR0=1).
At the same time, before the main program runs, it is best to debounce the key scan, and the minute and second program is placed before the main program;
DXP drawing PCB board
First create a project, then create a schematic diagram and PCB. Drag these two into the project and save them. Then start looking for components in the library and connect them. When connecting, make sure the pins are connected well, otherwise there will be errors when importing the PCB board. Pay attention to the packaging of components. Components without packaging will not be imported into the PCB.
After the schematic diagram is drawn, import the PCB and there are no errors. Start setting the size of the PCB board and the position and connection of the components. At the same time, the connection should not be too thin, and try to connect the wires appropriately.
Problems in the learning process
When you are stuck and have no idea in the process of writing code, you can choose to ask seniors or find experts on the Internet, and modify your own code by understanding their ideas of writing code. At the same time, the most important thing is to be careful when writing code. If the main function is wrong, the code will run and the detection will show a warning instead of an error, which will make you make a wrong judgment.
In the process of soldering the board, pay attention to the direction of the components before printing the drawings, otherwise the components will be opposite to the facts, resulting in re-soldering and waste of equipment.
Regarding the mirror image problem of PCB board:
When there are patches on PCB, the mirror image problem should be considered, because on the PCB board, the traces and packages we see are all plug-in and can be placed directly. There are two mirror images from PCB to finished product that have offset each other (one is thermally transferred to the board, and the other is the plug-in device from the reverse side of the wiring), but the patch package is placed directly from the wiring side, so the mirror image problem needs to be considered.
Single-layer board: the reverse side of the plug-in device, and the plug-in device is generally on the top of the circuit board, so the patch is on the ground of the circuit board. In this way, you only need to mirror the patch device before wiring, and the method is to make the patch symmetrical on the X axis.
code show as below:
void key_scan()
{
if(key1==0)
delay_50us(100);
if(key1==0)
{
TR0=0;
AN++;
while(!key1);
}
if(AN==1)
{
write_com(0x80+0x40+8);
write_com(0x0f);
if(key2==0)
delay_50us(100);
if(key2==0)
{
while(!key2);
miao++;
if(miao==60)
{
beef=~beef;
delay_50us(10);
miao=0;
fen++;
if(fen==60)
fen=0;
write_shu(4,fen);
}
write_shu(7,miao);
}
}
if(AN==2)
{
write_com(0x80+0x40+5);
write_com(0x0f);
if(key2==0)
delay_50us(100);
if(key2==0)
{
while(!key2);
fen++;
if(fen==60)
fen=0;
write_shu(4,fen);
}
}
if(AN==3)
{
TR0=1;
AN=0;
write_com(0x0c);
}
}
void int0 () interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
miao++;
if(miao==60)
{
miao=0;
beef=~beef;
delay_50us(10);
beef=~beef;
delay_50us(10);
beef=~beef;
delay_50us(10);
beef=~beef;
delay_50us(10);
beef=~beef;
delay_50us(10);
beef=~beef;
delay_50us(10);
fen++;
if(fen==60)
{
fen=0;
}
}
write_shu(4,fen);
write_shu(7,miao);
}
}
void main()
{
heat();
while(1)
{
key_scan();
}
}
Previous article:Vehicle anti-collision and automatic braking system based on single chip microcomputer
Next article:Design of Intelligent Temperature Monitoring System Based on Single Chip Microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- The interfaces of LED unit boards are all HUB75E, so they cannot be used interchangeably by different brands?
- C2000 MCU Boot Process Analysis - Taking TMS320F28069 as an Example
- The up-counting mode of Timer A of MSP430 is not written with new period = old period, what will happen to the counter?
- Question: Risks of MOS tube switching circuit
- ADI ADUM7702 16-bit isolated Sigma-Delta 24-bit AD7793+ADU5401 isolator data
- DSP F2812 Interrupt
- Problems with the Arteli AT-LINK-EZ virtual serial port
- How to prevent PCB warping
- EEWORLD University Hall----Black technology probe: know the current size by touching it (English, foreign netizens' evaluation)
- Detailed explanation of Zigbee networking principle