Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - KEIL global variables, variable types, LED lights, do not delay in interruption.
KEIL global variables, variable types, LED lights, do not delay in interruption.

It's the first time to do the blue bridge cup problem (the seventh session, simulating liquid level detection warning). After mastering each module, it's actually not that difficult to figure out the logic. It's been done for a long time, and then continue to work hard and record it when you encounter several pits.

method 1

defines a global variable in a file. If you want to use it in other files, you should declare it in this file with extern. (1) It can be initialized when it is defined. (2) extern cannot be initialized, otherwise an error will be reported.

example: u32 TimingDelay = is declared in init.c;

? To use this variable in main.c, you need to declare extern u32 TimingDelay;

method 2

is defined and initialized in init.c: u32 TimingDelay = ;

in init.h, declare with extern: extern u32 TimingDelay;

finally, include init.h: # include "init.h" in main.c

Today, because of the data type, the LCD display is always wrong, so I checked it out.

there are six basic data types in c language: short, int, long, float, double, char

1) integer: short int, int, long int

2) floating point: float, double

3) character types: char

u8, u16, u32.

because the data in the project is not very large, it is OK to use u8 for integers or characters, and the type conversion is ok. TimingDelay is used to u32, and the rest can be determined according to the data type of the function.

It should be noted that floating-point numbers cannot be represented by u8, etc. At present, there is no replacement for the float type, so it is better to use float.

the GPIO port connected to the LED lights on the board may be used with other modules inside the board, so turn off other lights every time one or several LED lights are lit.

today, when I was doing the problem, I applied delay_ms(2) to the interrupt service function at first, and the board got stuck directly. After checking the data, I found that it is best not to apply delay in the interrupt service function.