Embedded C Programming With 8051
Embedded C Programming With 8051
Feb,01 2021
Programming Lamguage for Embedded System
Development
The memory model determines the default memory type to use for
function arguments, automatic variables and declarations with no
expliit memory type specifier.
You may use the bit data types for variable declarations, argument
lists and function return values. E.g. static bit doneflag = 0;
You may use the sbit keyword to declare new variables that access
the bits of variables declared using bdata. For example:
sbit mybit = ibaseˆ7; (bit 15 of variable ibase))
ary07 = bary[0]ˆ7; (bit 7 of bary[0])
Declarations involving the sbit type require that the base object be
declared with the memory type bdata or it may be a special function
register.
You may declare these variables as external for the sbit type to
access these types in other modules.
extern bit mybit0; (bit 0 of ibase)
extern bit ary07; (bit 7 of bary[0])
You may not specify bit variables for the bit positions of a float.
The sbit data type uses the specified variable as a base address and
adds the bit position to obtain a physical address.
SFRs reside from address 0x80 to 0xFF and can be accessed as bits,
bytes and words.
C51 compiler provides access to SFRs with the sfr, sfr16 and sbit
data types.
sfr P0 = 0x80; (Port 0 address 80h)
sfr16 T2 = 0xCC; (Timer 2, T2L address 0CCh and T2H 0CDh)
sbit EA = 0xAF; (SFR bit at address AFh)
sbit OV = PSWˆ2; (PSW Registers 2nd bit)
sbit OV = 0XD0ˆ2; (PSW Registers 2nd bit)
sbit OV = 0XD2 ;(PSW Registers 2nd bit)