Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Most widely used serial I/O interfacing standard Input and output voltage levels are not TTL compatible
To connect RS232 to a microcontroller system must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa
Max-232
Converts from RS232 voltage levels to TTL voltage levels Uses a +5 V power source MAX232 has two sets of line drivers for transferring and receiving data Line drivers used for TxD are called T1 and T2 Line drivers for RxD are designated as R1 and R2 T1 and R1 are used together for TxD and RxD of the 8051 Second set is left unused
Inside Max-232
Why C51?
Writing subroutines with ease Sequence of operations is simple to trace, facilitating debugging Finite number of structures with standardized terminology Structures lend themselves easily to building subroutines. The set of structures is complete that is all programs can be written using three structures
Statements
Assignment, call to a subroutine, etc The while/do statement, Repeat/Until statements If-then-else statement, the case statement, the goto statement
Loops
Choice
Structured programming results in increased programming productivity Relieves the programmer of the hardware details Easier to write especially for large and complex programs Produces more readable program source codes.
Programmer has less control and less ability to directly interact with the hardware Some problems can be difficult to solve using only the three structures discussed earlier Nested structures can be difficult to follow
signed int
unsigned int signed long unsigned long float sbit sfr and sfr16
16
16 32 32 32 1 8 & 16
2
2 4 4 4 1&2
-32768 to +32767
0 to 65535 -2147483648 to +2147483647 0 to 4294967295 +-1.175494E-38 to +-3.402823E+38 0 to 1 0 to 255 & 0 to 65535
REG51.H
All the special function registers in 8051 All the individual flags, status and control bits in the bit addressable SFRs
It enables us to refer to the SFRs and all the flags and control bit etc using their symbols i.e. PSW, ACC, B, SP, TR0, TR1 etc.
Memory Types
Memory Type code Description (Size) Code memory (64 Kbytes). Objects declared in this segment must be initialized at compile time. Directly addressable internal data memory (128 bytes) Indirectly addressable internal data memory (256 bytes)
data idata
bdata
xdata pdata
char code errormsg[] = An error occurred; signed int data num1; bit bdata numbit; unsigned int xdata num2;
Accessing External Data and Code Memory Space The higher order address
byte comes from P2, the lower order comes from Ri, so before using this instruction you have to initialize P2
13
Memory Models
Memory Model Description Small Compact Large Variables default to the internal data memory (data) Variables default to the first 256 bytes of external data memory (pdata) Variables default to external data memory (xdata)
If you wish all the variables to be assigned a default memory type without having to specify them one by one then Use memory models by choosing anyone from the above. The default model is Small. Use the #pragma directive to explicitly select any other memory model than the default Small model.
#pragma small #pragma compact #pragma large
C51 Functions
return_type function_name(arguments) [memory] [reentrant] [interrupt] [using] return_type: refers to data type of the return value. function_name: is any name that you wish to call the function as. arguments: is the list of the type and number of input values. memory: refers to an explicit memory model (small, compact or large) reentrant: refers to whether the function is reentrant (recursive) interrupt: indicates that the function is actually an ISR using: explicitly specifies which register bank to use
Parameter Passing
Passing through registers is the faster and default way The registers used and their purpose are as follows. Since there are only 8 registers in available, any extra parameters may be passed using fixed memory locations.
Char/1-byte pointer R7 R5 R3 Int/2-byte pointer R6 & R7 R4 & R5 R2 & R3 Long/Float R4-R7 R0-R3 Generic Pointer R1-R3
Number of Arguments 1 2 3
Returning Values
Unlike parameters output values must be returned from functions via registers only.
Register Carry Flag (C) R7 R6 and R7 R4-R7 R4-R7 R1-R3 MSB in R6 and LSB in R7 MSB in R4 and LSB in R7 32-bit IEEE format Memory type in R3, MSB in R2, LSB in R1 Description
Return Type bit char/unsigned char/1byte pointer int/unsigned int/2-byte pointer long/unsigned long float generic pointer