Professional Documents
Culture Documents
07/09/11
Microcontroller 8051
Project.PRJ
Edit
revise
Task1.A51
07/09/11
1
Microcontroller 8051
Task2.C
2
Task2.C
Various.lib
Link/Locate
Project.M51
07/09/11
Microcontroller 8051
Link/Locate
Project.M51
Project.hex
revise
07/09/11 Microcontroller 8051 4
07/09/11
Microcontroller 8051
An Example
#include<stdio.h> #include <reg51.h> void main(void) {
07/09/11
Microcontroller 8051
Development Tools
Debugging Simulator becomes less useful when there is a lot of time critical hardware Download to a target with a monitor Disadvantages: serial port is tied up for downloading need for a software
07/09/11 Microcontroller 8051 7
Development Tools
InIn-circuit emulator combines monitor and simulator functions emulator plugs into the socket where the final processor would reside Costly
07/09/11
Microcontroller 8051
07/09/11
Microcontroller 8051
Why C
Can control many machine level functions without resorting to assembly language Application can be written in C more easily than assembly language because the development software manages the details because of modularity,reusable codes can be developed and maintained
07/09/11 Microcontroller 8051 10
Why C
The programmer need not be very thorough with the architecture of the processor Code developed in C is more portable
07/09/11
Microcontroller 8051
11
Memory Areas
Code memory (program memory). External data memory. Internal data memory.
07/09/11
Microcontroller 8051
12
Memory Areas
Internal data memory: >read from or written to. >faster than any other memory. >memory specifiers data idata bdata
07/09/11
Microcontroller 8051
13
Memory Types
07/09/11
Microcontroller 8051
14
Memory Types
Frequently used variables are put in the internal memory in preference to the external RAM By including a memory type specifier in the variable declaration, you can specify where variables are stored
07/09/11
Microcontroller 8051
15
Example
char data var1; char code text[] = "ENTER PARAMETER:"; unsigned long xdata array[100]; float idata x,y,z; unsigned int pdata dimension; char bdata flags;
07/09/11
Microcontroller 8051
16
Memory Models
SMALL :
all variables default to the internal data memory of the 8051 same as if they were declared explicitly using the data memory type specifier variable access is very efficient However, all data objects, as well as the stack must fit into the internal RAM
07/09/11
Microcontroller 8051
17
Memory Models
Compact:
all variables default to one page of external data memory same as if they were explicitly declared using the pdata memory type specifier can accommodate a maximum of 256 bytes of variables as it is accessed indirectly through R0 and R1 variable access is not as fast as small model
07/09/11 Microcontroller 8051 18
Memory Models
Large:
all variables default to external data memory same as if they were explicitly declared using the xdata memory type specifier Memory access through this data pointer is inefficient, especially for variables with a length of two or more bytes This type of data access generates more code than the small or compact models
07/09/11 Microcontroller 8051 19
07/09/11
Microcontroller 8051
20
An Example
8 switches are connected to P0 8 LEDs are connected to P2 #include <reg51.h> void msec (unsigned int); void main () { unsigned char array[10]; unsigned char I; while (1) { for (i=0; i<=9; i++) { array[i] = p2=p0; msec(100); } } } This example reads from P0,stores the readings in an array and shows the most recent reading on 8 LEDS 07/09/11 Microcontroller 23
8051
Operators
== <= >= != << >> ++ -&& ||
07/09/11
equal to comparison less than or equal to greater than or equal to not equal to shift left shift right increment decrement Boolean and Boolean or
Microcontroller 8051 24
Operators
+= -= *= /= |= &= ^= <<= >>= %= ->
07/09/11
add value to subtract value to multiply value to divide value to or value to and value to exclusive or value to shift value left shift value right modulo divide value to pointer to a structure
Microcontroller 8051 25
Bitwise operators
Logical operation
Assembly
C ~ & | ^
07/09/11
Microcontroller 8051
26
Assignment operators
Unique to C is the shorthand representation for modifying a variable and assigning it back portA = portA & 0xf7; portA &= oxf7;
07/09/11
Microcontroller 8051
27
Accessing an array element Unsigned int ary[20]; unsigned int x; ary[9] =x;
While defining arrays, it has to be made sure that large amounts of memory is not tied up
07/09/11
Microcontroller 8051
29
Pointers
C51 compiler supports two different types of pointers: Generic pointers Memory specific pointers
07/09/11
Microcontroller 8051
30
Generic Pointers
char *s; int *numptr; long *state; /* string ptr */ /* int ptr */ /* long ptr */
use three bytes,the first for the memory type, the second for the high-order byte of the offset, highand the third for the low-order byte of the lowoffset Generic pointers may be used to access any variable regardless of its location in 8051 memory space.
07/09/11 Microcontroller 8051 31
can be stored using only one byte (idata, data, bdata, and pdata pointers) or two bytes (code and xdata pointers pointers)
07/09/11
Microcontroller 8051
32
I request Electronics and communication ENGINEERING students to visit my blog for more abhishek1ek.blogspot.com awhengineering.blogspot.com THANK YOU
07/09/11 Microcontroller 8051 33