-
To put it simply, it can be like this:
setb k1 ;K1 always works.
loop:setb k2 ;By 12 p.m.
clr k3
clr k4
call delay60s ;Delay 60 seconds.
clr k2
setb k3
clr k4
call delay60s ;Delay 60 seconds.
clr k3
setb k4
clr k2
call delay60s ;Delay 60 seconds.
sjmp$ done.
-
The 8051 MCU clock circuit is as follows:
Capacitors C2 and C3 have the effect of fine-tuning the frequency, and the selection range of capacitance is 30pf and 10pf. **The range of frequencies is as follows: Clock period = reciprocal of the quartz oscillator frequency.
MCU is a kind of integrated circuit chip, which is a small and perfect microcomputer system composed of a small and perfect microcomputer system composed of a silicon wafer that uses ultra-large-scale integrated circuit technology to integrate the best processor CPU, random access RAM, read-only memory ROM, a variety of IO ports and interrupt systems, timer counters and other functions (may also include display drive circuits, pulse width modulation circuits, analog multiplexers, AD converters and other circuits) into a silicon wafer, which is widely used in the field of industrial control.
-
Back upstairs, none of the graduation projects are so simple.
If this is not a high time accuracy, it can be achieved with the internal timer of the microcontroller, I have tried to do it with assembly, and the time error is less than 3 seconds at the end of the day.
1。The component is very simple, it is the minimum system of 51 single-chip microcomputer, and it is enough to connect two 4-segment digital tubes and a few key switches.
2。The circuit is simple and omitted.
3。The program starts org 00h
Initialize the memory cell used for the hour, minute and second - > set the initial value of the timing counter (it can be interrupted once for 50ms, and then repeated 20 times for 1 second OK) - followed by an endless loop, in which the key is detected whether there is a button pressed, and if there is a key pressed, jump to the corresponding button to set the corresponding hour, minute, second memory unit plus 1 (inc a). If there is no button pressed, the endless loop continues to wait for the interruption. The interrupt program starts to detect from the second, and after the counter is cycled 20 times, it adds 1 to the memory unit of the second When it is added to 59, the memory of the minute is added by 1, and when the minute reaches 59, it is added to the time, when the hour is 12, after the minute reaches 59, it is restored to 0:
0:0 is enough for a day.
4。The program, do it yourself, is very simple.
-
Hehe, this one isn't very difficult. There are two options for implementing a clock:
1。The timer of 8051 is realized, the timer is 1s, add one every 1s, clear for full 60, add one for minutes, clear zero for full 60, and add one for hours.
2。With 8051+ time chips, such as DS1302, DS12887, etc.
I don't have ready-made examples on my hands. However, you can refer to Guo Tianxiang's ten days to learn single-chip microcomputer and C language programming. Lecture 10 introduces the first option, and lecture 11 introduces the second option. You can refer to it, I hope it will help you.
-
It will be possible to implement it with the timer of 8051.
-
Brother, isn't this all for you, it seems that you are going to do your graduation project.
-
1. The clock frequency is 6MHz, 12 clock cycles are 1 machine cycle, that is, 1 machine cycle is 2us, counting once is a machine cycle, if the timing is 2ms, then you need to count 1000 times, that is, the accumulator A needs to be added 1000 times and overflow, from 0 to th0 and tl0 there are a total of 65536 numbers, so this initial value is 65536-1000=64536, th0=64536 256=252=0xfc; tl0=64536%256=24=0x18;
2. After the timer 0 is loaded with the initial value, the open interrupt (EA=1, ET0=1), the start timer 0 (TR0=1), so that the timer 0 starts to time, when the accumulator A overflows to produce an interrupt, the execution timer 0 interrupts, which loads the initial value again in the interrupt process, because the open interrupt (EA=1, ET0=1) starts the timer 0 (TR0=1) is always valid, and the timer 0 is timed again after the interrupt is executed, and the cycle has been circulating.
3. while(1) is an endless loop, that is, let the microcontroller work all the time, and the main thing here is to let the microcontroller wait for interruption.
-
I also want to learn this, and I don't know anything about microcontrollers.
-
16 bits i.e. 0-2 to the power of 16 = (hexadecimal) 0000h-ffffh = (decimal) 0-65536 = (binary) 000000000000000-1111111111111111
So the maximum count is not 216, but 2 to the 16th power.
-
Because the counter is 16 bits.
-
It's not 216 pulses, it's 2 to the 16th power.
-
It's not 216 pulses, it's 2 16, which is 2 to the 16th power = 65536 pulses.
-
Microcontroller. 12m crystal oscillator.
The next machine cycle is 1us;
2. tmod=0x02, indicating that timer 0 works under mode 2 (automatic reloading of the initial value). TL0 is +1 per machine cycle, when its value count reaches 255 (0xff), and then another machine cycle +1 will produce overflow (0x100), which will cause a timing interruption, and at the same time, the MCU will automatically assign the value of TH0 to TL0 to continue to start the next round of timing.
3. The initial value of TL0 is 6, so after 250 counting cycles, the value of TL0 will reach 256 (0x100 overflow), resulting in an interruption.
250*1us = 250us =。Spring is old.
The initial value can be understood and assigned as follows: th0 = tl0 = 256-250; ( 6)
void key0()
if(p1_0!=1) *If the key 0 is pressed. >>>More
Crash, it may be that the on-site interference is too severe. Anyway, even have abandoned chips that don't have internal program memory and EEPROM. The reason is that it is often not a program problem, but a board and PCB design problem. >>>More
Not at all contradictory. The purpose of each port of the single-chip microcomputer is different, the structure is also different, you say that the current of the LED MA level can make it brighter, which refers to the rated brightness, different power has different brightness, you can't compare the 1 mm patch with the 10 mm one, can you understand? If you want to use LEDs at the P2 port, there are two ways. >>>More
For how to learn single-chip microcomputer, I think it is still necessary to master its hardware, storage structure, assembly must be proficient, because the introduction of assembly is very helpful and understand the hardware, if you learn single-chip microcomputer, and then learn other, such as arm, at this time you can only be familiar with the assembly, but the first time to learn single-chip microcomputer, assembly, must be proficient, I mean at first do not use c to write programs, write with sinks, write can 10 20 assemblers, your assembly will go to the next level, In the future, you'll be using C for development, and you'll see how comfortable it is to optimize C with a solid foundation for assembly. Regarding the study of microcontrollers, I think it is necessary to have: >>>More