You are on page 1of 38

Coding:

Lcd:
#include<REGX51.H>

void lcdinit();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void lcdready();
void lcddelay(unsigned int time);
void putstr(unsigned char *ptr);
void putch(unsigned char c);

#define ldata P1
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^7;
sbit mot = P2^0;
sbit busy = P1^7;

void main(){
lcdinit();
// lcddata('a');
//lcddata('b');
// putstr("LCD DISPLAY");
while(1){

lcdcmd(0x80);
mot=1;
putstr("ON ");
lcddelay(200);
lcdcmd(0x80);
mot=0;
putstr("OFF");
lcddelay(200);

}
}

void lcddelay (unsigned int time){

unsigned int i, j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}

void lcdinit(){

lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
}

void lcdcmd(unsigned char value){

lcdready();
P1 = value;
rw = 0;
rs = 0;
en = 1;
lcddelay(1);
en = 0;
return;
}

void lcddata(unsigned char value){

lcdready();
P1 = value;
rw = 0;
rs = 1;
en = 1;
lcddelay(1);
en = 0;
return;
}

void lcdready(){

busy = 1;
rs = 0;
rw = 1;
while(busy==1){
en = 0;
lcddelay(1);
en = 1;
}
}

void putstr(unsigned char *ptr){

while(!(*ptr=='\0')){
putch(*ptr);
ptr++;
}
}

void putch(unsigned char c){

lcddata(c);
}
Adc:
#include<regx51.h>
#include<lcd.c>

void delay (int time);


void start ();
void valtolcd (unsigned int val);
void datain ();

sbit OE = P3^0;
sbit EOC = P3^1;
sbit ALE = P3^2;

unsigned int value;

void main(){
P0=0x00;
P3=0x02;
P2=0xFF;
P1=0x00;

lcdinit();
putstr("TEMPERATURE :");
OE =0;
ALE=0;

while(1){

P0=~P0;
lcdcmd(0x8C);
//if(P0==0x00) lcddata('1');
//else lcddata('2');
start();
datain();
valtolcd(value);
}
}
void start(){
ALE=1;
delay(1000);
ALE=0;
}

void delay(int time){


while(time--);
}

void datain(){
while(EOC==0);
OE=1;
delay(1000);
value=P2;
delay(1000);
OE=0;
delay(1000);
}

void valtolcd(unsigned int val){


unsigned char a[3];
int i;
lcdcmd(0xCD);

for(i=0; i<3; i++){


a[i]=(char)(val%10);
a[i]=a[i]+48;
val=val/10;
}
for(i=2; i>=0; i--){
lcddata(a[i]);
}
delay(60000);
}

Serial communication:
Tx:
#include<regx51.h>
void putst(unsigned char *str);
void putch(unsigned char c);
void serinit();

void serinit(){

TMOD = 0X20;
TH1 = 0XFD;
SCON = 0X50;
IE = 0X90;
TR1 = 1;
TI = 0;
RI = 0;
}

void putst(unsigned char *str){

while(!(*str=='\0')){
putch(*str);
str++;
}
}

void putch(unsigned char c) {

SBUF=c;
while(TI==0);
TI=0;
}

Rx:
#include<regx51.h>
#include"tx.c"
#include"lcd.c"

char x;

void main(){

P2=0x00;
lcdinit();
serinit();
putst("Enter Characters");
// putlcdst("Receiver Check");
lcdcmd(0x80);
while(1);
}

void serial0(void) interrupt 4 {

if (RI==1){
x=SBUF;
putch(x);
lcddata(x);
RI=0;
}
else{ ;
// TI=0;
}
}

Motor:
#include <REGX51.H>
sbit sw1=P1^0;
sbit sw2=P1^1;
sbit motor=P2^0;
void main()
{
sw1=1;
sw2=1;
motor=0;
while(1)
{

}
Keypad:
#include <REGX51.H>
#include<lcd.c>

void datasel(int x, unsigned char y);


unsigned char col=0, coltest=0;
unsigned char rowtest[]={0x7E, 0x7D, 0x7B, 0x77};
int i;

void main(){

P2=0XFF;
lcdinit();

while(1){
P2=0x70;
col=P2&0X70;
col=col>>4;

while(!(col==7)){
coltest=col;

for(i=0;i<4;i++){
P2=rowtest[i];
col=P2&0X70;
col=col>>4;
if(col==coltest)
datasel(i,coltest);
}
}
}
}

void datasel(int x, unsigned char y){

lcdcmd(0XCF);

if(x==0&&y==0x06) lcddata('1');
if(x==0&&y==0x05) lcddata('2');
if(x==0&&y==0x03) lcddata('3');

if(x==1&&y==0x06) lcddata('4');
if(x==1&&y==0x05) lcddata('5');
if(x==1&&y==0x03) lcddata('6');

if(x==2&&y==0x06) lcddata('7');
if(x==2&&y==0x05) lcddata('8');
if(x==2&&y==0x03) lcddata('9');

if(x==3&&y==0x06) lcddata('*');
if(x==3&&y==0x05) lcddata('0');
if(x==3&&y==0x03) lcddata('#');
}

Software:

KEIL SOFTWARE

Keil Software is the leading vendor for 8/16-bit development tools


(ranked at first position in the 2004 Embedded Market Study of the
Embedded Systems and EE Times magazine). Keil Software is
represented world-wide in more than 40 countries. Since the market
introduction in 1988, the Keil C51 Compiler is the de facto industry
standard and supports more than 500 current 8051 device variants. Now,
Keil Software offers development tools for ARM.
Keil Software makes C compilers, macro assemblers, real-time kernels,
debuggers, simulators, integrated environments, and evaluation boards
for the 8051, 251, ARM, and XC16x/C16x/ST10 microcontroller
families.

Keil Software is pleased to announce simulation support for the Atmel


AT91 ARM family of microcontrollers. The Keil µVision Debugger
simulates the complete ARM instruction-set as well as the on-chip
peripherals for each device in the AT91 ARM/Thumb microcontroller
family. The integrated simulator provides complete peripheral
simulation. Other new features in the µVision Debugger include:

 An integrated Software Logic Analyzer that measures I/O signals as


well as program variables and helps developers create complex signal
processing algorithms.

 An Execution Profiler that measures time spent in each function,


source line, and assembler instruction. Now developers can find
exactly where programs spend the most time.

"Using nothing more than the provided simulation support and debug
scripts, developers can create a high-fidelity simulation of their actual
target hardware and environment. No extra hardware or test equipment
is required. The Logic Analyzer and Execution Profiler will help
developers when it comes time to develop and tune signaling
algorithms." said Jon Ward, President of Keil Software USA, Inc.

µVision3 Overview

The µVision3 IDE is a Windows-based software development platform


that combines a robust editor, project manager, and make facility.
µVision3 integrates all tools including the C compiler, macro assembler,
linker/locator, and HEX file generator. µVision3 helps expedite the
development process of your embedded applications by providing the
following:

 Full-featured source code editor,


 Device database for configuring the development tool setting,
 Project manager for creating and maintaining your projects,
 Integrated make facility for assembling, compiling, and linking
your embedded applications,
 Dialogs for all development tool settings,
 True integrated source-level Debugger with high-speed CPU and
peripheral simulator,
 Advanced GDI interface for software debugging in the target
hardware and for connection to Keil ULINK,
 Flash programming utility for downloading the application
program into Flash ROM,
 Links to development tools manuals, device datasheets & user’s
guides.

The µVision3 IDE offers numerous features and advantages that help
you quickly and successfully develop embedded applications. They are
easy to use and are guaranteed to help you achieve your design goals.

The µVision3 IDE and Debugger is the central part of the Keil
development toolchain. µVision3 offers a Build Mode and a Debug
Mode.

In the µVision3 Build Mode you maintain the project files and generate
the application.

In the µVision3 Debug Mode you verify your program either with a
powerful CPU and peripheral simulator or with the Keil ULINK USB-
JTAG Adapter (or other AGDI drivers) that connect the debugger to
the target system. The ULINK allows you also to download your
application into Flash ROM of your target system.

Features and Benefits

The µVision3 Simulator is the Write and test application code


only debugger that completely before production hardware is
simulates all on-chip available. Investigate different
peripherals. hardware configurations to optimize
the hardware design.

Simulation capabilities may be Sophisticated systems can be


expanded using the Advanced accurately simulated by adding your
Simulation Interface (AGSI). own peripheral drivers.

The Code Coverage feature of Safety-critical systems can be


the µVision3 Simulator thoroughly tested and validated.
provides statistical analysis of Execution analysis reports can be
your program’s execution. viewed and printed for certification
requirements.

The µVision3 Device Database Mistakes in tool settings are


automatically configures the practically eliminated and tool
development tools for the target configuration time is minimized.
microcontroller.

The µVision3 IDE integrates Quickly access development tools


additional third-party tools like and third-party tools. All
VCS, CASE, and configuration details are saved in
FLASH/Device Programming. the µVision3 project.

The ULINK USB-JTAG The same tool can be used for


Adapter supports both debugging and programming. No
Debugging and Flash extra configuration time required.
programming with configurable
algorithm files.

Identical Target Debugger and Shortens your learning curve.


Simulator User Interface.

µVision3 incorporates project Accelerates application


manager, editor, and debugger development. While editing, you
in a single environment. may configure debugger features.
While debugging, you may make
source code modifications.
About the Environment

The µVision3 screen provides you with a menu bar for command entry,
a tool bar where you can rapidly select command buttons, and windows
for source files, dialog boxes, and information displays. µVision3 lets
you simultaneously open and view multiple source files.

µVision3 has two operating modes:

 Build Mode: Allows you to translate all the application files and
to generate executable programs. The features of the Build Mode
are described under Creating Applications.
 Debug Mode: Provides you with a powerful debugger for testing
your application. The Debug Mode is described in Testing
Programs.

In both operating modes you may use the source editor of µVision3 to
modify your source code. The Debug mode adds additional windows
and stores an own screen layout. The following picture shows a typical
configuration of µVision3 in the Debug Mode.
 The tabs of the Project Workspace give you access to:
 Files and Groups of the project.
 CPU Registers during debugging.

 Tool and project specific on-line Books.

 Text Templates for often used text blocks.

 Function in the project for quick editor navigation.

 The tabs of the Output Window provides: Build messages and


fast error access; Debug Command input/output console; Find in
Files results with quick file access.
 The Memory Window gives access to the memory areas in
display various formats.
 The Watch & Call Stack Window allows you to review and
modify program variables and displays the current function call
tree.
 The Workspace is used for the file editing, disassembly output,
and other debug information.
 The Peripheral Dialogs help you to review the status of the on-
chip peripherals in the microcontroller.

Software Development Cycle

When you use the Keil µVision3, the project development cycle is
roughly the same as it is for any other software development project.

1. Create a project, select the target chip from the device database,
and configure the tool settings.
2. Create source files in C or assembly.
3. Build your application with the project manager.
4. Correct errors in source files.
5. Test the linked application.

The following block diagram illustrates the complete µVision3 software


development cycle. Each component is described below.
µVision3 IDE

The µVision3 IDE combines project management, a rich-featured editor


with interactive error correction, option setup, make facility, and on-line
help. Use µVision3 to create your source files and organize them into a
project that defines your target application. µVision3 automatically
compiles, assembles, and links your embedded application and provides
a single focal point for your development efforts.

C Compiler & Macro Assembler


Source files are created by the µVision3 IDE and are passed to the C or
EC++ Compiler or Macro Assembler. The compiler and assembler
process source files and create relocatable object files. 

Library Manager

The library manager allows you to create object library from the object
files created by the compiler and assembler. Libraries are specially
formatted, ordered program collections of object modules that may be
used by the linker at a later time. When the linker processes a library,
only those object modules in the library that are necessary to create the
program are used.

Linker/Locator

The Linker/Locator creates an executable program file using the object


modules extracted from libraries and those created by the compiler and
assembler. An executable program file (also called absolute object
module) contains no relocatable code or data. All code and data reside at
fixed memory locations.

This executable program file may be used:

 To program an Flash ROM or other memory devices,


 With the µVision3 Debugger for simulation and target debugging,
 With an in-circuit emulator for the program testing.
µVision3 Debugger

The µVision3 symbolic, source-level debugger is ideally suited for fast,


reliable program debugging. The debugger includes a high-speed
simulator that let you simulate an microcontroller system including on-
chip peripherals and external hardware. The attributes of the chip you
use are automatically configured when you select the device from the
Device Database.

The µVision3 Debugger provides several ways for you to test your
programs on real target hardware.

 Use the Keil ULINK USB-JTAG adapter for Flash downloading


and software test of your program via on-chip debugging system
like the Embedded ICE macro cell that is integrated in many ARM
devices.
 Use the AGDI interface to attach use the µVision3 Debugger front
end with your target system using other debuggers like Monitor,
In-System Debugger, or Emulator.
 File Menu and Commands

Shortcu
  Menu Item or Command t

New Ctrl+N
Creates a new source or text file.

Open Ctrl+O
Opens an existing file.

Close  
Closes the active file.

Save Ctrl+S
Saves the active file.

Save as...  
Renames and saves the active file.
Save All
Saves all open source and text files including the
project.

Device Database  
Opens the Device Database Dialog where you may
maintain the µVision3 Device Database.

License Management  
Opens the License Management Dialog where you
may maintain and review the installed software
components.

Print Setup...  
Opens the Printer Setup Dialog.

Print Ctrl+P
Prints the active file.

Print Preview  
Displays pages in print view.

1 - 9  
Opens the most recent used source or text files.

Exit
Exits µVision3 and prompts to save any files that are
open.
Flash Menu

The Flash menu allows you to configure and run Flash Programming
Utilities. With Configure Flash Tools… the programming tool is
selected and configured. For details refer to Configure Flash Menu.

Shortcu
Menu Item t

Download
Downloads program to Flash using the programming
utility configured under Options for Target — Utilities.

  Erase  
Erases the Flash ROM (only available for some
devices).

  Configure Flash Tools...


Opens the Options for Target — Utilities dialog
where you may configure the Flash Utilities.

Status Bar

The Status Bar shown at button of the screen  (when enabled in the
View Menu) displays messages and  information about the current
µVision command and other status information as explained below:
Debug Channel shows the active debug tool and displays the name of
the Advanced GDI Driver or Simulation when the program is tested
with build-in µVision Simulator. 

Execution Time displays time information during simulation. Right


click on execution time to set marks for timing analysis.

Cursor Position shows the position in the current editor file (L: line
number, C: column number).

Editor and Keyboard Status Information displays:

 CAP: the keyboard is currently in the caps lock status.


 NUM: the keyboard is currently in the num lock status.
 SCRL: the keyboard is currently in the scroll lock status.
 OVR: indicates the overtype editor mode that replaces characters
as you type. By default characters are inserted when you type. The
Insert key toggles between overtype and standard mode.
 R/W or R/O: the current editor file attribute. R/W full read/write
access. R/O read-only access which prevents from text
modifications.
 Using Debugger
 The µVision3 Debugger simulates up to 4GB (Giga Bytes) of
memory from which areas can be mapped for read, write, or code
execution access. The µVision3 simulator traps and reports illegal
memory accesses.
 In addition to memory mapping, the simulator also provides
support for the integrated peripherals of the various ARM based
microcontroller devices. The on-chip peripherals of the CPU you
have selected are configured from the Device Database selection
you have made when you create your project target. Refer to Start
µVision3 and Create a Project File for more information about
selecting a device.
 You may select and display the on-chip peripheral components
using the Debug menu. You can also change the aspects of each
peripheral using the controls in the dialog boxes.

Breakpoints

µVision3 lets you define breakpoints in several different ways. You


may already set Execution Breaks during editing of your source text,
even before the program code is translated. Breakpoints can be defined
and modified in the following ways:

 With the File Toolbar buttons. Just select the code line in the
Editor or Disassembly window and click on the breakpoint buttons.
 With the breakpoint commands in the local menu. The local menu
opens with a right mouse click on the code line in the Editor or
Disassembly window.
 The Debug – Breakpoints… dialog lets you review, define and
modify breakpoint settings. This dialog allows you to define also
access breakpoints with different attributes. Refer to the examples
below.
 In the Output Window – Command page you can use the
BreakSet, BreakKill, BreakList, BreakEnable, and
BreakDisable commands.

The Breakpoint dialog lets you view and modify breakpoints. You can
quickly disable or enable the breakpoints with a mouse click on the
check box in the Current Breakpoints list. A double click in the
Current Breakpoints list allows you to modify the selected break
definition.
You define a breakpoint by entering an Expression in the Breakpoint
dialog. Depending on the expression one of the following breakpoint
types is defined:

 When the expression is a code address, an Execution Break (E) is


defined that becomes active when the specified code address is
reached. The code address must refer to the first byte of a CPU
instruction.
 When a memory Access (Read, Write or both) is selected an
Access Break (A) is defined that becomes active when the
specified memory access occurs. You can specify the size of the
memory access window in bytes or object size of the expression.
Expressions for an Access Break must reduce to a memory address
and memory type. The operators (&, &&, <. <=. >, >=, = =, and !
=) can be used to compare the variable values before the Access
Break halts program execution or executes the Command.
 When the expression cannot be reduced to an address a
Conditional Break (C) is defined that becomes active when the
specified conditional expression becomes true. The conditional
expression is recalculated after each CPU instruction, therefore the
program execution speed may slow down considerably.

When you specify a Command for a breakpoint, µVision3 executes the


command and resumes executing your target program. The command
you specify here may be a µVision3 debug or signal function. To halt
program execution in a µVision3 function, set the _break_ system
variable. For more information refer to System Variables.

The Count value specifies the number of times the breakpoint


expression is true before the breakpoint is triggered.

CPU Registers

The CPU registers are displayed and


Project Workspace - Regs page. To modify
a register value, select the value with a mouse
click and wait a second. Another mouse click
or the F2 key starts the edit mode.
Disassembly Window

The Disassembly window shows your target program as mixed source


and assembly program or just assembly code. A trace history of
previously executed instructions may be displayed with Debug – View
Trace Records. To enable the trace history, set Debug –
Enable/Disable Trace Recording.

If you select the Disassembly Window as the active window all program
step commands work on CPU instruction level rather than program
source lines. You can select a text line and set or modify code
breakpoints using toolbar buttons or the context menu commands.

You may use the dialog Debug – Inline Assembly... to modify the CPU
instructions. That allows you to correct mistakes or to make temporary
changes to the target program you are debugging.

Logic Analyzer

The µVision3 Logic Analyzer provides a graphical display for value


changes of variables or VTREGs that you specify.

The Logic Analyzer window contains in the top border several buttons
and display fields. 

The Setup... dialog defines variables for signal recording and configures
the display output. Some configuration settings may be also changed
from the context menu that opens with a right click on the signal name.
Export... writes the current recorded signals to a tab-delimited file for
analysis with external tools.

The time fields show:

 Min Time: Start time of the signal recording buffer.


 Max Time: End time of the signal recording buffer content
(typically identical with the current CPU time).
 Range: Time range of the current display.
 Grid: Time range of a grid line.

The Zoom buttons define the time range of the display. Zoom All shows
the complete content of the signal recording buffer. Zoom Sel changes
the display to a selection that you have previously marked with a mouse
drag while holding down the Shift key.

Code Show opens the source or disassembly window at the code


position that causes the signal transition.

Setup Min/Max configures the display range of a signal. Auto


configures the max. / min. values based  based on the values from the
current recording. Undo restores the previous settings before Auto.

To Logic Analyzer allows you to review change information using the


following mouse and cursor commands:

 Set cursor line with a mouse click. The cursor line displays all
variable values at the selected time stamp.
 Move cursor line to previous or next signal change with Left or
Right cursor key. The signal is selected with a mouse click in the
left border.
 Show detailed information by placing the mouse cursor near a
signal change (the Logic Analyzer snaps to the closes signal
change). The information box shows the signal delta values based
on the current cursor line position.

Memory Window

 The Memory window displays the contents of the various memory


areas. Up to four different areas can be review in the different
pages. The context menu allows you to select the output format.

 In the Address field of the Memory Window, you can enter any
expression that evaluates to a start address of the area you want to
display. To change the memory contents, double click on a value.
This opens an edit box that allows you to enter new memory
values. To update the memory window while a target program is
running enable View – Periodic Window Update.

Watch Window

The Watch Window lets you view and modify program variables and
lists the current function call nesting. The contents of the Watch
Window are automatically updated whenever program execution stops.
You can enable View – Periodic Window Update to update variable
values while a target program is running.
Variable Values

The Locals page shows all local function variables of the current
function. The Watch pages display user-specify program variables. 

You can add variables in three different ways:

 Select the text <type F2 to edit> with a mouse click and wait a
second. Another mouse click or the F2 key starts the edit mode
that allows you to add variables. In the same way you can modify
existing variables.
 In an editor window open the context menu with a right mouse
click and use Add to Watch Window. µVision3 automatically
selects the variable name under the cursor position, alternatively
you may mark an expression before using that command.
 In the Output Window – Command page you can use the
WatchSet command to enter variable names.

To modify a variable value, select the value with a mouse click and wait
a second. Another mouse click or the F2 key starts the edit mode.

To remove a variable, click on the line and press the Delete key or use
the WatchKill command.

Function Call Nesting


The Call Stack page shows that current function call nesting. In the Call
Stack page you can double click on a line to show the invocation an
editor window.

You might also like