1. What does #pragma asm mean?
|
2. An algorithm program for hex to bcd
HEX_BCD:CLR A MOV 30H,A MOV 31H,A MOV 32H,A MOV R2,#15 H_B0: MOV A,R1 RLC A MOV R1,A MOV A,R0 RLC A MOV R0 ,A MOV A,32H RLC A ACALL BCD_ADJ MOV 32H,A MOV A,31H RLC A ACALL BCD_ADJ MOV 31H,A MOV A,30H RLC A ACALL BCD_ADJ MOV 30H,A DJNZ R2,H_B0 MOV A,R0 RLC A MOV A ,32H RLC A MOV 32H,A MOV A,31H RLC A MOV 31H,A MOV A,30H RLC A MOV 30H,A RET BCD_ADJ:PUSH PSW PUSH ACC CJNE A,#50H,$+2 JC B1 POP ACC ADD A,#30H PUSH ACC B1: ANL A,#0FH CJNE A,#5,$+2 JC B2 POP ACC ADD A,# 3 PUSH ACC B2: POP ACC POP PSW RET
|
3. Questions about the ALE pin of the microcontroller
"When the microcontroller does not access the external latch, the ALE terminal has a positive pulse signal output, and this frequency is about 1/6 of the clock oscillation frequency. Whenever the external data memory is accessed, ALE only appears once in two machine cycles, that is, one ALE pulse is lost." Is there something wrong with this sentence ? I think according to this statement, three ALE pulses should be lost. I have been unable to figure out what is going on. I hope the experts can help me. I am grateful. Answer: All other instructions issue one ALE every 6 machine cycles, while the MOVX instruction takes 12 machine cycles and only issues one ALE
|
4. How to convert an INT data into two CHAR data?
After Keil optimization, char1=int1/256, char2=int1%256 or char1=int1>>8, char2=int1&0x00ff have the same efficiency.
|
5. After simulating on KEIL C51, how to generate HEX file for burning? ?
Right-click Target 1 in the project, select the second one, and select CREAT HEX in OUTPUT
|
6. What is the difference between typedef and #define?
What is the difference between typedef and #define >>> For example, typedef unsigned char UCHAR; #define unsigned char UCHAR; typedef names a new data type, but in fact this new data type already exists, it just defines a new name. #define is just a label definition. There is no difference between the examples you gave, but #define can also be used like this: #define MAX 100 #define FUN(x) 100-(x) #define LABEL , etc. These cases cannot be defined with typedef
|
7. How to set the simulation working frequency (clock) of KELC51?
Right-click on target 1 on the left, and then enter in the xtal column
|
8. How to share sbit variables between different modules? Extern is not possible?
Put the SBIT definition in a separate .H file, and each module includes this .h file
|
IX. Do I need to define the access to Px.x in C51?
Yes. For example, sbit P17 = 0x97; can define the access to P1.7
|
10. The expression in the SWITCH() statement cannot be a bit variable, right?
You can use a bit variable: #include #include void main() { bit flag; flag=0; switch(flag) { case '0':{printf("0n");break;} case '1':{printf("1n");break;} default:break; } } A bit variable has only two states, so an if statement is enough!!!
|
11. Does const constant declaration occupy memory?
const is only used to define "constants". The space occupied depends on your definition. For example, const code cstStr[] ={"abc"}; occupies code space; while const char data cstStr[] ={"abc"}; certainly occupies memory space. In addition, the definition of #define does not seem to occupy space.
|
12. How to use the extended RAM of Philips' single-chip microcomputer P89C51RD+ in C51?
Try to clear auxr.1 to 0, and then directly declare a variable of type xdata in C language
|
13. BUG of Keil C51
In the program, the following statement is used: const unsigned char strArr[] ={"数学"}; The result shows that the content of strArr[] is {0xCA,0xD1,0xA7}. It is really strange! If there is 0xfd, it will disappear. So we can only enter the internal code manually, for example, uchar strArr[] = {0xCA,0xfd,0xd1,0xa7} (Ultraedit is very convenient).
|
14. How to achieve code optimization in Keil C51?
Under the Project menu, Option for target "Simulator" C51. Do you see Code optimization?
|
15. What is the difference between the ! and ~ symbols in c?
! is logical inversion, ~ is bitwise inversion.
|
16. When programming C51 and reading a port, do you need to output 1 first?
I see that some do, but some don't. Can an expert tell me what's going on? Thanks. It should output 1, unless you can guarantee that it was already 1 before and no other value has been output in the middle.
|
17. When timer 1 (T1) is used to generate baud rate, can P3^5 still be used as a normal I/O port?
P3.5 can be used as a normal IO port.
|
18. How to convert INT to 2 CHAR in C51?
Experts: How to convert INT to CHAR in C51? For example: X = LOW (Z); Y = HIGH (Z); Answer: x = (char) z; y = (char) (z>>8);
|
19. If I want to set the 7th bit of 2EH to 1, can I use bit operation?
I don't quite understand the bit operation instructions. Please give me some advice: For example, SETB 07H means 20H.7 is set to 1, right? (I read this in a book) So if I want to set the 7th bit of 2EH to 1, how can I express it like the example I gave? Thank you! SETB 77H setb (2eh-20h)*8+7 20h-2fh has 8 bits that can be operated (00h-7fh) per byte, and other RAM cannot be directly operated by bits
|
20. What is the difference between char *addr=0xc000 and char xdata *addr=0xc000?
char *addr=0xc000; char xdata *addr=0xc000; Are there any other differences except the different bytes occupied in the memory? char *addr=0xc000; is a general definition, the pointer variable addr can point to the value of any memory space; char xdata *addr=0xc000; specifies that the pointer variable can only point to the value in xdata; in the latter definition, the pointer variable (addr) will occupy one less storage byte. uchar xdata *addr=0xc000; pointer points to external ram; if: data uchar xdata *addr=0xc000; pointer points to external ram but the pointer itself exists in internal ram (data) and so on idata uchar xdata *addr=0xc000; pdata uchar xdata *addr=0xc000; data uchar idata *addr=0xa0;..... .... |
21. How long does it take to execute while(p1_0)?
Assuming that P1_0 is the first pin of the microcontroller's P1 port, how long does it take to execute the above code in KEIL C: while (P1_0) { P1_0= 0; } while(!P1_0) { P1_0=1; } ? Can you explain the execution time of while(P1_0) in detail? You can tell by running the simulation. I tried it and it took about 14 cycles.
|
22. How to write a watchdog program for C51?
Dear experts, I used KEIL C51 to write a program with an external watchdog, but the program cannot run. After searching , I found that after the program was compiled by C51, an initialization program was added to the front of the MAIN() function. When entering the main program to set the watchdog, the watchdog time has expired and my program is reset. How can I modify this initialization program so that the watchdog is set as soon as it runs? You can add a watchdog refresh instruction to startup.a51, of course, using assembly, and then recompile startup.a51 and connect it to your program. The new startup.a51 will automatically replace the system default startup module.
|
23. Keil C51 How to add the modified startup.a51 to the project file
Just add it directly Be careful not to change the symbols such as ?STACK, ?C_START, ?C_STARTUP. Startup.a51 can be added to the project directly without modification. You can modify some assembly restrictions or stack pointers in it.
|
24. About baud rate setting
I found a problem when setting the serial port baud rate: when the crystal oscillator is 11.0592MHz, if 9600BPS is set, TH1=0XFD, TL1=0XFD, and if 19200BPS is set, will TH1 and TL1 change? If not, why? If changed, why ? (Because I read that the two are the same in the book), I hope you can give me some advice. Answer: When BIT7 (SMOD) of the power control register (PCON) is 1, the baud rate doubles. The values of TH1 and TL1 remain unchanged.
|
25. How to declare in C to reserve this part of RAM area and not be used by C?
I don't know how to control this in the C source program, but just add the following paragraph in the assembly program: DSEG AT 20H AA: DS 10 In this way, C51 will not occupy 20H--29H. Or define it like this in C51: uchar data asm_buff[10] _at_ 0x20;
|
26. Questions about floating-point operations
When I was using C51, I found that it has a limit on the number of floating-point parameters passed. May I ask: 1) The parameters are passed in the form of global variables. Are there also limits on the parameters passed in the form of global variables? 2) How many limits are there on this kind of floating-point parameter passing? 3) Is the result of float*float a float type or a double type? Can it be directly assigned to a float type variable? Answer: Since the parameters of KEIL C51 are passed through R0-R7, there will be restrictions. However, KEIL provides a compilation parameter that can support the passing of more parameters. For details, see the PDF document of KEIL. I suggest that you define multiple parameters to be passed in pointers or structures, and pass parameters through pointers or structures. This is better. The answer to the third question is YES. You will know if you try it yourself.
|
27. How to define RAM at a certain address
using the _at_ command, so that you can locate a more flexible address uchar xdata dis_buff[16] _at_ 0x6020 ; //Locate RAM and locate dis_buff[16] at the 16 bytes starting at 0x6020
|
28. In Keil C, what function can be used to get the parity bit?
For example, for 32-bit data, XOR the four bytes with each other and check P. If you are worried that P may be changed, you can use inline assembly. #include unsigned char parity(unsigned char x){ x^=x; if(P)return(1); else return(0); } unsigned char parity2(unsigned int x){ #pragma asm mov a,r7 xrl ar6,a #pragma endasm if(P)return(1); else return(0); } |
Previous article:Talk about C51 programming standards
Next article:Simulate switch light
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Award-winning live broadcast: Keysight Technologies 100G/400G optical communication test solutions
- [Full cash back for orders, capped at 300 yuan] MPS Mall Power Design Products Recommendation, Huge Discount Experience Season!
- Crazy Shell AI open source drone GPIO (remote control indicator light control)
- Where can I get an evaluation board for Toshiba's rice-sized Bluetooth module?
- 16. Low-power intelligent TWS in-ear detection chip VK233DS, Shenzhen Yongjia Microelectronics is the first choice
- [Atria AT32WB415 Series Bluetooth BLE 5.0 MCU] PWM breathing light
- 30V8A stepper motor driver, step angle 1.8 degrees, required accuracy 0.1 degrees, should I choose chip or H bridge
- Can the 66AK2L06 SoC enable miniaturization of test and measurement equipment?
- Circuit diagram of leakage alarm automatic control socket
- How to detect mosquitoes using ultrasonic sensor circuit