Some ideas about a simple microcontroller project

The principle of the instrument is to energize the coil by means of electromagnetic induction. The different iron content causes the coil to oscillate at different frequencies, thereby testing the iron content of the component. The part I made is also very simple, using 51 single-chip operation 12864 to do display, matrix keyboard

Control system behavior, 1302 storage time, optional, 24c02 is used to store preset parameters, for convenient calculation, nothing more.

After receiving the task, prepare to finish it overnight. This is the first time I have been doing things in college since I was in college (in fact, I was basically in a daze in the middle of the night). The first night was still relatively fast, and the basic operations of each basic module can be carried out. then

I can go home and have a good time. In fact, the arduous task is still behind.

The first problem encountered is to make a kind of operation interface more reliable. Since there is no gui support, all the things you need to do are arranged by yourself. The original instrument uses a digital tube, and the natural reference value is not large. Try to follow the steps at first.

To arrange the interface.

Clock display - "Set parameter 1-" set parameter 2-". .. ..-"Measurement Results -" return to retest

The whole process is a linear setup process, checking each parameter one by one and then taking measurements.

Later, I found that since we have to choose parameters to set, we should put the parameter selection into a side-by-side environment, that is, the parameter selection interface - "1". ..2.. . . . .. - "Back to the parameter selection interface. This makes it easy to set parameters.

Modify the part that needs to be modified.

I didn't even think about it at the time, and wrote a super long loop with nested countless small loops. The direct result is

The lengthy procedure messed up my thinking. During the test, I found that the keyboard scan had a problem, and there were often no buttons detected. And look back at the program I wrote, to achieve a similar keyboard detection but using a variety of different methods, also written in the same

In the function, even if you don't make a mistake, you don't want to look at it again. There was a feeling of despair, and then all of this code was deleted. This is a lesson.

/************************************************* ************************************************** **************

* When implementing similar functions, it is best to use the same method. This method has to be carefully evaluated and experimented. It is not the easiest, but it must be the most reliable method. For example, in this program, after each display, then judge the button

Value, thus going to the next step. It can be seen that the switching of each step is similar. Of course, we can implement this function in many ways. The starting point is to think about how to do it and how to do it. I don't understand it when I write it. We can

Follow this pattern:

Key = KEY_NULL;

While(key == KEY_NULL)

{

Key = keyscan();

Switch(key)

{

. .. . ..

}

}

This code is used to detect relatively clear keys and high reliability, and can be used as a general template.

************************************************** ************************************************** ************/

After writing the control of the button, the next more tangled is the display problem of 12864. It would have been convenient to use the 12864 with a font, but it was a mess that I was amazed. I started writing a function that prints characters on 12864.

, then loop above to print out the numbers to display. The complexity of the program is not bad, the key is that the printing effect is very depressing, we know that the 12864 with the font is 16 * 16 for a large grid, so a byte is written down, a number occupies 1 square, the cursor is still

Flying around. After a while, I know that inspired by the printed string, the number is converted into ascii and placed in the array. Add '\0' to the tail of the array, and then ok as a string display.

Then there is the most maddening problem, EEPROM read error. 24c02 is the iic device, 51 analog iic timing is I used to sway from the Internet, test a single write read normal. But when I write an array, I read it out.

Garbled. I have never seen this problem online. Have a problem, let it go. May Day holiday, the first time in life, about girls, then. .., I don't know if there is any more. .. .. played for 5 days, returned to school, looking for experts to study. So everyone brainstormed, all kinds of

The way to find the problem, finally we found that if the person writes a number, it is also the first one correct, the next one is wrong, and then correct. I estimate the problem of delay, plus delay between writes, normal access. It can be seen that when the problem cannot be found,

It is very beneficial to discuss with you. Mainly to choose different test methods, step by step troubleshooting is the display problem? Conversion problem? What is the problem with eeprom reading? What is the problem with eeprom writing? I always suspected that it was a problem with the way of reading.

Consider the problem of writing. At the same time, it is also necessary to pay attention to the meaning of the delay function, especially for such a bus protocol with strict timing requirements. It is necessary to understand the meaning of each delay.

After finishing this, I found that the most painful problem in keil2 came, and somehow did not produce hex files, a lot of warming had seen before (uncalled segment), I don’t know how to do it, this time It’s broken. I have read these warnings carefully, all of them are capitalized.

But it can be seen that for some functions, the view finds that all functions are not used. We will comment out all the functions and variables that are not used, and the warming is reduced to a certain extent. Naturally, it seems that the compiler does not know what function. It is called, but it is compiled to generate obj. In other words, we usually have to develop good habits.

Functions and global variables that are not called are commented out in time. Otherwise, just like me, the program is not big, the memory is easy to overflow, so that variables and basic calculation errors cannot be defined. In order to reduce this memory waste, we must sacrifice some of the readability, break the function and write it directly to the place of use, try to make the functions side by side rather than nested.

I started to write and write such a wonderful structure for the function:

Void test_fun()

{

//char key;

T0T1_init();

Ascii_init();

Disp_welcome();

iniTIal_ds1302();

Disp_clock();

While(1)

{

Select_change(POINT_POSITION);

Disp_bas(POINT_POSITION);

Test_process(POINT_POSITION);

}

}

This structure is placed directly into the main function. In fact, the system needs to waste a lot of memory for the nesting inside to save the environment, so the memory is quickly eaten up. Disassemble this structure and load the main function directly, so you can define variables.

At present, the calculation of array restoration numbers is always wrong, and the reason is not clear.

Pillow Embossed Overlay Membrane Switch

Pillow Embossed Overlay Membrane Switch is a kind of membrane switch with pillow embossing button, This shape is a common one, and customers can also customize their own convex hull shape

Pillow Embossed Overlay Membrane Switch,8 Button Membrane Swtich,Circle Embossed Membrane Swtich,Grey Button Membrane Switch

Dongguan Nanhuang Industry Co., Ltd , https://www.soushine-nanhuang.com