8051

Check if number is in range on 8051

末鹿安然 提交于 2019-12-12 12:52:07
问题 I have received a character over UART, and need to validate if it's a number character. Normally I'd do if (char >= '0' && char <= '9') { /* VALID */ } However, I have to do it in assembly . I haven't found any compare instruction (so I assume there is none). How can I do this? mov A, SBUF ; load the number ; -- pseudocode -- cmp A, #'0' ; In AVR, I'd do it this way brlt fail ; but I'm new to 8051 cmp A, #'9' brge fail ; -- pseudocode -- ; number is good fail: edit: ok here's what I have now

How to write function at particular memory location in flash memory? Is there any directive for that?

元气小坏坏 提交于 2019-12-12 01:52:15
问题 How to write function at particular memory location in flash memory? Is there any directive for that? Do i need particular linker? 回答1: If you are using keil ide you can place a function at a specific address using .ARM.__at_address as the section name. To place the function add at 0x20000, specify: int add(int n1,int n2) __attribute__((section(".ARM.__at_0x20000"))); int add(int n1,int n2) { return n1+n2; } 回答2: Do you use the keil toolchain? If yes, perhaps http://www.keil.com/support/docs

When do I use xdata?

感情迁移 提交于 2019-12-09 16:49:30
问题 I am new at embedded system programming. I am working on a device that uses an 8051 chipset. I have noticed in the sample programs that when defining variables, sometimes they use the keyword xdata. like this... static unsigned char xdata PatternSize; while other times the xdata keyword is omitted. My understanding is that the xdata keyword instructs the compiler that that variable is to be stored in external, flash, memory. In what cases should I store variables externally with xdata?

Implementing function calls for 8051

不问归期 提交于 2019-12-07 10:10:51
问题 Say you have an 8051 microcontroller with no external RAM. Internal RAM is 128 bytes, and you have around 80 bytes available. And you want to write a compiler for a stack language. Say you want to compile an RPN expression 2 3 + . 8051 has native push and pop instructions, so you can write push #2 push #3 Then you can implement + as: pop A ; pop 2 into register A pop B ; pop 3 into register B add A, B ; A = A + B push A ; push the result on the stack Simple, right? But in this case + is

C8051f312 microcontroller [closed]

ⅰ亾dé卋堺 提交于 2019-12-04 07:27:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm not very good at C language, but I have write a very simple code to a C8051F312 microcontroller. My code doesn't working. Please help me what did I wrong. #include C8051F310.h #include stdio.h sbit LED_16 = P1^7; // green LED: 1 = ON; 0 = OFF void init(void) { // XBRN registers_init XBR0 = 0x00; XBR1 = 0x00;

When do I use xdata?

孤者浪人 提交于 2019-12-04 03:59:52
I am new at embedded system programming. I am working on a device that uses an 8051 chipset. I have noticed in the sample programs that when defining variables, sometimes they use the keyword xdata. like this... static unsigned char xdata PatternSize; while other times the xdata keyword is omitted. My understanding is that the xdata keyword instructs the compiler that that variable is to be stored in external, flash, memory. In what cases should I store variables externally with xdata? Accessing those variables takes longer, right? Values stored using xdata do not remain after a hard reset of

Writing a delay subroutine?

爷,独闯天下 提交于 2019-12-03 22:26:59
问题 I need to write a delay subroutine. It should delay about 1 second. It has to be for 8051 environment, DS89C430 micrcontroller ( 11.0592 MHz XTAL). How can I write this subroutine? Delay1sec: ... .... ... .... ... 回答1: To get an exact 1 second delay that also works during interrupts, you need to use a hardware timer, not a software timer. I would advise you to use one of the available on-board timers as suggested by Jerry Coffin. Here's an approach involving a built-in timer and counting

8051 LCD 'Hello World' - replacing DB with variable

只谈情不闲聊 提交于 2019-12-03 21:42:27
I'm using a proprietary 8051 board to learn assembly programming. I'm currently working on an LCD 'Hello World' program. Here's the code. lcd_cmd equ 0800h ;Write COMMAND reg address 0800h lcd_st equ 0801h ;Read STATUS reg address 0801h lcd_wr equ 0802h ;Write DATA reg address 0802h lcd_rd equ 0803h ;Read DATA reg address 0803h ORG 08100h hello: mov P2, #(lcd_cmd SHR 8) ;load P2 with high address mov R0, #(lcd_cmd AND 255) ;load R0 with command reg addr mov R7, #03h ;set LCD position, line=1, char=3 mov dptr, #mesg1 ;point to mesg1 acall wr_string ;write mesg1 to LCD mov R7, #41h ;set LCD

Unravelling Assembly Language Spaghetti Code

别等时光非礼了梦想. 提交于 2019-12-03 08:48:23
问题 I've inherited a 10K-line program written in 8051 assembly language that requires some changes. Unfortunately it's written in the finest traditions of spaghetti code. The program--written as a single file--is a maze of CALL and LJMP statements (about 1200 total), with subroutines having multiple entry and/or exit points, if they can be identified as subroutines at all. All variables are global. There are comments; some are correct. There are no existing tests, and no budget for refactoring. A

Unravelling Assembly Language Spaghetti Code

元气小坏坏 提交于 2019-12-02 22:41:35
I've inherited a 10K-line program written in 8051 assembly language that requires some changes. Unfortunately it's written in the finest traditions of spaghetti code. The program--written as a single file--is a maze of CALL and LJMP statements (about 1200 total), with subroutines having multiple entry and/or exit points, if they can be identified as subroutines at all. All variables are global. There are comments; some are correct. There are no existing tests, and no budget for refactoring. A little background on the application: The code controls a communications hub in a vending application