Professional Documents
Culture Documents
1|Page
8. Add the source files. See, application note 3083, "Performing ADC Conversions
9. Set Target Options. Click on the icon to the left of Target drop down box. Click on
the Target Tab. Configure the Target for an 11.0592MHz crystal, select Use On-Chip
ROM (0x0-0x3FFF), specify Off-chip Code Memory to Start at 0x4000 with a size of
0x8000 and Off-Chip Xdata memory to Start at 0x0 with a Size of 0x8000.
2|Page
3|Page
Target Board. See, application note 3087, "Downloading a Program to Flash Using
the MAX7651 EV Kit Serial Downloader."
15. If you do not have the MAX7651EVKIT and/or wish to run the program using the
Keil Vision simulator, click on the Debug Menu, and Start the debug Session. Click
OK for the warning of evaluation version. Select View Menu and click on Serial
Window #1. Select the Debug Menu and click on Go. The program will execute and
perform analog-to-digital conversions on all 8 channels.
4|Page
5|Page
6|Page
Flash Magic provides a clear and simple user interface to these features and more as
described in the following sections. Under Windows, only one application may have
access the COM Port at any one time, preventing other applications from using the
COM Port. Flash Magic only obtains access to the selected COM P ort when ISP
operations are being performed. This means that other applications that need to use
the COM Port, such a s debugging tools, may be used while Flash Magic is loaded.
Programming Mode
Execution Mode
8|Page
Board layout
9|Page
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
TITLE:
___________________________________________________________________________
Aim: Write a C program to send data serially through serial port.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3,flash magic
Program:
#include<REG51.h>
#include<stdio.h>
void serial_init(void);
void serial_init(void)
{
SCON=0X50;
TMOD=0X20;
TH1=0XFD;
TR1=1;
TI=1;
}
void main(void)
{
serial_init();
while(1)
printf("Hello! world\n");
}
Output:
10 | P a g e
Result:
Thus the program to send data serially through serial port was executed
successfully and got the desired output.
DEPARTMENT OF..................................................................................................................
11 | P a g e
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
TITLE:
Aim: Write a C program to receive data serially.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3, flashmagic
Program:
#include<reg51.h>
void serial(void);
void DelayMS(unsigned int);
unsigned int i,j;
unsigned char b[25],d;
void main()
{ EA=1;
ES=1;
serial();
while(1); }
void serial(void)
{
TMOD=0x20;
SCON= 0X50;
TH1=0XFD;
TR1=1;
}
void serin(void) interrupt 4
{
if(RI==1)
{
d=SBUF;
b[j]=d;
SBUF=b[j];
DelayMS(20);
j++;
}
SCON=0X50;
}
void DelayMS(unsigned int k)
{ unsigned int;
for(i=0;i<k;i++); }
Output:
12 | P a g e
Result:
Thus the program to receive data serially was executed successfully and got
the desired output.
DEPARTMENT OF..................................................................................................................
13 | P a g e
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
TITLE:
Aim: Write a program for the LED to glow from right to left.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3, flashmagic
Program:
#include<reg51.h>
void delay();
void main()
{
int i;
while(1)
{
for(i=0x01;i<=0xFF;i++)
{
P0=i;
delay();}}}
void delay() {
unsigned int i;
for(i=0;i<=5;i++)
{
TMOD=0X06;
TL0=0X00;
TH0=0X00;
TR0=1;
TR0=0;
}}
Output:
14 | P a g e
Result:
Thus the program the LED to glow from right to left serial port was
executed successfully and got the desired output.
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
15 | P a g e
Expt. No:
Date: ...........................
TITLE:
Aim: Write a C program to display a message on LCD.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3,flashmagic
Program:
#include<reg51.h>
#include<stdio.h>
#define data P1
sbit RS=P3^5;
sbit RW=P3^6;
sbit EN=P3^7;
code unsigned char msg[]=("WELCOME 2 JBREC");
code unsigned char msg1[]=("ES");
void lcd_init(void);
void lcd_cmd(unsigned char);
void lcd_display(unsigned char);
void delay(int);
void lcd_cmd(unsigned char cmd)
{
data=cmd;
RS=0;
RW=0;
EN=1;
delay(35);
EN=0;
}
void lcd_display(unsigned char dat)
{
data=dat;
RS=1;
RW=0;
EN=1;
delay(35);
EN=0;
}
void delay(int k)
{
unsigned int a;
for(a=0;a<k;a++);
}
void lcd_init(void)
{
16 | P a g e
unsigned char i;
lcd_cmd(0x38);delay(15);
lcd_cmd(0x0C);delay(15);
lcd_cmd(0x06);delay(15);
lcd_cmd(0x01);delay(15);
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}
delay(50);
lcd_cmd(0xC0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}
delay(50);
}
void main()
{
lcd_init();
delay(50);
while(1);
}
Output:
17 | P a g e
Result:
Thus the program to display a message on LCD was executed successfully
and the following message is displayed on LCD.
WELCOME 2 JBREC
ES
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
18 | P a g e
Expt. No:
Date: ...........................
TITLE::
Aim: Write a C program to to read Analog signals from ADC.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3,flashmagic
Program:
#include<stdio.h>
#include <reg51.h>
#include <ctype.h>
sbit A0 = P2^7;
sbit A1 = P2^6;
sbit A2 = P2^5;
sbit CS = P2^4;
void serial();
void delay1(int);
void delay2(int);
unsigned char READ_ADC(void);
unsigned char ch;
unsigned int i;
void delay1(int n)
{
int i;
for(i=0;i<n;i++);
}
void delay2(int n)
{
int i;
for(i=0;i<n;i++)
delay1(1000);
}
void serial()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
TI=1; }
unsigned char READ_ADC()
{
unsigned char ADC_DATA;
19 | P a g e
CS = 0; delay2(1);
CS = 1; delay2(1);
CS = 0; delay2(1);
CS = 1; delay2(1);
ADC_DATA = P1;
return(ADC_DATA);
}
void main(void)
{
P1=0xFF;
serial();
A0 = 0; A1 = 0; A2 = 0;
printf("ADC Demo - Channel '0' Adjust (R27) Trimpot\n");
printf("--------------------------------------------\n");
while(1)
{
ch = READ_ADC();
printf("\rCH0 = %3bu",ch);
delay2(2);
}
}
Output:
20 | P a g e
Result:
Thus the program to display value in Port1 is converted to decimal value and
Obtained desired results.
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
21 | P a g e
Expt. No:
Date: ...........................
TITLE::
Aim: Write a C program to to read data from keypad interface and display on LCD.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3,flashmagic
Program:
#include <stdio.h>
#include <reg51.h>
#define DATA P1
void lcd_init(void);
void lcd_cmd(unsigned char);
void lcd_display(unsigned char);
void Key_Scan(void);
void DelayMs(int);
sbit RS = P3^5;
sbit RW = P3^6;
sbit lcd_e = P3^7;
unsigned char R,C,ch,d=0x81;
unsigned int i=0;
unsigned char Key[4][4] = {'C','D','E','F','8','9','A','B','4','5','6','7','0','1','2','3',};
code unsigned char msg[] = ("KEYPAD TEST PGM ");
code unsigned char msg1[] = ("PRES ANY KEY... ");
void main()
{
lcd_init();
DelayMs(20);
lcd_cmd(0x01);
lcd_e=0;
lcd_cmd(0x80);
while(1)
{
Key_Scan();
lcd_e=1;
DelayMs(5);
ch = Key[R][C];
DelayMs(5);
lcd_cmd(d++);
DelayMs(10);
P2=0xFF;
}
}
22 | P a g e
void Key_Scan(void)
{
unsigned int i = 0;
P2 = 0x0F;
while(P2 == 0x0F);
if(P2 == 0x0E)
R = 0;
else if(P2 == 0x0D)
R = 1;
else if(P2 == 0x0B)
R = 2;
else if(P2 == 0x07)
R = 3;
P2 = 0xF0;
while(P2 == 0xF0);
if(P2 == 0xE0)
C = 0;
else if(P2 == 0xD0)
C = 1;
else if(P2 == 0xB0)
C = 2;
else if(P2 == 0x70)
C = 3;
DelayMs(20);
}
void lcd_cmd(unsigned char cmnd)
{
DATA = cmnd;
RS = 0;
RW = 0;
lcd_e = 1;
DelayMs(15);
lcd_e = 0;
}
void lcd_display(unsigned char dat)
{
DATA = dat;
RS = 1;
RW = 0;
lcd_e = 1;
DelayMs(15);
lcd_e = 0;
}
23 | P a g e
void lcd_init(void)
{
unsigned char i;
lcd_cmd(0x38);
DelayMs(15);
lcd_cmd(0x0c);
DelayMs(15);
lcd_cmd(0x06); DelayMs(15);
lcd_cmd(0x01); DelayMs(15);
lcd_cmd(0x80); DelayMs(15);
i=0;
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}
DelayMs(20);
lcd_cmd(0xc0);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}
DelayMs(30);
}
void DelayMs(int k)
{
unsigned int a,b;
for(a=0;a<=k;a++)
for(b=0;b<1275;b++);
}
Output:
24 | P a g e
Result:
Thus the program to display value given at keypad interface and displayed on LCD
panel.
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
25 | P a g e
TITLE::
Aim: Write a C program to read data from keypad interface and display on LCD using ARM
processor.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3,flashmagic
Program:
#include <LPC214x.h>
#include <stdio.h>
#include "Keypad.h"
extern void Delay(void);
unsigned char Row_Data, Col_Data;
unsigned char Msg[4][4] = { '0','1','2','3', '4','5','6','7', '8','9','A','B',
'C','D','E','F'};
void Delay(void)
{
unsigned int i,j;
for(i=0;i<35;i++)
for(j=0;j<1234;j++);
}
void main(void)
{
U0LCR
=
0x83;
U0DLL
=
0x61;
U0LCR
=
0x03;
PINSEL0 |=
0x05;
SCS
|=
0x03;
PINSEL2 |=
0x0;
U0THR = 'A';
while (1)
{
Delay();
Delay();
KeyScan(&IOPIN1/*KeyPad Port*/,16/*Starting Data Pin D0*/,
&Row_Data/*Addr of Row*/,&Col_Data/*Addr of Col*/);
if (Row_Data < 4 && Col_Data < 4)
{
U0THR = Msg[Row_Data][Col_Data];
Delay();
Delay(); U0THR = '\n'; } } }
Output:
26 | P a g e
Result:
Thus the program to display value given at keypad interface and displayed on LCD
panel.
DEPARTMENT OF..................................................................................................................
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
27 | P a g e
TITLE:
Aim: Write a C program to receive data serially.
Equipment Required:
Hardware:
Personnel Computer,microcontroller kit
Software:
Keil Vision3, flashmagic
Program:
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;
int main(void)
{
char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";
VPBDIV = 0x02;
init_serial();
while(1)
{
while (*Ptr)
{
putchar(*Ptr++);
}
putchar(getchar());
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005;
U0LCR
= 0x00000083;
U0DLL
= 0x000000C3;
U0LCR
= 0x00000003;
}
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR;
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getchar (void)
28 | P a g e
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
Output:
29 | P a g e
Result:
Thus the program to receive data serially was executed successfully and got
the desired output.
DEPARTMENT OF..................................................................................................................
30 | P a g e
........................................................................................................................LABORATORY
Expt. No:
Date: ...........................
TITLE:
Aim: Write a C program to send data serially through serial port using ARM processor.
Equipment Required:
Hardware:
Personnel Computer, Microcontroller Kit
Software:
Keil Vision3, Flashmagic
Program:
#pragma INTERWORK
#include <LPC21xx.H>
#define CR 0x0D
void init_serial (void)
{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1DLL = 97;
U1LCR = 0x03;
}
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U1LSR & 0x20));
U1THR = CR;
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getchar (void)
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
Output:
31 | P a g e
Result:
Thus the program to send data serially through serial port was executed
successfully and got the desired output.
32 | P a g e