For 8051 we need to include the file reg51.h. This file contains the all the definitions of 8051 registers. With this information C compiler produces hex file that can be downloaded into the ROM of the microcontroller. It is important to note that the size of the hex file produced by the assembly language is much larger than the hex file produced by C compiler. Apart from this fact, there is many reasons for writing programs in C instead of assembly:
●It is much easier and less time consuming to write programs in C assembly.
●C is more flexible; it is easier to modify and update.
●Programming in C allows to use code available in function libraries.
●Program written inC for one microcontroller is portable to other microcontrollers with little or no modifications.
●It is much easier and less time consuming to write programs in C assembly.
●C is more flexible; it is easier to modify and update.
●Programming in C allows to use code available in function libraries.
●Program written inC for one microcontroller is portable to other microcontrollers with little or no modifications.
Data Types in 8051 Embedded C
The table shown below lists the data types that are available in typical C51 compiler. The gives information about the size of the data variable and it's value range.Data type | Bits | Bytes | Value range |
---|---|---|---|
bit | 1 | 0 to 1 | |
signed char | 8 | 1 | -128 to +127 |
unsigned char | 8 | 1 | 0 to 255 |
enum | 8 or 16 | 1 or 2 | -128 to +127 or -32768 to +32767 |
signed short | 16 | 2 | -32768 to +32767 |
unsigned short | 16 | 2 | 0 to 65535 |
signed int | 16 | 2 | -32768 to +32767 |
unsigned int | 16 | 2 | 0 to 65535 |
signed long | 32 | 4 | -2147483648 to 2147483647 |
unsigned long | 32 | 4 | 0 to 4294967295 |
float | 32 | 4 | ±1.175494E-38 to ±3.402823E+38 |
sbit | 1 | 0 to 1 | |
sfr | 8 | 4 | 0 to 255 |
sfr16 | 16 | 2 | 0 to 65535 |
Using the Appropriate Data Type
It is necessary to keep in mind that the code space for 8051 or 89c51 is limited to 64 Kilobytes and it has limited on-chip ROM. Thus, it is necessary to look at the size the created hex file. One way to keep the size of the data file optimum is to use appropriate data type. The following points must be considered while selecting the data type.
•The unsigned char is an 8-bit data type. Thus, it must be to store the value in the range of 0-255 (00H-FFH). Since the 8051 is an 8-bit microcontroller, it is the one of the most widely used data type.
•Use unsigned data types when there is no need of signed data.
•C compiler uses signed data type as default. Thus when we want to use unsigned data type, we must use unsigned keywords.
•sbit data type should be used to access bit addressable registers. It allows use to access single bits of SFR registers.
•SFR data type should be used to access the byte size SFR registers.
•The unsigned char is an 8-bit data type. Thus, it must be to store the value in the range of 0-255 (00H-FFH). Since the 8051 is an 8-bit microcontroller, it is the one of the most widely used data type.
•Use unsigned data types when there is no need of signed data.
•C compiler uses signed data type as default. Thus when we want to use unsigned data type, we must use unsigned keywords.
•sbit data type should be used to access bit addressable registers. It allows use to access single bits of SFR registers.
•SFR data type should be used to access the byte size SFR registers.
Logical Operations in 8051 C
One of the most frequent operations required in embedded applications is monitoring a single or a group of bits of a port, checking the status of bits and controlling an external device connected to a bit of an output port. C allows logical operations such as AND, OR, X-OR as well as shifting a byte to the left and right. The table shown below provides the syntax for such operations;
Operations | In assembly | In C | Example in C |
---|---|---|---|
NOT | CPL A | ~ | A=~A |
AND | ANL A,#DATA | & | A=A&DATA |
OR | ORL A,#DATA | A=A DATA | |
EX-OR | XRL A,#DATA | ^ | A=A^DATA |
Shift right by n-bits | RR A | >> | A=A>>n |
Shift left by n-bits | RL A | << | A=A<<n |
Vtercolsi_pu Cassandra Bryant https://marketplace.visualstudio.com/items?itemName=caetarup-ya.Descargar-Blood-City-gratuita-2021
ReplyDeletehoheadnole
cestulioto-1997 Dai Ojeda https://www.msffest.com/profile/newlynnewlynsalysberry/profile
ReplyDeleteacesbarnist
perfgidiu_ku_Pueblo Stacy Cordova download
ReplyDeletehttps://colab.research.google.com/drive/1Ha3_canEOYW-lsStTduwo-fuIIlBiKuN
download
click here
erroracna
dielatrisyu Rene Manison Microsoft Excel 2016
ReplyDeleteAnyDroid 7.5.0.20211009
Bluebeam Revu eXtreme 20.2.85
Slack
crananroeri
This comment has been removed by the author.
ReplyDelete