Professional Documents
Culture Documents
after the code is properly compiled without any errors try and test it on the simulator.
Give a new project name for every assignment. carryout the test on the target board.
be familiar to make the correct connections on the board,down load the code and test them.
please practice c code bracketing with indentation to make the code readable and debuggable.
understand the use of watch variable window./disassembly view.use functions as much as possible.
be stringent in declaring variables. understand the use of reg52.h carryout the excercises and submit the
softcopy(optional) of the answers at the end of the course.or mail to sharma.ramgopal@gmail.com
compiler,debugger,simulator etc.these are cross platform tools and facilitate simulation only.
The developed code needs to be downloaded and tested on the target microcontroller.
Downloding means writing in to the code memory of the microcontroller in the target board.
This is called a programmer. Ther are stand alone programmers and in system programmers.(ISP).
ISP's are more useful as the the newer packaging implies " solder first,code next" as these are IC
baseless.
The basic difference is their interface with the PC. Basically, there are three types of programmers.
Of these serial port based and parallel port based programmers are easy to make in minimal cost. As the
serials and parallel ports are very old technologies they are fast disappearing from PCs.
Most laptops are not having them and even desktops are dropping them. Therefore, its no surprise that
your PC does not has serial ports. The future is USB. so you should have a usp isp programmer.
In this course we use a usb based programmer and the serial port is also usb basedwithg appropriate
drivers installed in the pc or laptop.
we provide the minimal and most useful data as handouts and the ppts are available in a dvd
/*
*/
#include<REG52.h>
void main(void)
{ while(1)
switch(P2)
} end of switch
} end of while
} end of main
{ temp=x;x=y; y=temp; }
return(z);
Code snippet: swap two 8 bit unsigned character variables without using a third variable
*/
#include<REG52.h>
while(1) { temp=0x01; for (j=0;j<8;j++){ P0=temp; //sending the output through port 0 to LEDs
Assigment 1Question 5 switching on and off individual LEDs and making it move in both directions
continuouslyP0 is the output which is connected to the LEDs */
#include<REG52.h>
void main(void)
{P0=i;
{P0=i;
} // end of main
Exercise: change unsigned char i to char i and observe the result and explain the reason.
*/
#include<REG52.h>
void main(void)
while(1)
{ P0=binbcd(i); for(j=0;j<=60000;j++);//delay }
#include<REG52.h>
void main(void)
while(1)
{P0=binbcd(k); for(j=0;j<=10000;j++);}
for(h=i;h>0;h--)
{P0=binbcd(h); for(j=0;j<=10000;j++); }
5. Write a C program to
a. upcount binary 0 to N and display on serial display continuously
b downcount binary N to 0 and display on serial display continuously
Where N is taken from PORT1 through DIP switch
Assignment 3Question 2 program to make a walking segment from segment 0 to segment 16
#include<REG52.h>
sbit clk=P3^7;
void main(void)
{ clk=0;clk=1;clk=0;} dat=0;clk=0;clk=1;clk=0;
dat=1;
#include <REG52.h>
// these the corresponding codes for 0 to F which has to be sent to the serial display
unsigned int j;
P2=0xff; temp=P2;
{ lowernibble=h&0x0f; upperniblle=h&0xf0;uppernibble=uppernibble>>4;
seven(a[uppernibble]); seven(a[lowernibble]);
} //end of while
void seven(unsigned char n) //to display a single digit on the serial display
temp=n;mask=0x80; for(i=0;i<8;i++)
3. Write a C program to recognize the keyboard and display the key value on
a.7-segment display.
b. serial display
c. LCD
And generate a beep sound whenever a key is pressed.
4. Write a C program that different names on the LCD for
Different keys. For ex: for key1 hello
For ex: for key2 world etc
Assignment 4 question 1, good bad ugly on lcd
include<REG52.h>
void main(void)
lcdint();
while(1)
{ for(count=0;count<=12;count++)
{ wrt(a[count],1); delay(50000); }
void lcdint(void)
#include<REG52.h>
void main(void)
{ int i,j,k,l,temp
while(1) { for(i=0;i<=9999;i++)
temp=i;j=0;
while(temp){buffer[j]=temp%10;buffer[j]=buffer[j]+0x30;temp=temp/10;j++;}
j--; while(j>0){wrt(buffer(j,1));j--}
} // end of while
} // end of main
void wrt(unsigned char n,unsigned char m) // write n to command area if m=0 else data
{ for(;n>0;n--);}
void lcdint(void) // used to initialise the LCD sequence should be written into the command space
Exercise: understand the different modes of lcd viz, left entry,right entry,inc,dec etc.
Assignment 4 question 3a. Recognize a 4x4 keypad and display on bcd display.
#include<REG52.h>
0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77};
for(j=0;j<16;j++)
{ if (value==lookup[j]) break; }
if (i<16)key=j;else key=0xff;
beep();
}//end of while
{ for(;n>0;n--);}
Lab Assignment no. 5
*
assignment 5 - question 1 .program a BCD to count from 0 to 99 by generating one second delay
using timer0 in polling mode and measure the actual time elapsed using timer1 in interrupt
mode and display it on the LCD. Count value on 1st line on lcd and elapsed time in the 2nd line od
lcd.
#include<REG52.h>
void polsec(unsigned char); //generates one sec delay using timer0 in polling mode
void wrt(unsigned char,unsigned char); //writes the data onto the LCD
long totaltime;
void main(void)
{ temp=i:units=i%10+0x30;tens=i/10+0x30; wrt(0x80,0);wrt(tens,1);write(units,1);
while(temp){buffer[j]=temp%10;buffer[j]=buffer[j]+0x30;temp=temp/10;j++;}
j--; while(j>0){wrt(buffer(j,1));j--}
while(1); // stops after 99
void polsec()
{totaltime++}
Exercise: change starting and ending values. Also increase or decrease time delay values.
*
assignment 5 - question 2 program to count from 0 to 99 by generating one second delay
using timer0 in interrupt mode and measure the actual time elapsed
the coded is same as above but for change in polsec() functionplus one more interruot
generated by timer0 also. Add another global variable called as count1.
void polsec()
while (count1,<0){}
TR0=1; count1++; }
assignment 5 - question 4,question 5 and question 6 combined
program to measure th on-off time 0f 555 oscillator and display it on the LCD
#include<REG52.h>
sbit IN=P2^7;
void main(void)
while(1)
Display (totaltime);display(freq);
Exercise: there are four methods to measure frequency: (a) shown above.(b) frequency is number of
rising edges per second. Use timer to generate one second delay and count the rising edges within that
time.
©; total time is the time betweek two consecutive rising edges. Count time using timer.
(d) connect the input to an interrupt( make it falling edge sensitive), then count the nuber of interrupts
in one second.
Lab Assignment no. 6
#include<REG52.h>
void main(void)
unsigned char k;
while(1)
{ while(!RI); //wait till a key is pressed so that the receive buffer becomes high
TI=0; //set TI as 0
Ecxercise: read a character and send back a character in the serial interrupt mode.
Lab Assignment no. 7
1. Use the (ADC) ICL7135 to measure the input voltage and show it
on LCD.
2. Write a code to generate a ramp using the DAC (DAC0800).
3. Generate analog signal using DAC and Read it from ADC and
display it on LCD.
void main(void)
{
unsigned int value; unsigned char a[4]; clk=1;busy=1; TMOD=0x05;
//uses timer0 in mode 1 in counter mode
TR0=0; //switching off timer0
lcdint(); //initialises LCD
while(1)
{
TL0=0;TH0=0; while(busy); //to get the rising edge
while(!busy); /
TR0=1; //switching on timer0
while(busy); TR0=0; //switching off timer0
While(1)
====================================================================================
assignment 8 - question 2 stop watch using keyboard and LCD
#include<REG52.h>
long time;
void main(void)
lcdint(); while(1)
{ P1=0xfe;delay(1000);val=P1;
switch(state)
if(val==0xbe) state=2;break;
} // end of main
{TR1=0;time++;TH1=value/256;TL1=value%256; TR1=1;}
. Write a C program for a stopwatch using hyperterminal and LCD.
- S START the watch.- E STOP the watch.- P PAUSE.- C to continue.Output should
display time in Minutes and Seconds on the PC.
Modifying the value of a global variable which will control the time or the state of
the machine. The state controls the behavior of the machine.