C51 is a C language compiler for the 8051 family of microcontrollers
Questions tagged [c51]
33 questions
5
votes
1 answer
Why does using data instead of xdata significantly reduce code space
I have tried searching for an answer to this but can not find a definitive reason.
I am trying to optimise some 8051 C code to reduce code space. I made the following change..
xdata unsigned char a, b;
to
data unsigned char a, b;
... and saw my…

user968722
- 59
- 3
3
votes
1 answer
How to reference a pointer to pdata or idata without using generic pointer?
Using Keil C51 on an 8051 target. I have a set of functions that take a pointer to a structure. The structure will only live in pdata or idata. Due to size constraints and memory mapping magic, I can't condense all structures into the same memory…

David Stover
- 31
- 1
3
votes
2 answers
Keil uVision (C51 compiler), what is meaning of unary operator "!"?
I'm programming with Keil uVision 4.
I have some code like this:
sbit X = P3 ^ 3; // X is third bit of P3 register
...
while (1) {
X = !X; // X equals not X ?!
if (X == 0)
printf("0");
else
printf("1");
…

Filippo Lauria
- 1,965
- 14
- 20
2
votes
1 answer
Keil C51 doesn't allocate memory for struct pointers at compile time
I'm trying to created a linked list of structs for an EFM8 microcontroller project. I want to have the compiler allocate memory for all of the nodes at compile time. The issue I'm having is that no memory is being allocated for struct…

Mike Szczys
- 125
- 1
- 10
2
votes
0 answers
Wrong output sprintf C51 8051 MCU embedded system
I have the following fragment of C code for an AT89S52 microcontroller:
unsigned char x = 0x10;
unsigned char str[21];
sprintf(str, "%u", (x >> 4) );
sprintf function prototype in stdio.h:
extern int sprintf (char *, const char *, ...);
Can…

MLuna
- 35
- 7
2
votes
2 answers
array [] vs pointer * - why will the first code fail in C?
I'm using a Keil C51 compiler to program a 8051 microcontroller. For some reason my code didn't run - I managed to track down the bug, but I still have difficulties understanding it. Why is the first code wrong, comparing to the other one? It's…

Suryu
- 25
- 1
- 9
1
vote
0 answers
Arithmetic operation in Assembler
I'm in the beginning of studying assembler, and I need to calculate (x1+x2)/(x1*x2), and I'm totally don't understand how to do it.
Here's my variation of solving, but my teacher says there's a better way to do it.
org 0000h
x1: equ 30h
x2: equ…

Alexander Gess
- 11
- 3
1
vote
2 answers
Invalid use of macro pasting in macro in Eclipse
Hello I have the following problem:
IDE: Eclipse Version: 2018-12 (4.10.0) with the Keil C51 plugin (for
Language Mapping)
Compiler (external): Wickenhäuser uc51
Problem here: Eclipse Bad Character Sequence
Keil Language mapping is using this…

Tick Tac Joe
- 43
- 7
1
vote
1 answer
KEIL for C51 and have some problems with error like syntax error near unsigned
I am working with Keil for 80C51 and I use C51 for coding. However, I have some problem in my compiling. My code is like following:
#include
#define uchar unsigned char
#define LED P2
sbit SH=P0^0;
sbit DATA=P3^0;
sbit CLK=P3^1;
void…

Sheng Nee
- 17
- 2
- 6
1
vote
0 answers
How to use buffer to read and write using serial port in 8051 MCU
I am using keil c51 compiler. I transmit data from my pc to MCU using serial port it works best.
When I transmit data from my MCU to PC then also it works best.
But when I transmit data to MCU and then store it to buffer character pointer and again…

Balvant Jat
- 71
- 11
1
vote
0 answers
Adapting sbit for GCC
I'm writing a test harness for some C modules, one of which contains the "sbit" keyword. The code was initially written for the Keil C51 compiler, where sbit is used to define a bit within an sfr, more information here. However, I'm writing the test…

Andy
- 21
- 2
1
vote
2 answers
I want to print a multidimensional char array on an lcd in c51 (Keil)
(The array is intialised with a bunch of characters)
I'm also getting an error saying "Data segment too large" when I make the array bigger. How do I copy the array from "CODE" to "XDATA"? or is this not the problem?
EDIT: Also when I call the…

user3277087
- 49
- 1
- 5
1
vote
1 answer
printf() results in gibberish
I have this code:
unsigned char *command = "0000";
unsigned char foo = (hex_char_to_int(command[0]) << 4) | hex_char_to_int(command[1]);
unsigned char bar = (hex_char_to_int(command[2]) << 4) | hex_char_to_int(command[3]);
printf("foo: %02x, bar:…

Drew
- 12,578
- 11
- 58
- 98
0
votes
0 answers
Emulated eeprom in C8051F380 Silabs controllef
In my project on the C8051F380 controller, it is necessary to save parameters after shutdown,
I am, as in the usual case, decided to use emulated EEPROM
But unfortunately, I couldn't find a detailed explanation on this topic,
Yes, there are some…

B Z
- 1
- 1
0
votes
0 answers
clock program (6 seven-segment digital tubes) in c51
/*Use C51 to write the program for STC89C52 single-chip microcomputer, the clock frequency is 11.0592MHZ*/
#include
#define unchar unsigned char
#define unint unsigned int
#define unlint unsigned long int
#define fosc 11059200ul
#define N…

マイドアリ
- 1