Wu Jianying Microcontroller Development Board Address
Shop:
【Wu Jianying’s Shop】
Address:
【https://item.taobao.com/item.htm?_u=ukgdp5a7629&id=524088004171】
1. The pointer to the code area array must also declare the code keyword.
For example, for the array unsigned char code arr[30];, to point to it, the pointer must also be declared as unsigned char code *p;
Later use found that in many other places this declaration is not necessary, just unsigned char *p; is sufficient, but I clearly remember that it was indeed necessary to add the code keyword declaration at that time.
2. In the 51 series, bit variables seem to be limited.
If you want to use a boolean type as a flag variable, to save space you can use a bit type variable, but I encountered an error using a bit type variable in the DRS1000 project, and switching to unsigned char worked. At that time, I had already defined many variables, perhaps I had exhausted the addressable storage that could use bits.
3. When triggering INT interrupts with mechanical switches:
Due to the vibration of mechanical switches, the generated voltage will have spikes, and these spikes can trigger the interrupt multiple times. The factors causing multiple triggers are twofold:
(1) The vibration when the switch is pressed. When the first low level arrives, it will enter the interrupt handler, and even if these vibrations occur during the execution of the interrupt handler, the interrupt flag will still be set, and after the interrupt handler ends, it will immediately trigger the interrupt handler again.
(2) The vibration when the switch is released. When the first high level arrives, it will exit the interrupt handler, and subsequent spikes will re-enter the interrupt handler.
Solution:
Add a segment of low-level waiting code at the end of the interrupt handler, wait for the low level to end, then delay for 5ms (to eliminate the interference from the switch release spikes), and after the 5ms delay, clear the interrupt flag (the interrupt flag may have been set again during the execution of the interrupt handler). The code is as follows:
void int0() interrupt 0
{
/*Do something*/
while(rollRA==0);// Wait for low level to end
delay5(1);// Wait for switch release spikes to end
IE0=0; // Clear interrupt flag to prevent re-entering interrupt
}
4. For the 15 series microcontrollers, when using the serial port, the value of the AUXR register must be specified; otherwise, the program will not run properly.
This situation has been encountered many times; the 15 series microcontrollers must specify the value of the AUXR register when using the serial port, unlike the 12 series, which can ignore this register.
I have developed a habit when using the 15 series microcontrollers: the first line of the main function sets AUXR=0;, and later initializes the serial port as needed.
Source: Internet
For those who like this article, welcome to like it!
Technology comes from accumulation, success comes from persistence —— Microcontroller Lectures by Wu Jianying |